001:
002:
003:
004:
005:
006:
007:
008:
009:
010:
011:
012:
013:
014:
015:
016:
017:
018:
019:
020:
021:
022:
023:
024: #include <iostream.h>
025: #include <fstream.h>
026: #include "InventorWriter.h"
027:
028: #ifdef DEBUG_BIN
029:
030: void InventorWriter::writeRGBColor(ofstream & out, float r, float g, float b, float a)
031: {
032: out << "Material { ambientColor " << r << " " << g << " " << b <<
033: " diffuseColor " << r << " " << g << " " << b << " transparency " << a << " }\n";
034:
035:
036:
037: }
038:
039:
040:
041: void InventorWriter::writeColor(ofstream & out, int whatColor)
042: {
043: InventorWriter::writeRGBColor(out,
044: colors[whatColor][0],
045: colors[whatColor][1],
046: colors[whatColor][2], whatColor == 12 ? 0.8 : 0.5);
047: }
048:
049:
050:
051: void InventorWriter::writeTranslation(ofstream & out, float x, float y, float z)
052: {
053: out << "Translation { translation " << x << " " << y << " " << z << " }\n";
054:
055: }
056:
057:
058:
059: void InventorWriter::writeCube(ofstream & out, float xSize, float ySize, float zSize)
060: {
061: out << "Cube { }\n";
062: }
063:
064:
065: void InventorWriter::writeBBox(ofstream & out, int indentLevel, int bbox[3])
066: {
067: for (int l=0; l<indentLevel; l++)
068: out << indent;
069: out << "Coordinate3 {" << endl;
070:
071: for (int l=0; l<indentLevel+1; l++)
072: out << indent;
073: out << "point [" << endl;
074:
075: float origin[] = { -1.05, -1.05, -1.05 };
076: float currentPoint[] = { -1.05, -1.05, -1.05 };
077:
078:
079:
080: for (int i=0; i < 2; i++) {
081: for (int j=0; j < 3; j++) {
082: if(j) currentPoint[j-1] = origin[j-1] + bbox[j-1]*baseUnit;
083:
084: if(i || j) out << "," << endl;
085:
086: for (int l=0; l<indentLevel+2; l++)
087: out << indent;
088: out << currentPoint[0] << " " << currentPoint[1] << " "
089: << currentPoint[2];
090: }
091: currentPoint[0] = -1.05;
092:
093: out << "," << endl;
094: for (int l=0; l<indentLevel+2; l++)
095: out << indent;
096: for (int l=0; l<indentLevel+2; l++)
097: out << indent;
098: out << currentPoint[0] << " " << currentPoint[1] << " "
099: << currentPoint[2];
100:
101: currentPoint[1] = -1.05;
102: currentPoint[2] = origin[2] + bbox[2]*baseUnit;
103: }
104: out << endl;
105:
106: for (int l=0; l<indentLevel+1; l++)
107: out << indent;
108: out << "]" << endl;
109:
110: for (int l=0; l<indentLevel; l++)
111: out << indent;
112: out << "}" << endl;
113:
114:
115:
116: for (int l=0; l<indentLevel; l++)
117: out << indent;
118: out << "IndexedLineSet {" << endl;
119:
120: for (int l=0; l<indentLevel+1; l++)
121: out << indent;
122: out << "coordIndex [" << endl;
123:
124: for (int l=0; l<indentLevel+1; l++)
125: out << indent;
126: out << "0, 1, -1," << endl;
127:
128: for (int l=0; l<indentLevel+1; l++)
129: out << indent;
130: out << "1, 2, -1," << endl;
131:
132: for (int l=0; l<indentLevel+1; l++)
133: out << indent;
134: out << "2, 3, -1," << endl;
135:
136: for (int l=0; l<indentLevel+1; l++)
137: out << indent;
138: out << "3, 0, -1," << endl;
139:
140:
141:
142:
143: for (int l=0; l<indentLevel+1; l++)
144: out << indent;
145: out << "4, 5, -1," << endl;
146:
147: for (int l=0; l<indentLevel+1; l++)
148: out << indent;
149: out << "5, 6, -1," << endl;
150:
151: for (int l=0; l<indentLevel+1; l++)
152: out << indent;
153: out << "6, 7, -1," << endl;
154:
155: for (int l=0; l<indentLevel+1; l++)
156: out << indent;
157: out << "7, 4, -1," << endl;
158:
159:
160:
161: for (int l=0; l<indentLevel+1; l++)
162: out << indent;
163: out << "0, 4, -1," << endl;
164:
165: for (int l=0; l<indentLevel+1; l++)
166: out << indent;
167: out << "1, 5, -1," << endl;
168:
169: for (int l=0; l<indentLevel+1; l++)
170: out << indent;
171: out << "2, 6, -1," << endl;
172:
173: for (int l=0; l<indentLevel+1; l++)
174: out << indent;
175: out << "3, 7, -1" << endl;
176:
177:
178:
179: for (int l=0; l<indentLevel+1; l++)
180: out << indent;
181: out << "]" << endl;
182:
183: for (int l=0; l<indentLevel; l++)
184: out << indent;
185: out << "}" << endl;
186:
187: }
188:
189:
190:
191:
192: char *InventorWriter::header = "#Inventor V2.1 ascii\n\nSeparator {\n";
193: char *InventorWriter::footer = "}";
194: char *InventorWriter::beginGroup = "Separator {\n";
195: char *InventorWriter::endGroup = "}\n";
196: char *InventorWriter::indent = "\t";
197:
198: float InventorWriter::baseUnit = 2.1;
199:
200:
201: float InventorWriter::colors[][3] =
202: {
203: {1, 0, 0},
204: {.7, .3, 0},
205: {.5, 1, .7},
206: {0, 1, 0},
207: {0, .5, .2},
208: {0, .8, .8},
209: {0, 0, 1},
210: {.5, 0, .8},
211: {.7, 0, .5},
212: {.7, .7, .7},
213: {.8, .5, .8},
214: {.8, .8, 0},
215: {1, 1, 1}
216: };
217:
218: #endif