38 #include <visp3/core/vpConfig.h> 40 #ifndef DOXYGEN_SHOULD_SKIP_THIS 46 #include "vpKeyword.h" 50 #include <visp3/core/vpException.h> 51 #include <visp3/core/vpPoint.h> 57 getExtension(
const char* file)
59 std::string sfilename(file);
61 size_t bnd = sfilename.find(
"bnd");
62 size_t BND = sfilename.find(
"BND");
63 size_t wrl = sfilename.find(
"wrl");
64 size_t WRL = sfilename.find(
"WRL");
66 size_t size = sfilename.size();
68 if ((bnd>0 && bnd<size ) || (BND>0 && BND<size))
70 else if ((wrl>0 && wrl<size) || ( WRL>0 && WRL<size))
72 #if defined(VISP_HAVE_COIN3D) 75 std::cout <<
"Coin not installed, cannot read VRML files" << std::endl;
76 throw std::string(
"Coin not installed, cannot read VRML files");
85 void set_scene (
const char* str, Bound_scene *sc,
float factor)
90 if ((fd = fopen (str,
"r")) == NULL)
92 std::string error =
"The file " + std::string(str) +
" can not be opened";
96 open_keyword (keyword_tbl);
98 open_source (fd, str);
99 malloc_Bound_scene (sc, str,(Index)BOUND_NBR);
103 if (std::fabs(factor) > std::numeric_limits<double>::epsilon())
105 for (
int i = 0; i < sc->bound.nbr; i++)
107 for (
int j = 0; j < sc->bound.ptr[i].point.nbr; j++)
109 sc->bound.ptr[i].point.ptr[j].x = sc->bound.ptr[i].point.ptr[j].x*factor;
110 sc->bound.ptr[i].point.ptr[j].y = sc->bound.ptr[i].point.ptr[j].y*factor;
111 sc->bound.ptr[i].point.ptr[j].z = sc->bound.ptr[i].point.ptr[j].z*factor;
122 #if defined(VISP_HAVE_COIN3D) 124 void set_scene_wrl (
const char* str, Bound_scene *sc,
float factor)
129 SbBool ok = in.openFile(str);
130 SoVRMLGroup *sceneGraphVRML2;
136 if(!in.isFileVRML2())
138 SoSeparator *sceneGraph = SoDB::readAll(&in);
139 if (sceneGraph == NULL) { }
142 SoToVRML2Action tovrml2;
143 tovrml2.apply(sceneGraph);
144 sceneGraphVRML2 =tovrml2.getVRML2SceneGraph();
145 sceneGraphVRML2->ref();
150 sceneGraphVRML2 = SoDB::readAllVRML(&in);
151 if (sceneGraphVRML2 == NULL) {
155 sceneGraphVRML2->ref();
160 int nbShapes = sceneGraphVRML2->getNumChildren();
164 malloc_Bound_scene (sc, str,(Index)BOUND_NBR);
167 for (
int i = 0; i < nbShapes; i++)
169 child = sceneGraphVRML2->getChild(i);
170 if (child->getTypeId() == SoVRMLShape::getClassTypeId())
173 std::list<indexFaceSet*> ifs_list;
174 SoChildList * child2list = child->getChildren();
175 for (
int j = 0; j < child2list->getLength(); j++)
177 if (((SoNode*)child2list->get(j))->getTypeId() == SoVRMLIndexedFaceSet::getClassTypeId())
179 indexFaceSet *ifs =
new indexFaceSet;
180 SoVRMLIndexedFaceSet * face_set;
181 face_set = (SoVRMLIndexedFaceSet*)child2list->get(j);
182 extractFaces(face_set,ifs);
183 ifs_list.push_back(ifs);
195 ifsToBound (&(sc->bound.ptr[iterShapes]), ifs_list);
196 destroyIfs(ifs_list);
202 if (std::fabs(factor) > std::numeric_limits<double>::epsilon())
204 for (
int i = 0; i < sc->bound.nbr; i++)
206 for (
int j = 0; j < sc->bound.ptr[i].point.nbr; j++)
208 sc->bound.ptr[i].point.ptr[j].x = sc->bound.ptr[i].point.ptr[j].x*factor;
209 sc->bound.ptr[i].point.ptr[j].y = sc->bound.ptr[i].point.ptr[j].y*factor;
210 sc->bound.ptr[i].point.ptr[j].z = sc->bound.ptr[i].point.ptr[j].z*factor;
217 void extractFaces(SoVRMLIndexedFaceSet* face_set, indexFaceSet *ifs)
221 SoVRMLCoordinate *coord = (SoVRMLCoordinate *)(face_set->coord.getValue());
222 int coordSize = coord->point.getNum();
224 ifs->nbPt = coordSize;
225 for (
int i = 0; i < coordSize; i++)
227 SbVec3f point(0,0,0);
228 point[0]=coord->point[i].getValue()[0];
229 point[1]=coord->point[i].getValue()[1];
230 point[2]=coord->point[i].getValue()[2];
231 vpPoint pt(point[0],point[1],point[2]);
232 ifs->pt.push_back(pt);
235 SoMFInt32 indexList = face_set->coordIndex;
236 int indexListSize = indexList.getNum();
238 ifs->nbIndex = indexListSize;
239 for (
int i = 0; i < indexListSize; i++)
241 int index = face_set->coordIndex[i];
242 ifs->index.push_back(index);
246 void ifsToBound (Bound* bptr, std::list<indexFaceSet*> &ifs_list)
249 for(std::list<indexFaceSet*>::const_iterator it=ifs_list.begin(); it!=ifs_list.end(); ++it){
252 bptr->point.nbr = (Index)nbPt;
253 bptr->point.ptr = (Point3f *) malloc ((
unsigned int)nbPt *
sizeof (Point3f));
256 unsigned int iter = 0;
257 for (std::list<indexFaceSet*>::const_iterator it=ifs_list.begin(); it!=ifs_list.end(); ++it)
259 indexFaceSet* ifs = *it;
260 for (
unsigned int j = 0; j < (
unsigned int)ifs->nbPt; j++)
262 bptr->point.ptr[iter].x = (float)ifs->pt[j].get_oX();
263 bptr->point.ptr[iter].y = (float)ifs->pt[j].get_oY();
264 bptr->point.ptr[iter].z = (float)ifs->pt[j].get_oZ();
269 unsigned int nbFace = 0;
271 std::list<int> indSize;
273 for (std::list<indexFaceSet*>::const_iterator it=ifs_list.begin(); it!=ifs_list.end(); ++it)
275 indexFaceSet* ifs = *it;
276 for (
unsigned int j = 0; j < (
unsigned int)ifs->nbIndex; j++)
278 if(ifs->index[j] == -1)
281 indSize.push_back(indice);
288 bptr->face.nbr = (Index)nbFace;
289 bptr->face.ptr = (Face *) malloc (nbFace *
sizeof (Face));
291 std::list<int>::const_iterator iter_indSize = indSize.begin();
292 for (
unsigned int i = 0; i < indSize.size(); i++)
294 bptr->face.ptr[i].vertex.nbr = (Index)*iter_indSize;
295 bptr->face.ptr[i].vertex.ptr = (Index *) malloc ((
unsigned int)*iter_indSize *
sizeof (Index));
301 for (std::list<indexFaceSet*>::const_iterator it=ifs_list.begin(); it!=ifs_list.end(); ++it)
303 indexFaceSet* ifs = *it;
305 for (
unsigned int j = 0; j < (
unsigned int)ifs->nbIndex; j++)
307 if(ifs->index[j] != -1)
309 bptr->face.ptr[indice].vertex.ptr[iter] = (Index)(ifs->index[j] + offset);
322 void destroyIfs(std::list<indexFaceSet*> &ifs_list)
324 for(std::list<indexFaceSet*>::const_iterator it=ifs_list.begin(); it!=ifs_list.end(); ++it){
330 void set_scene_wrl (
const char* , Bound_scene* ,
float )
340 for (
unsigned int i = 0; i < 4; i++) {
341 for (
unsigned int j = 0; j < 4; j++)
342 jlcM[j][i] = (
float)vpM[i][j];
Implementation of an homogeneous matrix and operations on such kind of matrices.
error that can be emited by ViSP classes.
Class that defines what is a point.