25 #include "IndexLineSetHandler.hh"
27 #include <bias_config.h>
34 dNumberOfLinesInSet_ =0;
39 dNumberOfLinesInSet_ =0;
55 std::vector<std::vector<BIAS::HomgPoint3D> >
59 std::vector<double> point;
60 std::vector<int> linePos;
63 stream.open(fileName.c_str(),ifstream::in);
66 while(tmp !=
"point" && !stream.eof()){
69 if(tmp ==
"point" || tmp ==
"Point")
79 while(tmp !=
"]" && !stream.eof() ) {
84 if(tmp ==
"]" || (tmp.find(
']',0) != string::npos))
86 point.push_back(atof(dummy));
88 if(point.size() == 3){
93 vDetectedPoints_.push_back(point);
98 while(tmp !=
"coordIndex" && !stream.eof()){
101 if(tmp ==
"coordIndex" || tmp ==
"coordIndex")
112 while(tmp !=
"]" && !stream.eof() ){
115 linePos.push_back(atoi(dummy)+vDetectedPoints_.size()-count);
118 if(tmp ==
"]"|| (tmp.find(
']',0) != string::npos))
121 if(tmp ==
"-1" || tmp ==
"-1,"){
125 if(tmp ==
"]"|| (tmp.find(
']',0) != string::npos))
128 linePos.push_back(atoi(dummy)+vDetectedPoints_.size()-count);
131 if(tmp ==
"]"|| (tmp.find(
']',0) != string::npos))
135 linePos.push_back(atoi(dummy)+vDetectedPoints_.size()-count);
137 if(linePos.size() == 2){
141 vConnectingLines_.push_back(linePos);
151 std::vector<std::vector<BIAS::HomgPoint3D> > output;
152 std::vector<BIAS::HomgPoint3D> line;
154 for(
unsigned int k=0;
155 k<vConnectingLines_.size() && k<vDetectedPoints_.size() ;
159 for(
int j=0;j<6;j++){
161 startPoint3D[j] = vDetectedPoints_[vConnectingLines_[k][0]][j];
165 stopPoint3D[j-3] = vDetectedPoints_[vConnectingLines_[k][1]][j-3];
173 line.push_back(startPoint3D);
174 line.push_back(stopPoint3D);
176 output.push_back(line);
178 dNumberOfLinesInSet_++;
185 dNumberOfLines = dNumberOfLinesInSet_;
190 Write(std::string fileName, std::vector<std::vector<BIAS::HomgPoint3D> > fLines)
195 int linesCount = fLines.size();
197 std::vector<double > pointX, pointY, pointZ;
202 std::ofstream stream;
203 stream.open(fileName.c_str(),ofstream::out);
206 stream <<
"#VRML V2.0 utf8" << endl;
207 stream <<
"#Created by BIAS::IndexLineSetWriter amattal/ischiller"
211 stream <<
"Shape{ appearance Appearance { material Material {emissiveColor 1 1 1 }}" << endl;
212 stream <<
" geometry IndexedLineSet {" << endl;
213 stream <<
" coord Coordinate {" << endl;
214 stream <<
" point [" << endl;
220 for (
int i = 0; i < linesCount; i++)
222 if (FindPoint(fLines[i][0], pointX, pointY, pointZ, a) == -1)
225 pointX.push_back(fLines[i][0][0]);
226 pointY.push_back(fLines[i][0][1]);
227 pointZ.push_back(fLines[i][0][2]);
233 << pointZ[a] << endl;
238 if (FindPoint(fLines[i][1], pointX, pointY, pointZ, a) == -1)
242 pointX.push_back(fLines[i][1][0]);
243 pointY.push_back(fLines[i][1][1]);
244 pointZ.push_back(fLines[i][1][2]);
250 << pointZ[a] << endl;
257 stream <<
" ]" << endl;
258 stream <<
" }" << endl;
259 stream <<
" coordIndex [" << endl;
263 std::vector< std::vector< bool > > bEdges;
267 for (
int i = 0; i < size; i++)
269 std::vector< bool > just;
271 for (
int j = 0; j < size; j++)
274 just.push_back(
false);
276 bEdges.push_back(just);
281 for (
int i = 0; i < linesCount; i++)
286 int indexX = FindPoint(fLines[i][0], pointX, pointY, pointZ, a);
287 int indexY = FindPoint(fLines[i][1], pointX, pointY, pointZ, a);
295 bEdges[indexX][indexY] =
true;
296 bEdges[indexY][indexX] =
true;
301 vector<int> sizeOfColumns;
302 sizeOfColumns.reserve(size);
304 for (
int i = 0; i < size; i++)
306 sizeOfColumns[i] = 0;
307 for (
int j = 0; j < size; j++)
319 for (
int i = 0; i < size; i++)
324 while(sizeOfColumns[i] != 0)
333 end = GetColumnElement(bEdges[begin], size);
338 bEdges[begin][end] =
false;
339 bEdges[end][begin] =
false;
342 if(end == begin){sizeOfColumns[end]--;}
345 sizeOfColumns[begin]--;
346 sizeOfColumns[end]--;
349 stream <<
" " << end;
354 stream <<
" " << end;
364 stream <<
" ]" << endl;
365 stream <<
" colorPerVertex FALSE" << endl;
366 stream <<
" }" << endl;
367 stream <<
"}" << endl;
382 int IndexLineSetHandler::
383 GetColumnElement(std::vector< bool > column,
int size)
385 for (
int i = 0; i < size; i++)
398 int IndexLineSetHandler::
400 std::vector<double > pX,
401 std::vector<double > pY,
402 std::vector<double > pZ,
405 for (
int i = 0; i < size; i++)
407 if ((pX[i] == point[0]) &&
408 (pY[i] == point[1]) &&
int Write(std::string fileName, std::vector< std::vector< BIAS::HomgPoint3D > > fLines)
Write a set of lines to disk as a IndexedLineSet.
class HomgPoint3D describes a point with 3 degrees of freedom in projective coordinates.
std::vector< std::vector< BIAS::HomgPoint3D > > Parse(std::string fileName, int &dNumberOfLines)
Parse a IndexLineSet and return lines in it.