File: renderer.cpp

package info (click to toggle)
gfan 0.5%2Bdfsg-5
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 8,296 kB
  • ctags: 5,612
  • sloc: cpp: 39,675; makefile: 453; sh: 1
file content (171 lines) | stat: -rw-r--r-- 3,362 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#include "renderer.h"

#include <math.h>

int StandardMonomialRenderer::getOffsetX()
{
  return boxSize*maxEntry*(1+2*(position%numberOfDrawingsPerLine));
}


int StandardMonomialRenderer::getOffsetY()
{
  return boxSize*maxEntry*(1+2*(position/numberOfDrawingsPerLine));
}


bool StandardMonomialRenderer::isInInitialIdeal(const PolynomialSet &s,int x, int y, int z)
{
  IntegerVector v(3);
  v[0]=x;
  v[1]=y;
  v[2]=z;
  PolynomialSet::const_iterator i;
  for(i=s.begin();i!=s.end();i++)
    if(i->getMarked().m.exponent.divides(v))break;

  return i!=s.end();
}


int StandardMonomialRenderer::trace(const PolynomialSet &s, int x, int y, int z, int d)
{
  int pos=0;

  while(1)
    {
      bool wasIn=isInInitialIdeal(s,x,y,z);
      if(!wasIn)return -1;

      switch(d)
	{
	case 0:
	  pos=x;
	  x--;
	  break;
	case 1:
	  pos=y;
	  y--;
	  break;
	case 2:
	  pos=z;
	  z--;
	  break;
	}

      if(x<0 || y<0 || z<0)break;

      bool isIn=isInInitialIdeal(s,x,y,z);

      if(!isIn && wasIn)
	return pos;
    }

  return 0;
}


void StandardMonomialRenderer::putPoint(float x, float y, int rotation, float size)
{ //rotation is clockwise
  fprintf(f," %i %i",getOffsetX()+int(x+size*sin(rotation*3.1415927f/3)),getOffsetY()+int(y-size*cos(rotation*3.1415927f/3)));
}


void StandardMonomialRenderer::drawQuad(int x, int y, int z, int rotation, int color, int intensity)
{
  fprintf(f,"2 3 0 1 0 %i 50 0 %i 0.000 0 0 -1 0 0 5\n        ",color, intensity);
  putPoint((x-y)*boxSize*sqrt(0.75),boxSize*(0.5*(x+y)-z),0,0);
  putPoint((x-y)*boxSize*sqrt(0.75),boxSize*(0.5*(x+y)-z),rotation,boxSize);
  putPoint((x-y)*boxSize*sqrt(0.75),boxSize*(0.5*(x+y)-z),rotation+1,boxSize);
  putPoint((x-y)*boxSize*sqrt(0.75),boxSize*(0.5*(x+y)-z),rotation+2,boxSize);
  putPoint((x-y)*boxSize*sqrt(0.75),boxSize*(0.5*(x+y)-z),0,0);
  fprintf(f,"\n");
}


StandardMonomialRenderer::StandardMonomialRenderer(FILE *f):
  numberOfDrawingsPerLine(5),
  maxEntry(8),
  position(0),
  boxSize(120)
{
  this->f=f;
  fprintf(f,"#FIG 3.2\n"
          "Landscape\n"
          "Center\n"
          "Inches\n"
          "Letter\n"
          "100.00\n"
          "Single\n"
          "-2\n"
          "1200 2\n");
}


void StandardMonomialRenderer::setMaxEntry(int maxEntry)
{
  this->maxEntry=maxEntry;
}


void StandardMonomialRenderer::setBoxSize(int boxSize)
{
  this->boxSize=boxSize;
}


void StandardMonomialRenderer::setNumberOfDrawingsPerLine(int numberOfDrawingsPerLine)
{
  this->numberOfDrawingsPerLine=numberOfDrawingsPerLine;
}


void StandardMonomialRenderer::render(const PolynomialSet &s)
{
  int x,y,z;
  bool color=false;

  x=maxEntry;
  for(y=0;y<maxEntry;y++)
    for(z=0;z<maxEntry;z++)
      {
	int pos=trace(s,x,y,z,0);
	if(pos>=0)
	  {
	    if(color)
	      drawQuad(pos,y,z,4,pos?15:7);
	    else
	      drawQuad(pos,y,z,4,7,pos?10:20);//dark
	  }
      }

  y=maxEntry;
  for(x=0;x<maxEntry;x++)
    for(z=0;z<maxEntry;z++)
      {
	int pos=trace(s,x,y,z,1);
	if(pos>=0)
	  {
	    if(color)
	      drawQuad(x,pos,z,0,pos?17:7);
	    else
	      drawQuad(x,pos,z,0,7,pos?12:20);
	  }
      }

  z=maxEntry;
  for(x=0;x<maxEntry;x++)
    for(y=0;y<maxEntry;y++)
      {
	int pos=trace(s,x,y,z,2);
	if(pos>=0)
	  {
	    if(color)
	      drawQuad(x,y,pos,2,pos?3:7);
	    else
	      drawQuad(x,y,pos,2,7,pos?14:20);//light
     	  }
      }

  position++;
}