31#include <visp3/core/vpConfig.h>
33#ifndef DOXYGEN_SHOULD_SKIP_THIS
43#include <visp3/core/vpException.h>
44#include <visp3/core/vpPoint.h>
50Model_3D getExtension(
const char *file)
52 std::string sfilename(file);
54 size_t bnd = sfilename.find(
"bnd");
55 size_t BND = sfilename.find(
"BND");
56 size_t wrl = sfilename.find(
"wrl");
57 size_t WRL = sfilename.find(
"WRL");
59 size_t size = sfilename.size();
61 if ((bnd > 0 && bnd < size) || (BND > 0 && BND < size))
63 else if ((wrl > 0 && wrl < size) || (WRL > 0 && WRL < size)) {
64#if defined(VISP_HAVE_COIN3D)
67 std::cout <<
"Coin not installed, cannot read VRML files" << std::endl;
68 throw std::string(
"Coin not installed, cannot read VRML files");
77void set_scene(
const char *str, Bound_scene *sc,
float factor)
82 if ((fd = fopen(str,
"r")) == NULL) {
83 std::string
error =
"The file " + std::string(str) +
" can not be opened";
87 open_keyword(keyword_tbl);
90 malloc_Bound_scene(sc, str, (Index)BOUND_NBR);
94 if (std::fabs(factor) > std::numeric_limits<double>::epsilon()) {
95 for (
int i = 0;
i < sc->bound.nbr;
i++) {
96 for (
int j = 0;
j < sc->bound.ptr[
i].point.nbr;
j++) {
97 sc->bound.ptr[
i].point.ptr[
j].x = sc->bound.ptr[
i].point.ptr[
j].x * factor;
98 sc->bound.ptr[
i].point.ptr[
j].y = sc->bound.ptr[
i].point.ptr[
j].y * factor;
99 sc->bound.ptr[
i].point.ptr[
j].z = sc->bound.ptr[
i].point.ptr[
j].z * factor;
110#if defined(VISP_HAVE_COIN3D)
112void set_scene_wrl(
const char *str, Bound_scene *sc,
float factor)
117 SbBool ok = in.openFile(str);
118 SoVRMLGroup *sceneGraphVRML2;
124 if (!in.isFileVRML2()) {
125 SoSeparator *sceneGraph = SoDB::readAll(&in);
126 if (sceneGraph == NULL) {
130 SoToVRML2Action tovrml2;
131 tovrml2.apply(sceneGraph);
132 sceneGraphVRML2 = tovrml2.getVRML2SceneGraph();
133 sceneGraphVRML2->ref();
137 sceneGraphVRML2 = SoDB::readAllVRML(&in);
138 if (sceneGraphVRML2 == NULL) {
142 sceneGraphVRML2->ref();
147 int nbShapes = sceneGraphVRML2->getNumChildren();
151 malloc_Bound_scene(sc, str, (Index)BOUND_NBR);
154 for (
int i = 0;
i < nbShapes;
i++) {
155 child = sceneGraphVRML2->getChild(i);
156 if (child->getTypeId() == SoVRMLShape::getClassTypeId()) {
157 std::list<indexFaceSet *> ifs_list;
158 SoChildList *child2list = child->getChildren();
159 for (
int j = 0;
j < child2list->getLength();
j++) {
160 if (((SoNode *)child2list->get(j))->getTypeId() == SoVRMLIndexedFaceSet::getClassTypeId()) {
161 indexFaceSet *ifs =
new indexFaceSet;
162 SoVRMLIndexedFaceSet *face_set;
163 face_set = (SoVRMLIndexedFaceSet *)child2list->get(j);
164 extractFaces(face_set, ifs);
165 ifs_list.push_back(ifs);
177 ifsToBound(&(sc->bound.ptr[iterShapes]), ifs_list);
178 destroyIfs(ifs_list);
184 if (std::fabs(factor) > std::numeric_limits<double>::epsilon()) {
185 for (
int i = 0;
i < sc->bound.nbr;
i++) {
186 for (
int j = 0;
j < sc->bound.ptr[
i].point.nbr;
j++) {
187 sc->bound.ptr[
i].point.ptr[
j].x = sc->bound.ptr[
i].point.ptr[
j].x * factor;
188 sc->bound.ptr[
i].point.ptr[
j].y = sc->bound.ptr[
i].point.ptr[
j].y * factor;
189 sc->bound.ptr[
i].point.ptr[
j].z = sc->bound.ptr[
i].point.ptr[
j].z * factor;
195void extractFaces(SoVRMLIndexedFaceSet *face_set, indexFaceSet *ifs)
199 SoVRMLCoordinate *coord = (SoVRMLCoordinate *)(face_set->coord.getValue());
200 int coordSize = coord->point.getNum();
202 ifs->nbPt = coordSize;
203 for (
int i = 0;
i < coordSize;
i++) {
204 SbVec3f point(0, 0, 0);
205 point[0] = coord->point[
i].getValue()[0];
206 point[1] = coord->point[
i].getValue()[1];
207 point[2] = coord->point[
i].getValue()[2];
208 vpPoint pt(point[0], point[1], point[2]);
209 ifs->pt.push_back(pt);
212 SoMFInt32 indexList = face_set->coordIndex;
213 int indexListSize = indexList.getNum();
215 ifs->nbIndex = indexListSize;
216 for (
int i = 0;
i < indexListSize;
i++) {
217 int index = face_set->coordIndex[
i];
218 ifs->index.push_back(index);
222void ifsToBound(Bound *bptr, std::list<indexFaceSet *> &ifs_list)
225 for (std::list<indexFaceSet *>::const_iterator it = ifs_list.begin(); it != ifs_list.end(); ++it) {
228 bptr->point.nbr = (Index)nbPt;
229 bptr->point.ptr = (Point3f *)malloc(
static_cast<unsigned int>(nbPt) *
sizeof(Point3f));
231 unsigned int iter = 0;
232 for (std::list<indexFaceSet *>::const_iterator it = ifs_list.begin(); it != ifs_list.end(); ++it) {
233 indexFaceSet *ifs = *it;
234 for (
unsigned int j = 0; j < static_cast<unsigned int>(ifs->nbPt);
j++) {
235 bptr->point.ptr[
iter].x =
static_cast<float>(ifs->pt[
j].get_oX());
236 bptr->point.ptr[
iter].y =
static_cast<float>(ifs->pt[
j].get_oY());
237 bptr->point.ptr[
iter].z =
static_cast<float>(ifs->pt[
j].get_oZ());
242 unsigned int nbFace = 0;
243 std::list<int> indSize;
245 for (std::list<indexFaceSet *>::const_iterator it = ifs_list.begin(); it != ifs_list.end(); ++it) {
246 indexFaceSet *ifs = *it;
247 for (
unsigned int j = 0; j < static_cast<unsigned int>(ifs->nbIndex);
j++) {
248 if (ifs->index[j] == -1) {
250 indSize.push_back(indice);
258 bptr->face.nbr = (Index)nbFace;
259 bptr->face.ptr = (Face *)malloc(nbFace *
sizeof(Face));
261 std::list<int>::const_iterator iter_indSize = indSize.begin();
262 for (
unsigned int i = 0;
i < indSize.size();
i++) {
263 bptr->face.ptr[
i].vertex.nbr = (Index)*iter_indSize;
264 bptr->face.ptr[
i].vertex.ptr = (Index *)malloc(
static_cast<unsigned int>(*iter_indSize) *
sizeof(Index));
270 for (std::list<indexFaceSet *>::const_iterator it = ifs_list.begin(); it != ifs_list.end(); ++it) {
271 indexFaceSet *ifs = *it;
273 for (
unsigned int j = 0; j <static_cast<unsigned int>(ifs->nbIndex);
j++) {
274 if (ifs->index[j] != -1) {
275 bptr->face.ptr[indice].vertex.ptr[
iter] = (Index)(ifs->index[j] + offset);
287void destroyIfs(std::list<indexFaceSet *> &ifs_list)
289 for (std::list<indexFaceSet *>::const_iterator it = ifs_list.begin(); it != ifs_list.end(); ++it) {
295void set_scene_wrl(
const char * , Bound_scene * ,
float ) { }
303 for (
unsigned int i = 0;
i < 4;
i++) {
304 for (
unsigned int j = 0;
j < 4;
j++)
305 jlcM[j][i] =
static_cast<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 ...