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>
57 Model_3D 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)) {
71 #if defined(VISP_HAVE_COIN3D)
74 std::cout <<
"Coin not installed, cannot read VRML files" << std::endl;
75 throw std::string(
"Coin not installed, cannot read VRML files");
84 void set_scene(
const char *str, Bound_scene *sc,
float factor)
89 if ((fd = fopen(str,
"r")) == NULL) {
90 std::string error =
"The file " + std::string(str) +
" can not be opened";
94 open_keyword(keyword_tbl);
97 malloc_Bound_scene(sc, str, (Index)BOUND_NBR);
101 if (std::fabs(factor) > std::numeric_limits<double>::epsilon()) {
102 for (
int i = 0; i < sc->bound.nbr; i++) {
103 for (
int j = 0; j < sc->bound.ptr[i].point.nbr; j++) {
104 sc->bound.ptr[i].point.ptr[j].x = sc->bound.ptr[i].point.ptr[j].x * factor;
105 sc->bound.ptr[i].point.ptr[j].y = sc->bound.ptr[i].point.ptr[j].y * factor;
106 sc->bound.ptr[i].point.ptr[j].z = sc->bound.ptr[i].point.ptr[j].z * factor;
117 #if defined(VISP_HAVE_COIN3D)
119 void set_scene_wrl(
const char *str, Bound_scene *sc,
float factor)
124 SbBool ok = in.openFile(str);
125 SoVRMLGroup *sceneGraphVRML2;
131 if (!in.isFileVRML2()) {
132 SoSeparator *sceneGraph = SoDB::readAll(&in);
133 if (sceneGraph == NULL) {
137 SoToVRML2Action tovrml2;
138 tovrml2.apply(sceneGraph);
139 sceneGraphVRML2 = tovrml2.getVRML2SceneGraph();
140 sceneGraphVRML2->ref();
144 sceneGraphVRML2 = SoDB::readAllVRML(&in);
145 if (sceneGraphVRML2 == NULL) {
149 sceneGraphVRML2->ref();
154 int nbShapes = sceneGraphVRML2->getNumChildren();
158 malloc_Bound_scene(sc, str, (Index)BOUND_NBR);
161 for (
int i = 0; i < nbShapes; i++) {
162 child = sceneGraphVRML2->getChild(i);
163 if (child->getTypeId() == SoVRMLShape::getClassTypeId()) {
165 std::list<indexFaceSet *> ifs_list;
166 SoChildList *child2list = child->getChildren();
167 for (
int j = 0; j < child2list->getLength(); j++) {
168 if (((SoNode *)child2list->get(j))->getTypeId() == SoVRMLIndexedFaceSet::getClassTypeId()) {
169 indexFaceSet *ifs =
new indexFaceSet;
170 SoVRMLIndexedFaceSet *face_set;
171 face_set = (SoVRMLIndexedFaceSet *)child2list->get(j);
172 extractFaces(face_set, ifs);
173 ifs_list.push_back(ifs);
186 ifsToBound(&(sc->bound.ptr[iterShapes]), ifs_list);
187 destroyIfs(ifs_list);
193 if (std::fabs(factor) > std::numeric_limits<double>::epsilon()) {
194 for (
int i = 0; i < sc->bound.nbr; i++) {
195 for (
int j = 0; j < sc->bound.ptr[i].point.nbr; j++) {
196 sc->bound.ptr[i].point.ptr[j].x = sc->bound.ptr[i].point.ptr[j].x * factor;
197 sc->bound.ptr[i].point.ptr[j].y = sc->bound.ptr[i].point.ptr[j].y * factor;
198 sc->bound.ptr[i].point.ptr[j].z = sc->bound.ptr[i].point.ptr[j].z * factor;
204 void extractFaces(SoVRMLIndexedFaceSet *face_set, indexFaceSet *ifs)
208 SoVRMLCoordinate *coord = (SoVRMLCoordinate *)(face_set->coord.getValue());
209 int coordSize = coord->point.getNum();
211 ifs->nbPt = coordSize;
212 for (
int i = 0; i < coordSize; i++) {
213 SbVec3f point(0, 0, 0);
214 point[0] = coord->point[i].getValue()[0];
215 point[1] = coord->point[i].getValue()[1];
216 point[2] = coord->point[i].getValue()[2];
217 vpPoint pt(point[0], point[1], point[2]);
218 ifs->pt.push_back(pt);
221 SoMFInt32 indexList = face_set->coordIndex;
222 int indexListSize = indexList.getNum();
224 ifs->nbIndex = indexListSize;
225 for (
int i = 0; i < indexListSize; i++) {
226 int index = face_set->coordIndex[i];
227 ifs->index.push_back(index);
231 void ifsToBound(Bound *bptr, std::list<indexFaceSet *> &ifs_list)
234 for (std::list<indexFaceSet *>::const_iterator it = ifs_list.begin(); it != ifs_list.end(); ++it) {
237 bptr->point.nbr = (Index)nbPt;
238 bptr->point.ptr = (Point3f *)malloc((
unsigned int)nbPt *
sizeof(Point3f));
240 unsigned int iter = 0;
241 for (std::list<indexFaceSet *>::const_iterator it = ifs_list.begin(); it != ifs_list.end(); ++it) {
242 indexFaceSet *ifs = *it;
243 for (
unsigned int j = 0; j < (
unsigned int)ifs->nbPt; j++) {
244 bptr->point.ptr[iter].x = (float)ifs->pt[j].get_oX();
245 bptr->point.ptr[iter].y = (float)ifs->pt[j].get_oY();
246 bptr->point.ptr[iter].z = (float)ifs->pt[j].get_oZ();
251 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);
267 bptr->face.nbr = (Index)nbFace;
268 bptr->face.ptr = (Face *)malloc(nbFace *
sizeof(Face));
270 std::list<int>::const_iterator iter_indSize = indSize.begin();
271 for (
unsigned int i = 0; i < indSize.size(); i++) {
272 bptr->face.ptr[i].vertex.nbr = (Index)*iter_indSize;
273 bptr->face.ptr[i].vertex.ptr = (Index *)malloc((
unsigned int)*iter_indSize *
sizeof(Index));
279 for (std::list<indexFaceSet *>::const_iterator it = ifs_list.begin(); it != ifs_list.end(); ++it) {
280 indexFaceSet *ifs = *it;
282 for (
unsigned int j = 0; j < (
unsigned int)ifs->nbIndex; j++) {
283 if (ifs->index[j] != -1) {
284 bptr->face.ptr[indice].vertex.ptr[iter] = (Index)(ifs->index[j] + offset);
296 void destroyIfs(std::list<indexFaceSet *> &ifs_list)
298 for (std::list<indexFaceSet *>::const_iterator it = ifs_list.begin(); it != ifs_list.end(); ++it) {
304 void set_scene_wrl(
const char * , Bound_scene * ,
float ) { }
312 for (
unsigned int i = 0; i < 4; i++) {
313 for (
unsigned int j = 0; j < 4; j++)
314 jlcM[j][i] = (
float)vpM[i][j];
error that can be emitted by ViSP classes.
@ notInitialized
Used to indicate that a parameter is not initialized.
Implementation of an homogeneous matrix and operations on such kind of matrices.
Class that defines a 3D point in the object frame and allows forward projection of a 3D point in the ...