diff --git a/apps/metro/metro.cpp b/apps/metro/metro.cpp index 1aac54ed..b06c142c 100644 --- a/apps/metro/metro.cpp +++ b/apps/metro/metro.cpp @@ -8,7 +8,7 @@ * \ * * All rights reserved. * * * -* This program is free software; you can redistribute it and/or modify * +* This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.19 2006/03/27 04:17:07 cignoni +moved to generic export.h + Revision 1.18 2006/01/10 13:20:40 cignoni Changed ply::PlyMask to io::Mask @@ -83,7 +86,7 @@ GPL added // standard libraries #include - +using namespace std; // project definitions. #include "defs.h" #include "sampling.h" @@ -97,11 +100,11 @@ GPL added // ----------------------------------------------------------------------------------------------- -using namespace std; + using namespace vcg; -////////////////// Command line Flags and parameters +////////////////// Command line Flags and parameters bool NumberOfSamples = false; bool SamplesPerAreaUnit = false; bool CleaningFlag=false; @@ -155,7 +158,7 @@ void OpenMesh(const char *filename, CMesh &m) printf("Error in reading %s: '%s'\n",filename,tri::io::Importer::ErrorMsg(err)); exit(-1); } - printf("read mesh `%s'\n", filename); + printf("read mesh `%s'\n", filename); if(CleaningFlag){ int dup = tri::Clean::RemoveDuplicateVertex(m); int unref = tri::Clean::RemoveUnreferencedVertex(m); @@ -172,7 +175,7 @@ int main(int argc, char**argv) unsigned long n_samples_target, elapsed_time; double n_samples_per_area_unit; int flags; - + // print program info printf("-------------------------------\n" " Metro V.4.06 \n" @@ -192,7 +195,7 @@ int main(int argc, char**argv) { if(argv[i][0]=='-') switch(argv[i][1]) - { + { case 'h' : flags |= SamplingFlags::HIST; break; case 'v' : flags &= ~SamplingFlags::VERTEX_SAMPLING; break; case 'e' : flags &= ~SamplingFlags::EDGE_SAMPLING; break; @@ -221,17 +224,17 @@ int main(int argc, char**argv) } i++; } - + if(!(flags & SamplingFlags::USE_HASH_GRID) && !(flags & SamplingFlags::USE_AABB_TREE) ) flags |= SamplingFlags::USE_STATIC_GRID; - + // load input meshes. OpenMesh(argv[1],S1); OpenMesh(argv[2],S2); string S1NewName=SaveFileName(argv[1]); string S2NewName=SaveFileName(argv[2]); - + if(!NumberOfSamples && !SamplesPerAreaUnit) { NumberOfSamples = true; @@ -253,7 +256,7 @@ int main(int argc, char**argv) bbox.Offset(bbox.Diag()*0.02); S1.bbox = bbox; S2.bbox = bbox; - + // initialize time info. int t0=clock(); @@ -323,7 +326,7 @@ int main(int argc, char**argv) elapsed_time = clock() - t0; int n_total_sample=ForwardSampling.GetNSamples()+BackwardSampling.GetNSamples(); double mesh_dist_max = max(dist1_max , dist2_max); - + printf("\nHausdorff distance: %f (%f wrt bounding box diagonal)\n",(float)mesh_dist_max,(float)mesh_dist_max/bbox.Diag()); printf(" Computation time : %d ms\n",(int)(1000.0*elapsed_time/CLOCKS_PER_SEC)); printf(" # samples/second : %f\n\n", (float)n_total_sample/((float)elapsed_time/CLOCKS_PER_SEC)); @@ -331,7 +334,7 @@ int main(int argc, char**argv) // save error files. if(flags & SamplingFlags::SAVE_ERROR) { - vcg::tri::io::PlyInfo p; + vcg::tri::io::PlyInfo p; p.mask|=vcg::tri::io::Mask::IOM_VERTCOLOR | vcg::tri::io::Mask::IOM_VERTQUALITY /* | vcg::ply::PLYMask::PM_VERTQUALITY*/ ; //p.mask|=vcg::ply::PLYMask::PM_VERTCOLOR|vcg::ply::PLYMask::PM_VERTQUALITY; if(ColorMax!=0 || ColorMin != 0){ diff --git a/apps/metro/sampling.h b/apps/metro/sampling.h index d4a55617..3632eee7 100644 --- a/apps/metro/sampling.h +++ b/apps/metro/sampling.h @@ -8,7 +8,7 @@ * \ * * All rights reserved. * * * -* This program is free software; you can redistribute it and/or modify * +* This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.21 2006/01/22 10:05:43 cignoni +Corrected use of Area with the unambiguous DoubleArea + Revision 1.20 2005/11/12 06:44:29 cignoni Changed GetClosest -> GetClosestFace @@ -101,7 +104,7 @@ instantiate GridStaticPtr on the simplexClass template. namespace vcg { -struct SamplingFlags{ +struct SamplingFlags{ enum{ HIST = 0x0001, VERTEX_SAMPLING = 0x0002, @@ -120,7 +123,7 @@ struct SamplingFlags{ }; // ----------------------------------------------------------------------------------------------- template -class Sampling +class Sampling { public: @@ -141,11 +144,11 @@ private: typedef Point3 Point3x; - + // data structures - MetroMesh &S1; + MetroMesh &S1; MetroMesh &S2; MetroMeshGrid gS2; MetroMeshHash hS2; @@ -161,11 +164,11 @@ private: int print_every_n_elements ; int referredBit; // parameters - double dist_upper_bound; + double dist_upper_bound; double n_samples_per_area_unit; unsigned long n_samples_target; int Flags; - + // results Histogram hist; unsigned long n_total_samples; @@ -173,7 +176,7 @@ private: unsigned long n_total_edge_samples; unsigned long n_total_vertex_samples; double max_dist; - double mean_dist; + double mean_dist; double RMS_dist; double volume; double area_S1; @@ -242,7 +245,7 @@ Sampling::Sampling(MetroMesh &_s1, MetroMesh &_s2):S1(_s1),S2(_s2) // store the unreferred vertices FaceIterator fi; VertexIterator vi; int i; for(fi = _s1.face.begin(); fi!= _s1.face.end(); ++fi) - for(i=0;i<3;++i) (*fi).V(i)->SetUserBit(referredBit); + for(i=0;i<3;++i) (*fi).V(i)->SetUserBit(referredBit); } template @@ -298,11 +301,11 @@ float Sampling::AddSample(const Point3x &p ) f=trimesh::GetClosestFace(S2, hS2, p, dist_upper_bound, dist, normf, bestq, ip); if(Flags & SamplingFlags::USE_STATIC_GRID) f=trimesh::GetClosestFace(S2, gS2, p, dist_upper_bound, dist, normf, bestq, ip); - + // update distance measures if(dist == dist_upper_bound) return -1.0; - + if(dist > max_dist) max_dist = dist; // L_inf mean_dist += dist; // L_1 @@ -312,7 +315,7 @@ float Sampling::AddSample(const Point3x &p ) if(Flags & SamplingFlags::HIST) hist.Add((float)fabs(dist)); - return (float)dist; + return (float)dist; } @@ -325,7 +328,7 @@ void Sampling::VertexSampling() // Vertex sampling. int cnt = 0; float error; - + printf("Vertex sampling\n"); VertexIterator vi; typename std::vector::iterator vif; @@ -339,7 +342,7 @@ void Sampling::VertexSampling() // save vertex quality if(Flags & SamplingFlags::SAVE_ERROR) (*vi).Q() = error; - + // print progress information if(!(++cnt % print_every_n_elements)) printf("Sampling vertices %d%%\r", (100 * cnt/S1.vn)); @@ -357,7 +360,7 @@ inline void Sampling::SampleEdge(const Point3x & v0, const Point3x & // uniform sampling of the segment v0v1. Point3x e((v1-v0)/(double)(n_samples_per_edge+1)); int i; - + for(i=1; i <= n_samples_per_edge; i++) { AddSample(v0 + e*i); @@ -381,7 +384,7 @@ void Sampling::EdgeSampling() for(int i=0; i<3; ++i) { Edges.push_back(make_pair((*fi).V0(i),(*fi).V1(i))); - if(Edges.back().first > Edges.back().second) + if(Edges.back().first > Edges.back().second) swap(Edges.back().first, Edges.back().second); } sort(Edges.begin(), Edges.end()); @@ -480,7 +483,7 @@ template void Sampling::FaceSubdiv(const Point3x & v0, const Point3x & v1, const Point3x & v2, int maxdepth) { // recursive face subdivision. - if(maxdepth == 0) + if(maxdepth == 0) { // ground case. AddSample((v0+v1+v2)/3.0f); @@ -494,7 +497,7 @@ void Sampling::FaceSubdiv(const Point3x & v0, const Point3x & v1, con double maxd12 = SquaredDistance(v1,v2); double maxd20 = SquaredDistance(v2,v0); int res; - if(maxd01 > maxd12) + if(maxd01 > maxd12) if(maxd01 > maxd20) res = 0; else res = 2; else @@ -503,17 +506,17 @@ void Sampling::FaceSubdiv(const Point3x & v0, const Point3x & v1, con // break the input triangle along the median to the the longest edge. Point3x pp; - switch(res) + switch(res) { - case 0 : pp = (v0+v1)/2; + case 0 : pp = (v0+v1)/2; FaceSubdiv(v0,pp,v2,maxdepth-1); FaceSubdiv(pp,v1,v2,maxdepth-1); break; - case 1 : pp = (v1+v2)/2; + case 1 : pp = (v1+v2)/2; FaceSubdiv(v0,v1,pp,maxdepth-1); FaceSubdiv(v0,pp,v2,maxdepth-1); break; - case 2 : pp = (v2+v0)/2; + case 2 : pp = (v2+v0)/2; FaceSubdiv(v0,v1,pp,maxdepth-1); FaceSubdiv(pp,v1,v2,maxdepth-1); break; @@ -608,15 +611,15 @@ void Sampling::Hausdorff() { Box3< ScalarType> bbox; - + typedef typename std::vector::iterator FaceVecIterator; // set grid meshes. if(Flags & SamplingFlags::USE_HASH_GRID) - hS2.Set::iterator>(S2.face.begin(),S2.face.end()); + hS2.Set(S2.face.begin(),S2.face.end()); if(Flags & SamplingFlags::USE_AABB_TREE) - tS2.Set::iterator>(S2.face.begin(),S2.face.end()); + tS2.Set(S2.face.begin(),S2.face.end()); if(Flags & SamplingFlags::USE_STATIC_GRID) - gS2.Set::iterator>(S2.face.begin(),S2.face.end()); - + gS2.Set(S2.face.begin(),S2.face.end()); + // set bounding box bbox = S2.bbox; dist_upper_bound = /*bbox_factor * */bbox.Diag(); @@ -655,7 +658,7 @@ void Sampling::Hausdorff() // compute vertex colour if(Flags & SamplingFlags::SAVE_ERROR) vcg::tri::UpdateColor::VertexQuality(S1); - + // compute statistics n_samples_per_area_unit = (double) n_total_samples / area_S1; volume = mean_dist / n_samples_per_area_unit / 2.0; diff --git a/vcg/space/index/spatial_hashing.h b/vcg/space/index/spatial_hashing.h index 379ea8a4..becb635f 100644 --- a/vcg/space/index/spatial_hashing.h +++ b/vcg/space/index/spatial_hashing.h @@ -8,7 +8,7 @@ * \ * * All rights reserved. * * * -* This program is free software; you can redistribute it and/or modify * +* This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * @@ -24,6 +24,11 @@ History $Log: not supported by cvs2svn $ +Revision 1.17 2006/01/23 21:26:57 ponchio +gcc compatibility (templates mostly) +bbox -> this->bbox +More consistent use of Box3x and such. + Revision 1.16 2006/01/23 15:26:31 ponchio P1 --> HASH_P1 Old definition was conflicting with functions in segment.h @@ -112,7 +117,7 @@ namespace vcg{ /** Spatial Hash Table Spatial Hashing as described in - "Optimized Spatial Hashing for Coll ision Detection of Deformable Objects", + "Optimized Spatial Hashing for Coll ision Detection of Deformable Objects", Matthias Teschner and Bruno Heidelberger and Matthias Muller and Danat Pomeranets and Markus Gross */ template < typename OBJTYPE,class FLT=double> @@ -121,7 +126,7 @@ namespace vcg{ public: - typedef OBJTYPE ObjType; + typedef OBJTYPE ObjType; typedef ObjType* ObjPtr; typedef typename ObjType::ScalarType ScalarType; typedef Point3 CoordType; @@ -158,7 +163,7 @@ namespace vcg{ public: - //elements + //elements CellContainerType _entries; Cell() @@ -197,10 +202,10 @@ namespace vcg{ Point3i CellN() {return cell_n;} - bool operator ==(const Cell &h) + bool operator ==(const Cell &h) {return (cell_n==h.CellN());} - bool operator !=(const Cell &h) + bool operator !=(const Cell &h) {return ((cell_n!=h.CellN()));} }; // end struct Cell @@ -309,16 +314,16 @@ namespace vcg{ _UpdateHMark(s); return bb; } - - + + /// Insert a mesh in the grid. template void Set(const OBJITER & _oBegin, const OBJITER & _oEnd,const Box3x &_bbox=Box3x() ) { - + OBJITER i; Box3x b; - Box3x &bbox = this->bbox; + Box3x &bbox = this->bbox; CoordType &dim = this->dim; Point3i &siz = this->siz; CoordType &voxel = this->voxel; @@ -336,8 +341,8 @@ namespace vcg{ ScalarType infl=bbox.Diag()/_size; bbox.min -= CoordType(infl,infl,infl); bbox.max += CoordType(infl,infl,infl); - } - + } + dim = bbox.max - bbox.min; BestDim( _size, dim, siz ); // find voxel size @@ -355,17 +360,17 @@ namespace vcg{ { IteHtable I; vcg::Point3i _c; - PToIP(p,_c); + this->PToIP(p,_c); Grid(_c,first,last); } - ///return the simplexes on a specified cell + ///return the simplexes on a specified cell void Grid( int x,int y,int z, CellIterator & first, CellIterator & last ) { Grid(vcg::Point3i(x,y,z),first,last); } - ///return the simplexes on a specified cell + ///return the simplexes on a specified cell void Grid( const Point3i & _c, CellIterator & first, CellIterator & last ) { IteHtable I; @@ -374,7 +379,7 @@ namespace vcg{ first= &*(*I).second._entries.begin(); last= &*(*I).second._entries.end(); } - else + else { ///return 2 equals pointers first=&*(*hash_table.begin()).second._entries.begin(); last= &*(*hash_table.begin()).second._entries.begin(); @@ -409,7 +414,7 @@ namespace vcg{ template - ObjPtr GetClosest(OBJPOINTDISTFUNCTOR & _getPointDistance, OBJMARKER & _marker, + ObjPtr GetClosest(OBJPOINTDISTFUNCTOR & _getPointDistance, OBJMARKER & _marker, const CoordType & _p, const ScalarType & _maxDist,ScalarType & _minDist, CoordType & _closestPt) { return (vcg::GridClosest(*this,_getPointDistance,_marker, _p,_maxDist,_minDist,_closestPt)); @@ -417,7 +422,7 @@ namespace vcg{ template - unsigned int GetKClosest(OBJPOINTDISTFUNCTOR & _getPointDistance,OBJMARKER & _marker, + unsigned int GetKClosest(OBJPOINTDISTFUNCTOR & _getPointDistance,OBJMARKER & _marker, const unsigned int _k, const CoordType & _p, const ScalarType & _maxDist,OBJPTRCONTAINER & _objectPtrs, DISTCONTAINER & _distances, POINTCONTAINER & _points) { @@ -425,14 +430,14 @@ namespace vcg{ OBJPOINTDISTFUNCTOR,OBJMARKER,OBJPTRCONTAINER,DISTCONTAINER,POINTCONTAINER> (*this,_getPointDistance,_marker,_k,_p,_maxDist,_objectPtrs,_distances,_points)); } - + template - unsigned int GetInSphere(OBJPOINTDISTFUNCTOR & _getPointDistance, + unsigned int GetInSphere(OBJPOINTDISTFUNCTOR & _getPointDistance, OBJMARKER & _marker, const CoordType & _p, const ScalarType & _r, OBJPTRCONTAINER & _objectPtrs, - DISTCONTAINER & _distances, + DISTCONTAINER & _distances, POINTCONTAINER & _points) { return(vcg::GridGetInSphere - unsigned int GetInBox(OBJMARKER & _marker, + unsigned int GetInBox(OBJMARKER & _marker, const Box3x _bbox, - OBJPTRCONTAINER & _objectPtrs) + OBJPTRCONTAINER & _objectPtrs) { return(vcg::GridGetInBox (*this,_marker,_bbox,_objectPtrs)); } template - ObjPtr DoRay(OBJRAYISECTFUNCTOR & _rayIntersector, OBJMARKER & _marker, const Ray3 & _ray, const ScalarType & _maxDist, ScalarType & _t) + ObjPtr DoRay(OBJRAYISECTFUNCTOR & _rayIntersector, OBJMARKER & _marker, const Ray3 & _ray, const ScalarType & _maxDist, ScalarType & _t) { return(vcg::GridDoRay (*this,_rayIntersector,_marker,_ray,_maxDist,_t)); @@ -474,12 +479,12 @@ namespace vcg{ typedef typename SpatialHashTable::CellIterator CellIterator; void _UpdateHMark(ObjType* s){ s->HMark() = this->tempMark;} - + /// create an empty spatial hash table void InitEmpty(const Box3x &_bbox, vcg::Point3i grid_size) { Box3x b; - Box3x &bbox = this->bbox; + Box3x &bbox = this->bbox; CoordType &dim = this->dim; Point3i &siz = this->size; CoordType &voxel = this->voxel; @@ -507,7 +512,7 @@ namespace vcg{ } }; - + }// end namespace