38 #include <visp3/core/vpConfig.h> 40 #ifndef DOXYGEN_SHOULD_SKIP_THIS 45 #include "vpKeyword.h" 50 #include <visp3/core/vpException.h> 51 #include <visp3/core/vpPoint.h> 56 Model_3D getExtension(
const char *file)
58 std::string sfilename(file);
60 size_t bnd = sfilename.find(
"bnd");
61 size_t BND = sfilename.find(
"BND");
62 size_t wrl = sfilename.find(
"wrl");
63 size_t WRL = sfilename.find(
"WRL");
65 size_t size = sfilename.size();
67 if ((bnd > 0 && bnd < size) || (BND > 0 && BND < size))
69 else if ((wrl > 0 && wrl < size) || (WRL > 0 && WRL < size)) {
70 #if defined(VISP_HAVE_COIN3D) 73 std::cout <<
"Coin not installed, cannot read VRML files" << std::endl;
74 throw std::string(
"Coin not installed, cannot read VRML files");
83 void set_scene(
const char *str, Bound_scene *sc,
float factor)
88 if ((fd = fopen(str,
"r")) == NULL) {
89 std::string error =
"The file " + std::string(str) +
" can not be opened";
93 open_keyword(keyword_tbl);
96 malloc_Bound_scene(sc, str, (Index)BOUND_NBR);
100 if (std::fabs(factor) > std::numeric_limits<double>::epsilon()) {
101 for (
int i = 0; i < sc->bound.nbr; i++) {
102 for (
int j = 0; j < sc->bound.ptr[i].point.nbr; j++) {
103 sc->bound.ptr[i].point.ptr[j].x = sc->bound.ptr[i].point.ptr[j].x * factor;
104 sc->bound.ptr[i].point.ptr[j].y = sc->bound.ptr[i].point.ptr[j].y * factor;
105 sc->bound.ptr[i].point.ptr[j].z = sc->bound.ptr[i].point.ptr[j].z * factor;
116 #if defined(VISP_HAVE_COIN3D) 118 void set_scene_wrl(
const char *str, Bound_scene *sc,
float factor)
123 SbBool ok = in.openFile(str);
124 SoVRMLGroup *sceneGraphVRML2;
130 if (!in.isFileVRML2()) {
131 SoSeparator *sceneGraph = SoDB::readAll(&in);
132 if (sceneGraph == NULL) {
136 SoToVRML2Action tovrml2;
137 tovrml2.apply(sceneGraph);
138 sceneGraphVRML2 = tovrml2.getVRML2SceneGraph();
139 sceneGraphVRML2->ref();
142 sceneGraphVRML2 = SoDB::readAllVRML(&in);
143 if (sceneGraphVRML2 == NULL) {
147 sceneGraphVRML2->ref();
152 int nbShapes = sceneGraphVRML2->getNumChildren();
156 malloc_Bound_scene(sc, str, (Index)BOUND_NBR);
159 for (
int i = 0; i < nbShapes; i++) {
160 child = sceneGraphVRML2->getChild(i);
161 if (child->getTypeId() == SoVRMLShape::getClassTypeId()) {
163 std::list<indexFaceSet *> ifs_list;
164 SoChildList *child2list = child->getChildren();
165 for (
int j = 0; j < child2list->getLength(); j++) {
166 if (((SoNode *)child2list->get(j))->getTypeId() == SoVRMLIndexedFaceSet::getClassTypeId()) {
167 indexFaceSet *ifs =
new indexFaceSet;
168 SoVRMLIndexedFaceSet *face_set;
169 face_set = (SoVRMLIndexedFaceSet *)child2list->get(j);
170 extractFaces(face_set, ifs);
171 ifs_list.push_back(ifs);
184 ifsToBound(&(sc->bound.ptr[iterShapes]), ifs_list);
185 destroyIfs(ifs_list);
191 if (std::fabs(factor) > std::numeric_limits<double>::epsilon()) {
192 for (
int i = 0; i < sc->bound.nbr; i++) {
193 for (
int j = 0; j < sc->bound.ptr[i].point.nbr; j++) {
194 sc->bound.ptr[i].point.ptr[j].x = sc->bound.ptr[i].point.ptr[j].x * factor;
195 sc->bound.ptr[i].point.ptr[j].y = sc->bound.ptr[i].point.ptr[j].y * factor;
196 sc->bound.ptr[i].point.ptr[j].z = sc->bound.ptr[i].point.ptr[j].z * factor;
202 void extractFaces(SoVRMLIndexedFaceSet *face_set, indexFaceSet *ifs)
206 SoVRMLCoordinate *coord = (SoVRMLCoordinate *)(face_set->coord.getValue());
207 int coordSize = coord->point.getNum();
209 ifs->nbPt = coordSize;
210 for (
int i = 0; i < coordSize; i++) {
211 SbVec3f point(0, 0, 0);
212 point[0] = coord->point[i].getValue()[0];
213 point[1] = coord->point[i].getValue()[1];
214 point[2] = coord->point[i].getValue()[2];
215 vpPoint pt(point[0], point[1], point[2]);
216 ifs->pt.push_back(pt);
219 SoMFInt32 indexList = face_set->coordIndex;
220 int indexListSize = indexList.getNum();
222 ifs->nbIndex = indexListSize;
223 for (
int i = 0; i < indexListSize; i++) {
224 int index = face_set->coordIndex[i];
225 ifs->index.push_back(index);
229 void ifsToBound(Bound *bptr, std::list<indexFaceSet *> &ifs_list)
232 for (std::list<indexFaceSet *>::const_iterator it = ifs_list.begin(); it != ifs_list.end(); ++it) {
235 bptr->point.nbr = (Index)nbPt;
236 bptr->point.ptr = (Point3f *)malloc((
unsigned int)nbPt *
sizeof(Point3f));
239 unsigned int iter = 0;
240 for (std::list<indexFaceSet *>::const_iterator it = ifs_list.begin(); it != ifs_list.end(); ++it) {
241 indexFaceSet *ifs = *it;
242 for (
unsigned int j = 0; j < (
unsigned int)ifs->nbPt; j++) {
243 bptr->point.ptr[iter].x = (float)ifs->pt[j].get_oX();
244 bptr->point.ptr[iter].y = (float)ifs->pt[j].get_oY();
245 bptr->point.ptr[iter].z = (float)ifs->pt[j].get_oZ();
250 unsigned int nbFace = 0;
252 std::list<int> indSize;
254 for (std::list<indexFaceSet *>::const_iterator it = ifs_list.begin(); it != ifs_list.end(); ++it) {
255 indexFaceSet *ifs = *it;
256 for (
unsigned int j = 0; j < (
unsigned int)ifs->nbIndex; j++) {
257 if (ifs->index[j] == -1) {
259 indSize.push_back(indice);
266 bptr->face.nbr = (Index)nbFace;
267 bptr->face.ptr = (Face *)malloc(nbFace *
sizeof(Face));
269 std::list<int>::const_iterator iter_indSize = indSize.begin();
270 for (
unsigned int i = 0; i < indSize.size(); i++) {
271 bptr->face.ptr[i].vertex.nbr = (Index)*iter_indSize;
272 bptr->face.ptr[i].vertex.ptr = (Index *)malloc((
unsigned int)*iter_indSize *
sizeof(Index));
278 for (std::list<indexFaceSet *>::const_iterator it = ifs_list.begin(); it != ifs_list.end(); ++it) {
279 indexFaceSet *ifs = *it;
281 for (
unsigned int j = 0; j < (
unsigned int)ifs->nbIndex; j++) {
282 if (ifs->index[j] != -1) {
283 bptr->face.ptr[indice].vertex.ptr[iter] = (Index)(ifs->index[j] + offset);
294 void destroyIfs(std::list<indexFaceSet *> &ifs_list)
296 for (std::list<indexFaceSet *>::const_iterator it = ifs_list.begin(); it != ifs_list.end(); ++it) {
302 void set_scene_wrl(
const char * , Bound_scene * ,
float ) {}
310 for (
unsigned int i = 0; i < 4; i++) {
311 for (
unsigned int j = 0; j < 4; j++)
312 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 a 3D point in the object frame and allows forward projection of a 3D point in the ...
Used to indicate that a parameter is not initialized.