source: git/Singular/bbcone.cc @ 7a81686

spielwiese
Last change on this file since 7a81686 was a33266, checked in by Hans Schoenemann <hannes@…>, 13 years ago
conditional compile: HAVE_FANS git-svn-id: file:///usr/local/Singular/svn/trunk@13902 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 19.6 KB
Line 
1#include <Singular/mod2.h>
2
3#ifdef HAVE_FANS
4
5#include <Singular/ipid.h>
6#include <Singular/blackbox.h>
7#include <omalloc/omalloc.h>
8#include <kernel/febase.h>
9#include <kernel/longrat.h>
10#include <Singular/subexpr.h>
11#include <gfanlib/gfanlib.h>
12#include <Singular/bbcone.h>
13#include <ipshell.h>
14#include <kernel/intvec.h>
15#include <sstream>
16
17
18int coneID;
19
20int integerToInt(gfan::Integer const &V, bool &ok)
21{
22  mpz_t v;
23  mpz_init(v);
24  V.setGmp(v);
25  int ret=0;
26  if(mpz_fits_sint_p(v))
27    ret=mpz_get_si(v);
28  else
29    ok=false;
30  mpz_clear(v);
31  return ret;
32}
33
34intvec* zVector2Intvec(const gfan::ZVector zv)
35{
36  int d=zv.size();
37  intvec* iv = new intvec(1, d, 0);
38  bool ok = true;
39  for(int i=1;i<=d;i++)
40    IMATELEM(*iv, 1, i) = integerToInt(zv[i-1], ok);
41  if (!ok) WerrorS("overflow while converting a gfan::ZVector to an intvec");
42  return iv;
43}
44
45intvec* zMatrix2Intvec(const gfan::ZMatrix zm)
46{
47  int d=zm.getHeight();
48  int n=zm.getWidth();
49  intvec* iv = new intvec(d, n, 0);
50  bool ok = true;
51  for(int i=1;i<=d;i++)
52    for(int j=1;j<=n;j++)
53      IMATELEM(*iv, i, j) = integerToInt(zm[i-1][j-1], ok);
54  if (!ok) WerrorS("overflow while converting a gfan::ZMatrix to an intmat");
55  return iv;
56}
57
58gfan::ZMatrix intmat2ZMatrix(const intvec* iMat)
59{
60  int d=iMat->rows();
61  int n=iMat->cols();
62  gfan::ZMatrix ret(d,n);
63  for(int i=0;i<d;i++)
64    for(int j=0;j<n;j++)
65      ret[i][j]=IMATELEM(*iMat, i+1, j+1);
66  return ret;
67}
68
69/* expects iMat to have just one row */
70gfan::ZVector intvec2ZVector(const intvec* iVec)
71{
72  int n =iVec->rows();
73  gfan::ZVector ret(n);
74  for(int j=0;j<n;j++)
75    ret[j]=IMATELEM(*iVec, j+1, 1);
76  return ret;
77}
78
79std::string toString(gfan::ZMatrix const &m, char *tab=0)
80{
81  std::stringstream s;
82
83  for(int i=0;i<m.getHeight();i++)
84    {
85      if(tab)s<<tab;
86      for(int j=0;j<m.getWidth();j++)
87        {
88          s<<m[i][j];
89          if(i+1!=m.getHeight() || j+1!=m.getWidth())
90            {
91              s<<",";
92            }
93        }
94      s<<std::endl;
95    }
96  return s.str();
97}
98
99std::string toString(gfan::ZCone const &c)
100{
101  std::stringstream s;
102  gfan::ZMatrix i=c.getInequalities();
103  gfan::ZMatrix e=c.getEquations();
104  s<<"AMBIENT_DIM"<<std::endl;
105  s<<c.ambientDimension()<<std::endl;
106  s<<"INEQUALITIES"<<std::endl;
107  s<<toString(i);
108  s<<"EQUATIONS"<<std::endl;
109  s<<toString(e);
110  return s.str();
111}
112
113void *bbcone_Init(blackbox *b)
114{
115  return (void*)(new gfan::ZCone());
116}
117
118BOOLEAN bbcone_Assign(leftv l, leftv r)
119{
120  gfan::ZCone* newZc;
121  if (r==NULL)
122  { 
123    if (l->Data()!=NULL) 
124    {   
125      gfan::ZCone* zd = (gfan::ZCone*)l->Data();
126      delete zd;
127    }
128    newZc = new gfan::ZCone();
129  }
130  else if (r->Typ()==l->Typ())
131  {
132    if (l->Data()!=NULL)
133    {   
134      gfan::ZCone* zd = (gfan::ZCone*)l->Data();
135      delete zd;
136    }
137    gfan::ZCone* zc = (gfan::ZCone*)r->Data();
138    newZc = new gfan::ZCone(*zc);
139  }
140  else if (r->Typ()==INT_CMD)
141  {
142    int ambientDim = (int)(long)r->Data();
143    if (ambientDim < 0)
144    {
145      Werror("expected an int >= 0, but got %d", ambientDim);
146      return TRUE;
147    }
148    if (l->Data()!=NULL)
149    {   
150      gfan::ZCone* zd = (gfan::ZCone*)l->Data();
151      delete zd;
152    }
153    newZc = new gfan::ZCone(ambientDim);
154  }
155  else
156  {
157    Werror("assign Type(%d) = Type(%d) not implemented",l->Typ(),r->Typ());
158    return TRUE;
159  }
160 
161  if (l->rtyp==IDHDL)
162  {
163    IDDATA((idhdl)l->data)=(char *)newZc;
164  }
165  else
166  {
167    l->data=(void *)newZc;
168  }
169  return FALSE;
170}
171
172char * bbcone_String(blackbox *b, void *d)
173{ if (d==NULL) return omStrDup("invalid object");
174   else
175   {
176     std::string s=toString(*((gfan::ZCone*)d));
177     char* ns = (char*) omAlloc(strlen(s.c_str()) + 10);
178     sprintf(ns, "%s", s.c_str());
179     omCheckAddr(ns);
180     return ns;
181   }
182}
183
184void bbcone_destroy(blackbox *b, void *d)
185{
186  if (d!=NULL)
187  {
188    gfan::ZCone* zc = (gfan::ZCone*) d;
189    delete zc;
190  }
191}
192
193void * bbcone_Copy(blackbox*b, void *d)
194{       
195  gfan::ZCone* zc = (gfan::ZCone*)d;
196  gfan::ZCone* newZc = new gfan::ZCone(*zc);
197  return newZc;
198}
199
200static BOOLEAN jjCONERAYS1(leftv res, leftv v)
201{
202  /* method for generating a cone object from half-lines
203     (cone = convex hull of the half-lines; note: there may be
204     entire lines in the cone);
205     valid parametrizations: (intmat) */
206  intvec* rays = (intvec *)v->CopyD(INTVEC_CMD);
207  gfan::ZMatrix zm = intmat2ZMatrix(rays);
208  gfan::ZCone* zc = new gfan::ZCone();
209  *zc = gfan::ZCone::givenByRays(zm, gfan::ZMatrix(0, zm.getWidth()));
210  res->rtyp = coneID;
211  res->data = (char *)zc;
212  return FALSE;
213}
214
215static BOOLEAN jjCONERAYS2(leftv res, leftv u, leftv v)
216{
217  /* method for generating a cone object from half-lines,
218     and lines (any point in the cone being the sum of a point
219     in the convex hull of the half-lines and a point in the span
220     of the lines; the second argument may contain or entirely consist
221     of zero rows);
222     valid parametrizations: (intmat, intmat)
223     Errors will be invoked in the following cases:
224     - u and v have different numbers of columns */
225  intvec* rays = (intvec *)u->CopyD(INTVEC_CMD);
226  intvec* linSpace = (intvec *)v->CopyD(INTVEC_CMD);
227  if (rays->cols() != linSpace->cols())
228  {
229    Werror("expected same number of columns but got %d vs. %d",
230           rays->cols(), linSpace->cols());
231    return TRUE;
232  }
233  gfan::ZMatrix zm1 = intmat2ZMatrix(rays);
234  gfan::ZMatrix zm2 = intmat2ZMatrix(linSpace);
235  gfan::ZCone* zc = new gfan::ZCone();
236  *zc = gfan::ZCone::givenByRays(zm1, zm2);
237  res->rtyp = coneID;
238  res->data = (char *)zc;
239  return FALSE;
240}
241
242static BOOLEAN jjCONERAYS3(leftv res, leftv u, leftv v, leftv w)
243{
244  /* method for generating a cone object from half-lines,
245     and lines (any point in the cone being the sum of a point
246     in the convex hull of the half-lines and a point in the span
247     of the lines), and an integer k;
248     valid parametrizations: (intmat, intmat, int);
249     Errors will be invoked in the following cases:
250     - u and v have different numbers of columns,
251     - k not in [0..3];
252     if the 2^0-bit of k is set, then the lineality space is known
253     to be the span of the provided lines;
254     if the 2^1-bit of k is set, then the extreme rays are known:
255     each half-line spans a (different) extreme ray */
256  intvec* rays = (intvec *)u->CopyD(INTVEC_CMD);
257  intvec* linSpace = (intvec *)v->CopyD(INTVEC_CMD);
258  if (rays->cols() != linSpace->cols())
259  {
260    Werror("expected same number of columns but got %d vs. %d",
261           rays->cols(), linSpace->cols());
262    return TRUE;
263  }
264  int k = (int)(long)w->Data();
265  if ((k < 0) || (k > 3))
266  {
267    WerrorS("expected int argument in [0..3]");
268    return TRUE;
269  }
270  gfan::ZMatrix zm1 = intmat2ZMatrix(rays);
271  gfan::ZMatrix zm2 = intmat2ZMatrix(linSpace);
272  gfan::ZCone* zc = new gfan::ZCone();
273  *zc = gfan::ZCone::givenByRays(zm1, zm2);
274  //k should be passed on to zc; not available yet
275  res->rtyp = coneID;
276  res->data = (char *)zc;
277  return FALSE;
278}
279
280BOOLEAN cone_via_rays(leftv res, leftv args)
281{
282  leftv u = args;
283  if ((u != NULL) && (u->Typ() == INTMAT_CMD))
284  {
285    if (u->next == NULL) return jjCONERAYS1(res, u);
286  }
287  leftv v = u->next;
288  if ((v != NULL) && (v->Typ() == INTMAT_CMD))
289  {
290    if (v->next == NULL) return jjCONERAYS2(res, u, v);
291  }
292  leftv w = v->next;
293  if ((w != NULL) && (w->Typ() == INT_CMD))
294  {
295    if (w->next == NULL) return jjCONERAYS3(res, u, v, w);
296  }
297  WerrorS("cone_via_rays: unexpected parameters");
298  return TRUE;
299}
300
301static BOOLEAN jjCONENORMALS1(leftv res, leftv v)
302{
303  /* method for generating a cone object from inequalities;
304     valid parametrizations: (intmat) */
305  intvec* inequs = (intvec *)v->CopyD(INTVEC_CMD);
306  gfan::ZMatrix zm = intmat2ZMatrix(inequs);
307  gfan::ZCone* zc = new gfan::ZCone(zm, gfan::ZMatrix(0, zm.getWidth()));
308  res->rtyp = coneID;
309  res->data = (char *)zc;
310  return FALSE;
311}
312
313static BOOLEAN jjCONENORMALS2(leftv res, leftv u, leftv v)
314{
315  /* method for generating a cone object from iequalities,
316     and equations (...)
317     valid parametrizations: (intmat, intmat)
318     Errors will be invoked in the following cases:
319     - u and v have different numbers of columns */
320  intvec* inequs = (intvec *)u->CopyD(INTVEC_CMD);
321  intvec* equs = (intvec *)v->CopyD(INTVEC_CMD);
322  if (inequs->cols() != equs->cols())
323  {
324    Werror("expected same number of columns but got %d vs. %d",
325           inequs->cols(), equs->cols());
326    return TRUE;
327  }
328  gfan::ZMatrix zm1 = intmat2ZMatrix(inequs);
329  gfan::ZMatrix zm2 = intmat2ZMatrix(equs);
330  gfan::ZCone* zc = new gfan::ZCone(zm1, zm2);
331  res->rtyp = coneID;
332  res->data = (char *)zc;
333  return FALSE;
334}
335
336static BOOLEAN jjCONENORMALS3(leftv res, leftv u, leftv v, leftv w)
337{
338  /* method for generating a cone object from inequalities, equations,
339     and an integer k;
340     valid parametrizations: (intmat, intmat, int);
341     Errors will be invoked in the following cases:
342     - u and v have different numbers of columns,
343     - k not in [0..3];
344     if the 2^0-bit of k is set, then ... */
345  intvec* inequs = (intvec *)u->CopyD(INTVEC_CMD);
346  intvec* equs = (intvec *)v->CopyD(INTVEC_CMD);
347  if (inequs->cols() != equs->cols())
348  {
349    Werror("expected same number of columns but got %d vs. %d",
350           inequs->cols(), equs->cols());
351    return TRUE;
352  }
353  int k = (int)(long)w->Data();
354  if ((k < 0) || (k > 3))
355  {
356    WerrorS("expected int argument in [0..3]");
357    return TRUE;
358  }
359  gfan::ZMatrix zm1 = intmat2ZMatrix(inequs);
360  gfan::ZMatrix zm2 = intmat2ZMatrix(equs);
361  gfan::ZCone* zc = new gfan::ZCone(zm1, zm2, k);
362  res->rtyp = coneID;
363  res->data = (char *)zc;
364  return FALSE;
365}
366
367BOOLEAN cone_via_normals(leftv res, leftv args)
368{
369  leftv u = args;
370  if ((u != NULL) && (u->Typ() == INTMAT_CMD))
371  {
372    if (u->next == NULL) return jjCONENORMALS1(res, u);
373  }
374  leftv v = u->next;
375  if ((v != NULL) && (v->Typ() == INTMAT_CMD))
376  {
377    if (v->next == NULL) return jjCONENORMALS2(res, u, v);
378  }
379  leftv w = v->next;
380  if ((w != NULL) && (w->Typ() == INT_CMD))
381  {
382    if (w->next == NULL) return jjCONENORMALS3(res, u, v, w);
383  }
384  WerrorS("cone_via_normals: unexpected parameters");
385  return TRUE;
386}
387
388static BOOLEAN jjGETPROPC(leftv res, leftv u, leftv v)
389{
390  /* method for retrieving cone properties;
391     valid parametrizations: (cone, string),
392     Errors will be invoked in the following cases:
393     - invalid property string (see below for valid ones) */
394  gfan::ZCone* zc = (gfan::ZCone*)u->Data();
395  char* prop = (char*)v->Data();
396  gfan::ZMatrix retMat;
397  gfan::ZCone retCone;
398  int retInt;
399  gfan::ZVector retVec;
400  int typeInfo;
401
402  /* ################ properties with return type intmat: ################## */
403  if      (strcmp(prop, "INEQUALITIES") == 0)
404  {
405    retMat = zc->getInequalities();
406    typeInfo = INTMAT_CMD;
407  }
408  else if (strcmp(prop, "EQUATIONS") == 0)
409  {
410    retMat = zc->getEquations();
411    typeInfo = INTMAT_CMD;
412  }
413  else if (strcmp(prop, "FACETS") == 0)
414  {
415    retMat = zc->getFacets();
416    typeInfo = INTMAT_CMD;
417  }
418  else if (strcmp(prop, "IMPLIED_EQUATIONS") == 0)
419  {
420    retMat = zc->getImpliedEquations();
421    typeInfo = INTMAT_CMD;
422  }
423  else if (strcmp(prop, "GENERATORS_OF_SPAN") == 0)
424  {
425    retMat = zc->generatorsOfSpan();
426    typeInfo = INTMAT_CMD;
427  }
428  else if (strcmp(prop, "GENERATORS_OF_LINEALITY_SPACE") == 0)
429  {
430    retMat = zc->generatorsOfLinealitySpace();
431    typeInfo = INTMAT_CMD;
432  }
433  else if (strcmp(prop, "RAYS") == 0)
434  {
435    retMat = zc->extremeRays();
436    typeInfo = INTMAT_CMD;
437  }
438  else if (strcmp(prop, "QUOTIENT_LATTICE_BASIS") == 0)
439  {
440    retMat = zc->quotientLatticeBasis();
441    typeInfo = INTMAT_CMD;
442  }
443  else if (strcmp(prop, "LINEAR_FORMS") == 0)
444  {
445    retMat = zc->getLinearForms();
446    typeInfo = INTMAT_CMD;
447  }
448  /* ################ properties with return type int: ################## */
449  else if (strcmp(prop, "AMBIENT_DIM") == 0)
450  {
451    retInt = zc->ambientDimension();
452    typeInfo = INT_CMD;
453  }
454  else if (strcmp(prop, "DIM") == 0)
455  {
456    retInt = zc->dimension();
457    typeInfo = INT_CMD;
458  }
459  else if (strcmp(prop, "LINEALITY_DIM") == 0)
460  {
461    retInt = zc->dimensionOfLinealitySpace();
462    typeInfo = INT_CMD;
463  }
464  else if (strcmp(prop, "MULTIPLICITY") == 0)
465  {
466    bool ok = true;
467    retInt = integerToInt(zc->getMultiplicity(), ok);
468    if (!ok)
469      WerrorS("overflow while converting a gfan::Integer to an int");
470    typeInfo = INT_CMD;
471  }
472  else if (strcmp(prop, "IS_ORIGIN") == 0)
473  {
474    retInt = zc->isOrigin() ? 1 : 0;
475    typeInfo = INT_CMD;
476  }
477  else if (strcmp(prop, "IS_FULL_SPACE") == 0)
478  {
479    retInt = zc->isFullSpace() ? 1 : 0;
480    typeInfo = INT_CMD;
481  }
482  else if (strcmp(prop, "SIMPLICIAL") == 0)
483  {
484    retInt = zc->isSimplicial() ? 1 : 0;
485    typeInfo = INT_CMD;
486  }
487  else if (strcmp(prop, "CONTAINS_POSITIVE_VECTOR") == 0)
488  {
489    retInt = zc->containsPositiveVector() ? 1 : 0;
490    typeInfo = INT_CMD;
491  }
492  /* ################ properties with return type ZCone: ################## */
493  else if (strcmp(prop, "LINEALITY_SPACE") == 0)
494  {
495    retCone = zc->linealitySpace();
496    typeInfo = coneID;
497  }
498  else if (strcmp(prop, "DUAL_CONE") == 0)
499  {
500    retCone = zc->dualCone();
501    typeInfo = coneID;
502  }
503  else if (strcmp(prop, "NEGATED") == 0)
504  {
505    retCone = zc->negated();
506    typeInfo = coneID;
507  }
508  /* ################ properties with return type intvec: ################## */
509  else if (strcmp(prop, "SEMI_GROUP_GENERATOR") == 0)
510  {
511    /* test whether the cone's dim = dim of lin space + 1: */
512    int d = zc->dimension();
513    int dLS = zc->dimensionOfLinealitySpace();
514    if (d == dLS + 1)
515      retVec = zc->semiGroupGeneratorOfRay();
516    else
517    {
518      Werror("expected dim of cone one larger than dim of lin space\n"
519             "but got dimensions %d and %d", d, dLS);
520    }
521    typeInfo = INTVEC_CMD;
522  }
523  else if (strcmp(prop, "RELATIVE_INTERIOR_POINT") == 0)
524  {
525    retVec = zc->getRelativeInteriorPoint();
526    typeInfo = INTVEC_CMD;
527  }
528  else if (strcmp(prop, "UNIQUE_POINT") == 0)
529  {
530    retVec = zc->getUniquePoint();
531    typeInfo = INTVEC_CMD;
532  }
533  else
534  {
535    Werror("unexpected cone property '%s'", prop);
536    return TRUE;
537  }
538
539  res->rtyp = typeInfo;
540  if (typeInfo == INT_CMD)
541    res->data = (void*)retInt;
542  else if (typeInfo == INTMAT_CMD)
543    res->data = (void*)zMatrix2Intvec(retMat);
544  else if (typeInfo == coneID)
545    res->data = (void*)new gfan::ZCone(retCone);
546  else if (typeInfo == INTVEC_CMD)
547    res->data = (void*)zVector2Intvec(retVec);
548  else
549  {
550    WerrorS("implementation error in bbcone.cc::jjGETPROPC");
551    return TRUE;
552  }
553  return FALSE;
554}
555
556BOOLEAN getprop(leftv res, leftv args)
557{
558  leftv u = args;
559  if ((u != NULL) && (u->Typ() == coneID))
560  {
561    leftv v = u->next;
562    if ((v != NULL) && (v->Typ() == STRING_CMD))
563    {
564      if (v->next == NULL) return jjGETPROPC(res, u, v);
565    }
566  }
567  WerrorS("getprop: unexpected parameters");
568  return TRUE;
569}
570
571BOOLEAN cone_intersect(leftv res, leftv args)
572{
573  leftv u = args;
574  if ((u != NULL) && (u->Typ() == coneID))
575  {
576    leftv v = u->next;
577    if ((v != NULL) && (v->Typ() == coneID))
578    {
579      gfan::ZCone* zc1 = (gfan::ZCone*)u->Data();
580      gfan::ZCone* zc2 = (gfan::ZCone*)v->Data();
581      int d1 = zc1->ambientDimension();
582      int d2 = zc2->ambientDimension();
583      if (d1 != d2)
584        Werror("expected ambient dims of both cones to coincide\n"
585               "but got %d and %d", d1, d2);
586      gfan::ZCone zc3 = gfan::intersection(*zc1, *zc2);
587      res->rtyp = coneID;
588      res->data = (void *)new gfan::ZCone(zc3);
589      return FALSE;
590    }
591  }
592  WerrorS("cone_intersect: unexpected parameters");
593  return TRUE;
594}
595
596BOOLEAN cone_link(leftv res, leftv args)
597{
598  leftv u = args;
599  if ((u != NULL) && (u->Typ() == coneID))
600  {
601    leftv v = u->next;
602    if ((v != NULL) && (v->Typ() == INTVEC_CMD))
603    {
604      gfan::ZCone* zc = (gfan::ZCone*)u->Data();
605      intvec* iv = (intvec*)v->Data();
606      gfan::ZVector zv= intvec2ZVector(iv);
607      int d1 = zc->ambientDimension();
608      int d2 = zv.size();
609      if (d1 != d2)
610        Werror("expected ambient dim of cone and size of vector\n"
611               "to be equal but got %d and %d", d1, d2);
612      if(!zc->contains(zv))
613      {
614        WerrorS("the provided intvec does not lie in the cone");
615      }
616      res->rtyp = coneID;
617      res->data = (void *)new gfan::ZCone(zc->link(zv));
618      return FALSE;
619    }
620  }
621  WerrorS("cone_link: unexpected parameters");
622  return TRUE;
623}
624
625static BOOLEAN jjCONTAINS2(leftv res, leftv u, leftv v)
626{
627  gfan::ZCone* zc1 = (gfan::ZCone*)u->Data();
628  gfan::ZCone* zc2 = (gfan::ZCone*)v->Data();
629  int d1 = zc1->ambientDimension();
630  int d2 = zc2->ambientDimension();
631  if (d1 != d2)
632    Werror("expected cones with same ambient dimensions\n but got"
633           " dimensions %d and %d", d1, d2);
634  res->rtyp = INT_CMD;
635  res->data = (void *)(zc1->contains(*zc2) ? 1 : 0);
636  return FALSE;
637}
638
639static BOOLEAN jjCONTAINS3(leftv res, leftv u, leftv v, leftv w)
640{
641  gfan::ZCone* zc = (gfan::ZCone*)u->Data();
642  intvec* vec = (intvec*)v->Data();
643  int flag = (int)(long)w->Data();
644  gfan::ZVector zv = intvec2ZVector(vec);
645  int d1 = zc->ambientDimension();
646  int d2 = zv.size();
647  if (d1 != d2)
648    Werror("expected ambient dim of cone and size of vector\n"
649           "to be equal but got %d and %d", d1, d2);
650  res->rtyp = INT_CMD;
651  if (flag)
652    res->data = (void *)(zc->containsRelatively(zv) ? 1 : 0);
653  else
654    res->data = (void *)(zc->contains(zv) ? 1 : 0);;
655  return FALSE;
656}
657
658BOOLEAN contains(leftv res, leftv args)
659{
660
661  leftv u = args;
662  if ((u != NULL) && (u->Typ() == coneID))
663  {
664    leftv v = u->next;
665    if ((v != NULL) && (v->Typ() == coneID)) return jjCONTAINS2(res, u, v); 
666    if ((v != NULL) && (v->Typ() == INTVEC_CMD))
667    {
668      leftv w = v->next;
669      if ((w != NULL) && (w->Typ() == INT_CMD)) return jjCONTAINS3(res, u, v, w);
670    }
671  }
672  WerrorS("contains: unexpected parameters");
673  return TRUE;
674}
675
676static BOOLEAN jjSETPROPC3A(leftv res, leftv u, leftv v, leftv w)
677{
678  gfan::ZCone* zc = (gfan::ZCone*)u->Data();
679  char* prop = (char*)v->Data();
680  int val = (int)(long)w->Data();
681
682  if (strcmp(prop, "MULTIPLICITY") == 0)
683  {
684    zc->setMultiplicity(gfan::Integer(val));
685  }
686  else
687  {
688    Werror("unexpected cone property '%s'", prop);
689    return TRUE;
690  }
691  res->rtyp = NONE;
692  res->data = NULL;
693  return FALSE;
694}
695static BOOLEAN jjSETPROPC3B(leftv res, leftv u, leftv v, leftv w)
696{
697  gfan::ZCone* zc = (gfan::ZCone*)u->Data();
698  char* prop = (char*)v->Data();
699  intvec* mat = (intvec*)w->Data();
700  gfan::ZMatrix zm = intmat2ZMatrix(mat);
701
702  if (strcmp(prop, "LINEAR_FORMS") == 0)
703  {
704    zc->setLinearForms(zm);
705  }
706  else
707  {
708    Werror("unexpected cone property '%s'", prop);
709    return TRUE;
710  }
711  res->rtyp = NONE;
712  res->data = NULL;
713  return FALSE;
714}
715
716BOOLEAN setprop(leftv res, leftv args)
717{
718
719  leftv u = args;
720  if ((u != NULL) && (u->Typ() == coneID))
721  {
722    leftv v = u->next;
723    if ((v != NULL) && (v->Typ() == STRING_CMD))
724    {
725      leftv w = v->next;
726      if ((w != NULL) && (w->Typ() == INT_CMD)) return jjSETPROPC3A(res, u, v, w);
727      if ((w != NULL) && (w->Typ() == INTMAT_CMD)) return jjSETPROPC3B(res, u, v, w);
728    } 
729  }
730  WerrorS("setprop: unexpected parameters");
731  return TRUE;
732}
733
734void bbcone_setup()
735{
736  blackbox *b=(blackbox*)omAlloc0(sizeof(blackbox));
737  // all undefined entries will be set to default in setBlackboxStuff
738  // the default Print is quite usefule,
739  // all other are simply error messages
740  b->blackbox_destroy=bbcone_destroy;
741  b->blackbox_String=bbcone_String;
742  //b->blackbox_Print=blackbox_default_Print;
743  b->blackbox_Init=bbcone_Init;
744  b->blackbox_Copy=bbcone_Copy;
745  b->blackbox_Assign=bbcone_Assign;
746  iiAddCproc("","cone_via_rays",FALSE,cone_via_rays);
747  iiAddCproc("","cone_via_normals",FALSE,cone_via_normals);
748  iiAddCproc("","getprop",FALSE,getprop);
749  iiAddCproc("","cone_intersect",FALSE,cone_intersect);
750  iiAddCproc("","cone_link",FALSE,cone_link);
751  iiAddCproc("","contains",FALSE,contains);
752  iiAddCproc("","setprop",FALSE,setprop);
753  coneID=setBlackboxStuff(b,"cone");
754  Print("created type %d (cone)\n",coneID); 
755}
756
757#endif
758/* HAVE_FANS */
Note: See TracBrowser for help on using the repository browser.