source: git/Singular/bbcone.cc @ 06c0b3

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