diff --git a/.github/workflows/BuildSamplesUbuntu.yml b/.github/workflows/BuildExamplesLinux.yml similarity index 55% rename from .github/workflows/BuildSamplesUbuntu.yml rename to .github/workflows/BuildExamplesLinux.yml index 9601bba4..e2fa3b37 100644 --- a/.github/workflows/BuildSamplesUbuntu.yml +++ b/.github/workflows/BuildExamplesLinux.yml @@ -1,12 +1,12 @@ -name: BuildSamplesUbuntu +name: BuildExamplesLinux on: [push, pull_request] jobs: ubuntu_build_tests: - name: Build Samples (Ubuntu) - runs-on: ubuntu-latest #in order to deploy, need to use oldest supported version + name: Build Examples (Linux) + runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 @@ -14,5 +14,7 @@ jobs: uses: jurplel/install-qt-action@v2 - name: Build Samples run: | - qmake apps/sample/sample.pro + mkdir build + cd build + cmake -DVCG_BUILD_EXAMPLES=ON .. make -j4 diff --git a/.github/workflows/BuildSamplesMacOS.yml b/.github/workflows/BuildExamplesMacOS.yml similarity index 64% rename from .github/workflows/BuildSamplesMacOS.yml rename to .github/workflows/BuildExamplesMacOS.yml index 7640a8ea..1c86276f 100644 --- a/.github/workflows/BuildSamplesMacOS.yml +++ b/.github/workflows/BuildExamplesMacOS.yml @@ -1,11 +1,11 @@ -name: BuildSamplesMacOS +name: BuildExamplesMacOS on: [push, pull_request] jobs: macos_build_tests: - name: Build Samples (MacOS) + name: Build Examples (MacOS) runs-on: macos-latest steps: @@ -14,5 +14,7 @@ jobs: uses: jurplel/install-qt-action@v2 - name: Build Samples run: | - qmake apps/sample/sample.pro + mkdir build + cd build + cmake -DVCG_BUILD_EXAMPLES=ON .. make -j4 diff --git a/.github/workflows/BuildSamplesWindows.yml b/.github/workflows/BuildExamplesWindows.yml similarity index 84% rename from .github/workflows/BuildSamplesWindows.yml rename to .github/workflows/BuildExamplesWindows.yml index a9a069b0..f92285cc 100644 --- a/.github/workflows/BuildSamplesWindows.yml +++ b/.github/workflows/BuildExamplesWindows.yml @@ -1,10 +1,10 @@ -name: BuildSamplesWindows +name: BuildExamplesWindows on: [push, pull_request] jobs: windows_build_tests: - name: Build Samples (Windows) + name: Build Examples (Windows) runs-on: windows-latest steps: @@ -25,5 +25,7 @@ jobs: uses: jurplel/install-qt-action@v2 - name: Build Samples run: | - qmake apps/sample/sample.pro + mkdir build + cd build + cmake -G "NMake Makefiles" -DVCG_BUILD_EXAMPLES=ON .. jom -j4 diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..fc28d096 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,303 @@ +# Copyright 2019, 2020, Collabora, Ltd. +# Copyright 2019, 2021, Visual Computing Lab, ISTI - Italian National Research Council +# SPDX-License-Identifier: BSL-1.0 + +cmake_minimum_required(VERSION 3.13) +project(VCGLib) + +# Eigen options +option(ALLOW_BUNDLED_EIGEN "Allow use of bundled Eigen source" ON) +option(ALLOW_SYSTEM_EIGEN "Allow use of system-provided Eigen" ON) + +# VCG options +option(VCG_HEADER_ONLY "Use VCG library in header only mode" ON) +option(VCG_BUILD_EXAMPLES "Build a set of examples of the library" OFF) + +set (VCG_INCLUDE_DIRS ${CMAKE_CURRENT_LIST_DIR}) +set (VCG_INCLUDE_DIRS ${CMAKE_CURRENT_LIST_DIR} PARENT_SCOPE) + +# Prefer GLVND +if(POLICY CMP0072) + cmake_policy(SET CMP0072 NEW) +endif() + +### Build settings +set(CMAKE_CXX_STANDARD 11) + +### Eigen +set(VCG_EIGEN_DIR ${CMAKE_CURRENT_LIST_DIR}/eigenlib) + +if(ALLOW_SYSTEM_EIGEN AND EIGEN3_INCLUDE_DIR) + message(STATUS "- Eigen - using system-provided library") + set(EIGEN_INCLUDE_DIRS ${EIGEN3_INCLUDE_DIR}) +elseif(ALLOW_BUNDLED_EIGEN AND EXISTS "${VCG_EIGEN_DIR}/Eigen/Eigen") + message(STATUS "- Eigen - using bundled source") + set(EIGEN_INCLUDE_DIRS ${VCG_EIGEN_DIR}) +else() + message( + FATAL_ERROR + "Eigen is required - at least one of ALLOW_SYSTEM_EIGEN or ALLOW_BUNDLED_EIGEN must be enabled and found.") +endif() + +### VCGLib headers and sources + +set(VCG_HEADERS + vcg/complex/append.h + vcg/complex/all_types.h + vcg/complex/complex.h + vcg/complex/allocate.h + vcg/complex/exception.h + vcg/complex/algorithms/overlap_estimation.h + vcg/complex/algorithms/dual_meshing.h + vcg/complex/algorithms/intersection.h + vcg/complex/algorithms/clip.h + vcg/complex/algorithms/geodesic.h + vcg/complex/algorithms/parametrization/poisson_solver.h + vcg/complex/algorithms/parametrization/uv_utils.h + vcg/complex/algorithms/parametrization/distortion.h + vcg/complex/algorithms/parametrization/tangent_field_operators.h + vcg/complex/algorithms/parametrization/voronoi_atlas.h + vcg/complex/algorithms/edge_collapse.h + vcg/complex/algorithms/hole.h + vcg/complex/algorithms/align_pair.h + vcg/complex/algorithms/closest.h + vcg/complex/algorithms/tetra_implicit_smooth.h + vcg/complex/algorithms/bitquad_support.h + vcg/complex/algorithms/skeleton.h + vcg/complex/algorithms/symmetry.h + vcg/complex/algorithms/voronoi_volume_sampling.h + vcg/complex/algorithms/polygon_polychord_collapse.h + vcg/complex/algorithms/inside.h + vcg/complex/algorithms/local_optimization/tri_edge_flip.h + vcg/complex/algorithms/local_optimization/quad_diag_collapse.h + vcg/complex/algorithms/local_optimization/tri_edge_collapse_quadric.h + vcg/complex/algorithms/local_optimization/tri_edge_collapse_quadric_tex.h + vcg/complex/algorithms/local_optimization/tri_edge_collapse.h + vcg/complex/algorithms/local_optimization/tetra_edge_collapse.h + vcg/complex/algorithms/polygonal_algorithms.h + vcg/complex/algorithms/inertia.h + vcg/complex/algorithms/mesh_assert.h + vcg/complex/algorithms/cut_tree.h + vcg/complex/algorithms/nring.h + vcg/complex/algorithms/tetra/tetfuse_collapse.h + vcg/complex/algorithms/stat.h + vcg/complex/algorithms/ransac_matching.h + vcg/complex/algorithms/refine.h + vcg/complex/algorithms/outline_support.h + vcg/complex/algorithms/convex_hull.h + vcg/complex/algorithms/clean.h + vcg/complex/algorithms/mesh_to_matrix.h + vcg/complex/algorithms/quadrangulator.h + vcg/complex/algorithms/isotropic_remeshing.h + vcg/complex/algorithms/smooth.h + vcg/complex/algorithms/autoalign_4pcs.h + vcg/complex/algorithms/local_optimization.h + vcg/complex/algorithms/curve_on_manifold.h + vcg/complex/algorithms/clustering.h + vcg/complex/algorithms/refine_loop.h + vcg/complex/algorithms/cylinder_clipping.h + vcg/complex/algorithms/pointcloud_normal.h + vcg/complex/algorithms/bitquad_creation.h + vcg/complex/algorithms/crease_cut.h + vcg/complex/algorithms/implicit_smooth.h + vcg/complex/algorithms/voronoi_remesher.h + vcg/complex/algorithms/polygon_support.h + vcg/complex/algorithms/point_sampling.h + vcg/complex/algorithms/create/mc_lookup_table.h + vcg/complex/algorithms/create/mc_trivial_walker.h + vcg/complex/algorithms/create/extrude.h + vcg/complex/algorithms/create/resampler.h + vcg/complex/algorithms/create/ball_pivoting.h + vcg/complex/algorithms/create/readme.txt + vcg/complex/algorithms/create/zonohedron.h + vcg/complex/algorithms/create/platonic.h + vcg/complex/algorithms/create/marching_cubes.h + vcg/complex/algorithms/create/plymc/voxel.h + vcg/complex/algorithms/create/plymc/simplemeshprovider.h + vcg/complex/algorithms/create/plymc/tri_edge_collapse_mc.h + vcg/complex/algorithms/create/plymc/volume.h + vcg/complex/algorithms/create/plymc/plymc.h + vcg/complex/algorithms/create/plymc/svoxel.h + vcg/complex/algorithms/create/tetramesh_support.h + vcg/complex/algorithms/create/advancing_front.h + vcg/complex/algorithms/textcoord_optimization.h + vcg/complex/algorithms/bitquad_optimization.h + vcg/complex/algorithms/halfedge_quad_clean.h + vcg/complex/algorithms/voronoi_processing.h + vcg/complex/algorithms/update/quality.h + vcg/complex/algorithms/update/selection.h + vcg/complex/algorithms/update/fitmaps.h + vcg/complex/algorithms/update/component_ep.h + vcg/complex/algorithms/update/texture.h + vcg/complex/algorithms/update/curvature_fitting.h + vcg/complex/algorithms/update/normal.h + vcg/complex/algorithms/update/position.h + vcg/complex/algorithms/update/halfedge_topology.h + vcg/complex/algorithms/update/topology.h + vcg/complex/algorithms/update/flag.h + vcg/complex/algorithms/update/bounding.h + vcg/complex/algorithms/update/halfedge_indexed.h + vcg/complex/algorithms/update/color.h + vcg/complex/algorithms/update/curvature.h + vcg/complex/algorithms/point_outlier.h + vcg/complex/algorithms/harmonic.h + vcg/complex/algorithms/point_matching_scale.h + vcg/complex/algorithms/attribute_seam.h + vcg/complex/foreach.h + vcg/complex/base.h + vcg/complex/used_types.h + vcg/container/entries_allocation_table.h + vcg/container/container_allocation_table.h + vcg/container/derivation_chain.h + vcg/container/vector_occ.h + vcg/container/simple_temporary_data.h + vcg/space/segment2.h + vcg/space/fitting3.h + vcg/space/tetra3.h + vcg/space/triangle2.h + vcg/space/ray2.h + vcg/space/deprecated_point2.h + vcg/space/point4.h + vcg/space/box2.h + vcg/space/ray3.h + vcg/space/planar_polygon_tessellation.h + vcg/space/texcoord2.h + vcg/space/deprecated_point3.h + vcg/space/intersection/triangle_triangle3.h + vcg/space/distance2.h + vcg/space/point3.h + vcg/space/deprecated_point.h + vcg/space/space.h + vcg/space/point.h + vcg/space/colorspace.h + vcg/space/rect_packer.h + vcg/space/triangle3.h + vcg/space/obox3.h + vcg/space/point2.h + vcg/space/smallest_enclosing.h + vcg/space/color4.h + vcg/space/polygon3.h + vcg/space/line3.h + vcg/space/index/octree.h + vcg/space/index/grid_util2d.h + vcg/space/index/grid_closest.h + vcg/space/index/grid_static_ptr.h + vcg/space/index/grid_util.h + vcg/space/index/spatial_hashing.h + vcg/space/index/closest2d.h + vcg/space/index/grid_static_obj.h + vcg/space/index/kdtree/kdtree.h + vcg/space/index/kdtree/priorityqueue.h + vcg/space/index/kdtree/kdtree_face.h + vcg/space/index/kdtree/mlsutils.h + vcg/space/index/octree_template.h + vcg/space/index/aabb_binary_tree/kclosest.h + vcg/space/index/aabb_binary_tree/closest.h + vcg/space/index/aabb_binary_tree/ray.h + vcg/space/index/aabb_binary_tree/frustum_cull.h + vcg/space/index/aabb_binary_tree/aabb_binary_tree.h + vcg/space/index/aabb_binary_tree/base.h + vcg/space/index/grid_closest2d.h + vcg/space/index/spatial_hashing2d.h + vcg/space/index/space_iterators.h + vcg/space/index/grid_static_ptr2d.h + vcg/space/index/base2d.h + vcg/space/index/base.h + vcg/space/index/perfect_spatial_hashing.h + vcg/space/index/space_iterators2d.h + vcg/space/line2.h + vcg/space/point_matching.h + vcg/space/intersection3.h + vcg/space/deprecated_point4.h + vcg/space/rasterized_outline2_packer.h + vcg/space/box.h + vcg/space/plane3.h + vcg/space/outline2_packer.h + vcg/space/segment3.h + vcg/space/intersection2.h + vcg/space/sphere3.h + vcg/space/box3.h + vcg/space/distance3.h + vcg/math/quadric5.h + vcg/math/factorial.h + vcg/math/eigen_matrix_addons.h + vcg/math/quadric.h + vcg/math/perlin_noise.h + vcg/math/shot.h + vcg/math/spherical_harmonics.h + vcg/math/eigen_matrixbase_addons.h + vcg/math/quaternion.h + vcg/math/similarity.h + vcg/math/disjoint_set.h + vcg/math/random_generator.h + vcg/math/camera.h + vcg/math/linear.h + vcg/math/matrix44.h + vcg/math/eigen.h + vcg/math/old_lin_algebra.h + vcg/math/similarity2.h + vcg/math/gen_normal.h + vcg/math/old_matrix44.h + vcg/math/old_deprecated_matrix.h + vcg/math/old_matrix33.h + vcg/math/polar_decomposition.h + vcg/math/base.h + vcg/math/histogram.h + vcg/math/legendre.h + vcg/math/matrix33.h + vcg/math/old_matrix.h + vcg/simplex/edge/distance.h + vcg/simplex/edge/topology.h + vcg/simplex/edge/pos.h + vcg/simplex/edge/component.h + vcg/simplex/edge/base.h + vcg/simplex/tetrahedron/tetrahedron.h + vcg/simplex/tetrahedron/topology.h + vcg/simplex/tetrahedron/pos.h + vcg/simplex/tetrahedron/component.h + vcg/simplex/tetrahedron/base.h + vcg/simplex/face/component_occ.h + vcg/simplex/face/component_ep.h + vcg/simplex/face/jumping_pos.h + vcg/simplex/face/distance.h + vcg/simplex/face/component_polygon.h + vcg/simplex/face/topology.h + vcg/simplex/face/pos.h + vcg/simplex/face/component.h + vcg/simplex/face/component_ocf.h + vcg/simplex/face/base.h + vcg/simplex/vertex/component_occ.h + vcg/simplex/vertex/component_sph.h + vcg/simplex/vertex/distance.h + vcg/simplex/vertex/component.h + vcg/simplex/vertex/component_ocf.h + vcg/simplex/vertex/base.h + vcg/connectors/halfedge_pos.h + vcg/connectors/hedge.h + vcg/connectors/hedge_component.h + + #wrap + wrap/callback.h +) + +set(SOURCES +) + +if (VCG_HEADER_ONLY) + add_library(vcglib INTERFACE) + target_include_directories( + vcglib INTERFACE + ${CMAKE_CURRENT_LIST_DIR} + ${EIGEN_INCLUDE_DIRS}) + + #just to show headers in ide + add_custom_target(vcglib_ide SOURCES ${VCG_HEADERS}) +else() + #TODO make vcglib that includes all the wrap sources, checking everytime + # if the the required targets (e.g. qt, gl, glew...) exists +endif() + +if(VCG_BUILD_EXAMPLES) + #TODO make the list of samples to build + add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/apps) +endif() diff --git a/README.md b/README.md index 63209851..d98ee6ec 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ The **_Visualization and Computer Graphics Library_** (VCGlib for short) is a open source, portable, C++, templated, no dependency, library for manipulation, processing, cleaning, simplifying triangle meshes. -![BuildSamplesUbuntu](https://github.com/cnr-isti-vclab/vcglib/workflows/BuildSamplesUbuntu/badge.svg) -![BuildSamplesMacOS](https://github.com/cnr-isti-vclab/vcglib/workflows/BuildSamplesMacOS/badge.svg) -![BuildSamplesWindows](https://github.com/cnr-isti-vclab/vcglib/workflows/BuildSamplesWindows/badge.svg) +![BuildExamplesLinux](https://github.com/cnr-isti-vclab/vcglib/workflows/BuildExamplesLinux/badge.svg) +![BuildExamplesMacOS](https://github.com/cnr-isti-vclab/vcglib/workflows/BuildExamplesMacOS/badge.svg) +![BuildExamplesWindows](https://github.com/cnr-isti-vclab/vcglib/workflows/BuildExamplesWindows/badge.svg) The library, composed by more than 100k lines of code, is released under the GPL license, and it is the base of most of the software tools of the [Visual Computing Lab](http://vcg.isti.cnr.it) of the Italian National Research Council Institute ISTI, like MeshLab, metro and many others. @@ -28,17 +28,10 @@ A number of applications have been developed using the vcglib: - Metro, the tool for measuring differences between meshes - The first high quality out-of-core mesh simplifier that was used by the Stanford Digital Michelangelo project to process their huge 3D scanned models. -## Contributing -In case of bugs please report them [here](https://github.com/cnr-isti-vclab/vcglib/issues). - -Copyright of the library is fully owned by CNR. Contributing means signing an appropriate [license agreement](https://github.com/cnr-isti-vclab/vcglib/blob/master/docs/ContributorLicenseAgreement.pdf) . - -Pull requests about trivial, small, questionable updates (e.g. small stylistic changes like int -> uint8_t) will be rejected without discussion. - - ## Contacts For any info about licensing (portion of) the library please contact us: Paolo Cignoni (p.cignoni@isti.cnr.it) Visual Computing Lab of the Italian National Research Council - ISTI +In case of bugs please report them [here](https://github.com/cnr-isti-vclab/vcglib/issues) . diff --git a/apps/CMakeLists.txt b/apps/CMakeLists.txt index dc516ffe..7af54e3a 100644 --- a/apps/CMakeLists.txt +++ b/apps/CMakeLists.txt @@ -1,9 +1,7 @@ -cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR) -set(CMAKE_CXX_STANDARD 11) -set(CMAKE_BUILD_TYPE Release) -set(CMAKE_CXX_STANDARD_REQUIRED ON) #...is required... -set(CMAKE_CXX_EXTENSIONS OFF) #...without compiler extensions like gnu++11 -include_directories(../) -include_directories(../eigenlib) +cmake_minimum_required(VERSION 3.13) + +project(VCGApps) + +add_subdirectory(sample) add_subdirectory(metro) add_subdirectory(tridecimator) diff --git a/apps/QT/trimesh_QT/glarea.h b/apps/QT/trimesh_QT/glarea.h index 75b17dfa..aaf5c1c1 100644 --- a/apps/QT/trimesh_QT/glarea.h +++ b/apps/QT/trimesh_QT/glarea.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. * @@ -64,10 +64,10 @@ class CMesh : public vcg::tri::TriMesh< std::vector, std::vectorbbox.Center()); + glTranslate(-glWrap.m->bbox.Center()); // the trimesh drawing calls switch(drawmode) { - case SMOOTH: + case SMOOTH: glWrap.Draw (); break; - case PERPOINTS: + case PERPOINTS: glWrap.Draw (); break; - case WIRE: + case WIRE: glWrap.Draw (); break; - case FLATWIRE: + case FLATWIRE: glWrap.Draw (); break; - case HIDDEN: + case HIDDEN: glWrap.Draw (); break; - case FLAT: + case FLAT: glWrap.Draw (); break; - default: + default: break; } @@ -185,7 +185,7 @@ void initMesh() } void TW_CALL loadMesh(void *) -{ +{ if(filename==0) return; int err=vcg::tri::io::ImporterPLY::Open(mesh,(char*)filename); if(err!=0){ @@ -276,7 +276,7 @@ int main(int argc, char *argv[]) // (note that AntTweakBar could also be intialized after GLUT, no matter) if( !TwInit(TW_OPENGL, NULL) ) { - // A fatal error occured + // A fatal error occured fprintf(stderr, "AntTweakBar initialization failed: %s\n", TwGetLastError()); return 1; } @@ -311,12 +311,12 @@ int main(int argc, char *argv[]) glutKeyboardFunc(keyPressEvent); glutKeyboardUpFunc(keyReleaseEvent); - + glutMouseWheelFunc(wheelEvent); bar = TwNewBar("TweakBar"); TwCopyCDStringToClientFunc (CopyCDStringToClient); - + TwAddVarRW(bar,"Input",TW_TYPE_CDSTRING,&filename," label='Filepath' group=SetMesh help=` Name of the file to load` "); TwAddButton(bar,"Load from file",loadMesh,0, " label='Load Mesh' group=SetMesh help=`load the mesh` "); TwAddButton(bar,"Use tetrahedron",loadTetrahedron,0, " label='Make Tetrahedron' group=SetMesh help=`use tetrahedron.` "); diff --git a/apps/metro/CMakeLists.txt b/apps/metro/CMakeLists.txt index f628ace7..aa5ec471 100644 --- a/apps/metro/CMakeLists.txt +++ b/apps/metro/CMakeLists.txt @@ -1,2 +1,17 @@ +cmake_minimum_required(VERSION 3.13) project (metro) -add_executable(metro metro.cpp ../../wrap/ply/plylib.cpp) + +if (VCG_HEADER_ONLY) + set(SOURCES + metro.cpp + ${VCG_INCLUDE_DIRS}/wrap/ply/plylib.cpp) +endif() + +add_executable(metro + ${SOURCES}) + +target_link_libraries( + metro + PUBLIC + vcglib + ) diff --git a/apps/plymc/simplemeshprovider.h b/apps/plymc/simplemeshprovider.h index 9505d33b..e6c38402 100644 --- a/apps/plymc/simplemeshprovider.h +++ b/apps/plymc/simplemeshprovider.h @@ -112,7 +112,7 @@ template // ALNParser::ParseALN(rmaps, alnName); // for(size_t i=0; i::VertexSetV(m); + //note - using unordered_map to set visited vertices because + //the mesh is const (before, the function used vertex flags...). + //could be used std::vector if the vertex has the Index() + //member function... + std::unordered_map vertVisited; + for (ConstVertexIterator vi = m.vert.begin(); vi != m.vert.end(); ++vi) + if (!vi->IsD()) vertVisited[&(*vi)] = true; + // First loop Clear all referenced vertices - for (FaceIterator fi = m.face.begin(); fi != m.face.end(); ++fi) + for (ConstFaceIterator fi = m.face.begin(); fi != m.face.end(); ++fi) if (!fi->IsD()) - for(int i=0;i<3;++i) fi->V(i)->ClearV(); + for(int i=0;i<3;++i){ + vertVisited[fi->V(i)] = false; + } // Second Loop, count (twice) faux edges and mark all vertices touched by non faux edges // (e.g vertexes on the boundary of a polygon) int countE = 0; - for (FaceIterator fi = m.face.begin(); fi != m.face.end(); ++fi) + for (ConstFaceIterator fi = m.face.begin(); fi != m.face.end(); ++fi) if (!fi->IsD()) { for(int i=0;i<3;++i) { @@ -962,16 +971,16 @@ public: countE++; else { - fi->V0(i)->SetV(); - fi->V1(i)->SetV(); + vertVisited[fi->V0(i)] = true; + vertVisited[fi->V1(i)] = true; } } } // Third Loop, count the number of referenced vertexes that are completely surrounded by faux edges. int countV = 0; - for (VertexIterator vi = m.vert.begin(); vi != m.vert.end(); ++vi) - if (!vi->IsD() && !vi->IsV()) countV++; + for (ConstVertexIterator vi = m.vert.begin(); vi != m.vert.end(); ++vi) + if (!vi->IsD() && !(vertVisited[&(*vi)])) countV++; return m.fn - countE/2 + countV ; } @@ -1520,7 +1529,7 @@ public: std::vector< VertexPointer > minVertVec; std::vector< VertexPointer > maxVertVec; - // The set of directions to be choosen + // The set of directions to be chosen std::vector< CoordType > dirVec; dirVec.push_back(CoordType(1,0,0)); dirVec.push_back(CoordType(0,1,0)); diff --git a/vcg/complex/algorithms/harmonic.h b/vcg/complex/algorithms/harmonic.h index ec9a67cd..2c83d103 100644 --- a/vcg/complex/algorithms/harmonic.h +++ b/vcg/complex/algorithms/harmonic.h @@ -235,19 +235,19 @@ public: ScalarT cotB = 0; // Get the edge (a pair of vertices) - VertexType * v0 = f.cV(edge); - VertexType * v1 = f.cV((edge+1)%f.VN()); + const VertexType * v0 = f.cV(edge); + const VertexType * v1 = f.cV((edge+1)%f.VN()); if (fp != NULL && fp != &f) { // not a border edge - VertexType * vb = fp->cV((f.cFFi(edge)+2)%fp->VN()); + const VertexType * vb = fp->cV((f.cFFi(edge)+2)%fp->VN()); ScalarT angleB = ComputeAngle(v0, vb, v1); cotB = vcg::math::Cos(angleB) / vcg::math::Sin(angleB); } - VertexType * va = f.cV((edge+2)%f.VN()); + const VertexType * va = f.cV((edge+2)%f.VN()); ScalarT angleA = ComputeAngle(v0, va, v1); cotA = vcg::math::Cos(angleA) / vcg::math::Sin(angleA); diff --git a/vcg/complex/algorithms/isotropic_remeshing.h b/vcg/complex/algorithms/isotropic_remeshing.h index 264e7c08..5b7ac9ec 100644 --- a/vcg/complex/algorithms/isotropic_remeshing.h +++ b/vcg/complex/algorithms/isotropic_remeshing.h @@ -813,7 +813,7 @@ private: { if (faces[i]->IsFaceEdgeS(VtoE(vIdxes[i], (vIdxes[i]+1)%3)) && !vcg::tri::IsMarked(*params.m, faces[i]->cV1(vIdxes[i]))) { - vcg::tri::Mark(*params.m,faces[i]->cV1(vIdxes[i])); + vcg::tri::Mark(*params.m,faces[i]->V1(vIdxes[i])); incidentFeatures++; CoordType movingEdgeVector0 = (faces[i]->cP1(vIdxes[i]) - faces[i]->cP(vIdxes[i])).Normalize(); if (std::fabs(movingEdgeVector0 * dEdgeVector) < .9f || !p.IsEdgeS()) @@ -821,7 +821,7 @@ private: } if (faces[i]->IsFaceEdgeS(VtoE(vIdxes[i], (vIdxes[i]+2)%3)) && !vcg::tri::IsMarked(*params.m, faces[i]->cV2(vIdxes[i]))) { - vcg::tri::Mark(*params.m,faces[i]->cV2(vIdxes[i])); + vcg::tri::Mark(*params.m,faces[i]->V2(vIdxes[i])); incidentFeatures++; CoordType movingEdgeVector1 = (faces[i]->cP2(vIdxes[i]) - faces[i]->cP(vIdxes[i])).Normalize(); if (std::fabs(movingEdgeVector1 * dEdgeVector) < .9f || !p.IsEdgeS()) diff --git a/vcg/complex/algorithms/mesh_assert.h b/vcg/complex/algorithms/mesh_assert.h index 5f8a174a..ec821a39 100644 --- a/vcg/complex/algorithms/mesh_assert.h +++ b/vcg/complex/algorithms/mesh_assert.h @@ -23,6 +23,10 @@ #ifndef __VCGLIB_MESH_ASSERT #define __VCGLIB_MESH_ASSERT +#include +#include +#include + namespace vcg { namespace tri { /** diff --git a/vcg/complex/algorithms/parametrization/uv_utils.h b/vcg/complex/algorithms/parametrization/uv_utils.h index 6318310e..e93bcedf 100644 --- a/vcg/complex/algorithms/parametrization/uv_utils.h +++ b/vcg/complex/algorithms/parametrization/uv_utils.h @@ -96,11 +96,10 @@ public: } ///calculate the BBox in UV space - static vcg::Box2 PerVertUVBox(MeshType &m) + static vcg::Box2 PerVertUVBox(const MeshType &m) { vcg::Box2 UVBox; - VertexIterator vi; - for (vi=m.vert.begin();vi!=m.vert.end();vi++) + for (auto vi=m.vert.begin();vi!=m.vert.end();vi++) { if ((*vi).IsD()) continue; UVBox.Add((*vi).T().P()); diff --git a/vcg/complex/algorithms/point_sampling.h b/vcg/complex/algorithms/point_sampling.h index 10047237..d5e711f8 100644 --- a/vcg/complex/algorithms/point_sampling.h +++ b/vcg/complex/algorithms/point_sampling.h @@ -35,6 +35,7 @@ sampling strategies (montecarlo, stratified etc). #ifndef __VCGLIB_POINT_SAMPLING #define __VCGLIB_POINT_SAMPLING +#include #include #include @@ -712,8 +713,10 @@ static void FillAndShuffleFacePointerVector(MeshType & m, std::vector &vertVec) { @@ -722,8 +725,10 @@ static void FillAndShuffleVertexPointerVector(MeshType & m, std::vector vs;// vertices of the polygon ExtractPolygon(&*tfi,vs); - std::reverse(vs.begin(),vs.end()); + if (vs.size() > 3) + std::reverse(vs.begin(), vs.end()); //now vs contains all the vertices of the polygon (still in the trimesh) if (vs.size()==0)continue; typename PolyMeshType::FaceIterator pfi = tri::Allocator::AddFaces(pm,1); diff --git a/vcg/complex/algorithms/refine.h b/vcg/complex/algorithms/refine.h index cd3c75a6..082a0228 100644 --- a/vcg/complex/algorithms/refine.h +++ b/vcg/complex/algorithms/refine.h @@ -303,7 +303,7 @@ Given a mesh the following function refines it according to two functor objects: - a predicate that tells if a given edge must be splitted -- a functor that gives you the new poistion of the created vertices (starting from an edge) +- a functor that gives you the new position of the created vertices (starting from an edge) If RefineSelected is true only selected faces are taken into account for being splitted. diff --git a/vcg/complex/algorithms/textcoord_optimization.h b/vcg/complex/algorithms/textcoord_optimization.h index 831e92cd..3c822ace 100644 --- a/vcg/complex/algorithms/textcoord_optimization.h +++ b/vcg/complex/algorithms/textcoord_optimization.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. * @@ -45,13 +45,13 @@ namespace tri /* Base class for all Texture Optimizers*/ -template +template class TextureOptimizer{ protected: MESH_TYPE &m; SimpleTempData isFixed; public: - + /* Tpyes */ typedef MESH_TYPE MeshType; typedef typename MESH_TYPE::VertexIterator VertexIterator; @@ -59,26 +59,26 @@ public: typedef typename MESH_TYPE::VertexType VertexType; typedef typename MESH_TYPE::FaceType FaceType; typedef typename MESH_TYPE::ScalarType ScalarType; - - + + /* Access functions */ const MeshType & Mesh() const {return m;} MeshType & Mesh() {return m;} - + /* Constructior */ TextureOptimizer(MeshType &_m):m(_m),isFixed(_m.vert){ assert(m.HasPerVertexTexture()); } - - // initializes on current geometry + + // initializes on current geometry virtual void TargetCurrentGeometry()=0; - - // performs an interation. Returns largest movement. + + // performs an iteration. Returns largest movement. virtual ScalarType Iterate()=0; - + // performs an iteration (faster, but it does not tell how close it is to stopping) virtual void IterateBlind()=0; - + // performs iteration virtual ScalarType IterateN(int step){ for (int i=0; i1) return this->Iterate(); else return 0; } - + // performs iterations until convergence. bool IterateUntilConvergence(ScalarType threshold=0.0001, int maxite=5000){ int i; @@ -95,34 +95,34 @@ public: } return true; } - + // desctuctor: free temporary field ~TextureOptimizer(){ isFixed.Stop(); }; - + // set the current border as fixed (forced to stay in position during text optimization) void SetBorderAsFixed(){ isFixed.Start(); for (VertexIterator v=m.vert.begin(); v!=m.vert.end(); v++) { - isFixed[v]=(v->IsB())?1:0; - } + isFixed[v]=(v->IsB())?1:0; + } } - + // everything moves, no vertex must fixed during texture optimization) void SetNothingAsFixed(){ isFixed.Start(); for (VertexIterator v=m.vert.begin(); v!=m.vert.end(); v++) { - isFixed[v]=0; - } + isFixed[v]=0; + } } - + // fix a given vertex void FixVertex(const VertexType *v, bool fix=true){ isFixed[v]=(fix)?1:0; } - - + + }; @@ -130,12 +130,12 @@ public: /* AREA PRESERVING TEXTURE OPTIMIZATION -as in: Degener, P., Meseth, J., Klein, R. +as in: Degener, P., Meseth, J., Klein, R. "An adaptable surface parameterization method." - Proc. of the 12th International Meshing oundtable, 201–213 [2003]. + Proc. of the 12th International Meshing oundtable, 201-213 [2003]. Features: - + :) - Balances angle and area distortions (best results!). :) - Can choose how to balance area and angle preservation (see SetTheta) theta=0 -> pure conformal (use MIPS instead!) @@ -144,12 +144,12 @@ Features: :( - Slowest method. :( - Requires a fixed boundary, else expands forever in texture space (unless theta=0). :( - Diverges in presence of flipped faces (unless theta=0). -:( - Requires a speed parameter to be set. +:( - Requires a speed parameter to be set. Speed too large => when close, bounces back and forth around minimum, w/o getting any closer. Lower speed => longer convercence times */ -template +template class AreaPreservingTextureOptimizer:public TextureOptimizer{ public: /* Types */ @@ -159,34 +159,34 @@ public: typedef typename MESH_TYPE::VertexType VertexType; typedef typename MESH_TYPE::FaceType FaceType; typedef typename MESH_TYPE::ScalarType ScalarType; - + private: typedef TextureOptimizer Super; // superclass (commodity) - + // extra data per face: [0..3] -> cotangents. [4] -> area*2 SimpleTempData > data; SimpleTempData > sum; - + ScalarType totArea; ScalarType speed; - + int theta; - + public: - + // constructor and destructor AreaPreservingTextureOptimizer(MeshType &_m):Super(_m),data(_m.face),sum(_m.vert){ speed=0.001; theta=3; } - + ~AreaPreservingTextureOptimizer(){ data.Stop(); sum.Stop(); Super::isFixed.Stop(); } - + void SetSpeed(ScalarType _speed){ speed=_speed; } @@ -194,7 +194,7 @@ public: ScalarType GetSpeed(){ return speed; } - + // sets the parameter theta: // good parameters are in 1..3 // 0 = converge to pure conformal, ignore area preservation @@ -207,16 +207,16 @@ public: int GetTheta(){ return theta; } - + void IterateBlind(){ - /* todo: do as iterate, but without */ + /* todo: do as iterate, but without */ Iterate(); } - + ScalarType Iterate(){ - + ScalarType max; // max displacement - + #define v0 (f->V0(i)->T().P()) #define v1 (f->V1(i)->T().P()) #define v2 (f->V2(i)->T().P()) @@ -236,15 +236,15 @@ public: for (FaceIterator f=Super::m.face.begin(); f!=Super::m.face.end(); f++) { int i=0; ScalarType area2 = ((v1-v0) ^ (v2-v0)); for (i=0; i<3; i++){ - ScalarType + ScalarType a = (v1-v0).Norm(), b = ((v1-v0) * (v2-v0))/a, c = area2 / a, - + m0= data[f][i] / area2, m1= data[f][(i+1)%3] / area2, m2= data[f][(i+2)%3] / area2, - + mx= (b-a)/area2, my= c/area2, // 1.0/a mA= data[f][3]/area2 * scale, @@ -258,35 +258,35 @@ public: /* linear weightings - dx= (OMEGA) * (my * M2) + + dx= (OMEGA) * (my * M2) + (1-OMEGA) * ( px - 2.0*qx), - dy= (OMEGA) * (-mx * M2) + + dy= (OMEGA) * (-mx * M2) + (1-OMEGA) * ( py - 2.0*qy),*/ - + // exponential weighting // 2d gradient - + dx=// M1 - //*M1 // ^ theta-1 + //*M1 // ^ theta-1 pow(M1,theta-1) - *(px*(M1+ theta*M2) - 2.0*qx*M1), + *(px*(M1+ theta*M2) - 2.0*qx*M1), dy=// M1 - //*M1 // ^ theta-1 + //*M1 // ^ theta-1 pow(M1,theta-1) - *(py*(M1+ theta*M2) - 2.0*qy*M1), + *(py*(M1+ theta*M2) - 2.0*qy*M1), gy= dy/c, gx= (dx - gy*b) / a; // 3d gradient - sum[f->V(i)]+= ( (v1-v0) * gx + (v2-v0) * gy ) * data[f][3]; + sum[f->V(i)]+= ( (v1-v0) * gx + (v2-v0) * gy ) * data[f][3]; } } - max=0; // max displacement + max=0; // max displacement speed=0.001; - for (VertexIterator v=Super::m.vert.begin(); v!=Super::m.vert.end(); v++) - if ( !Super::isFixed[v] ) //if (!v->IsB()) + for (VertexIterator v=Super::m.vert.begin(); v!=Super::m.vert.end(); v++) + if ( !Super::isFixed[v] ) //if (!v->IsB()) { ScalarType n=sum[v].Norm(); if ( n > 1 ) { sum[v]/=n; n=1.0;} @@ -298,17 +298,17 @@ public: } return max; #undef v0 - #undef v1 - #undef v2 + #undef v1 + #undef v2 //printf("rejected %d\n",rejected); } - + void TargetCurrentGeometry(){ - + Super::isFixed.Start(); data.Start(); sum.Start(); - + totArea=0; for (FaceIterator f=Super::m.face.begin(); f!=Super::m.face.end(); f++) { double area2 = ((f->V(1)->P() - f->V(0)->P() )^(f->V(2)->P() - f->V(0)->P() )).Norm(); @@ -322,7 +322,7 @@ public: } } } - + }; @@ -333,12 +333,12 @@ public: // returns false if any fold is present (faster than MarkFolds) template bool IsFoldFree(MESH_TYPE &m){ - + assert(m.HasPerVertexTexture()); - + typedef typename MESH_TYPE::VertexType::TextureType::PointType PointType; typedef typename MESH_TYPE::VertexType::TextureType::PointType::ScalarType ScalarType; - + ScalarType lastsign=0; for (typename MESH_TYPE::FaceIterator f=m.face.begin(); f!=m.face.end(); f++){ ScalarType sign=((f->V(1)->T().P()-f->V(0)->T().P()) ^ (f->V(2)->T().P()-f->V(0)->T().P())); @@ -354,16 +354,16 @@ bool IsFoldFree(MESH_TYPE &m){ // returns number of folded faces template int MarkFolds(MESH_TYPE &m){ - + assert(m.HasPerVertexTexture()); assert(m.HasPerFaceQuality()); - + typedef typename MESH_TYPE::VertexType::TextureType::PointType PointType; typedef typename MESH_TYPE::VertexType::TextureType::PointType::ScalarType ScalarType; - + SimpleTempData sign(m.face); sign.Start(0); - + // first pass, determine predominant sign int npos=0, nneg=0; ScalarType lastsign=0; @@ -372,7 +372,7 @@ int MarkFolds(MESH_TYPE &m){ if (fsign<0) { sign[f]=-1; nneg++; } if (fsign>0) { sign[f]=+1; npos++; } } - + // second pass, detect folded faces int res=0; short gsign= (nneg>npos)?-1:+1; @@ -382,28 +382,28 @@ int MarkFolds(MESH_TYPE &m){ f->Q()=0; } else f->Q()=1; } - + sign.Stop(); - + return res; } // Smooths texture coords. -// (can be useful to remove folds, +// (can be useful to remove folds, // e.g. these created when obtaining tecture coordinates after projections) template void SmoothTextureCoords(MESH_TYPE &m){ - + assert(m.HasPerVertexTexture()); - + typedef typename MESH_TYPE::VertexType::TextureType::PointType PointType; - + SimpleTempData div(m.vert); SimpleTempData sum(m.vert); - + div.Start(); sum.Start(); - + for (typename MESH_TYPE::VertexIterator v=m.vert.begin(); v!=m.vert.end(); v++) { sum[v].SetZero(); div[v]=0; @@ -415,13 +415,13 @@ void SmoothTextureCoords(MESH_TYPE &m){ div[f->V(2)] +=2; sum[f->V(2)] += f->V(1)->T().P(); sum[f->V(2)] += f->V(0)->T().P(); } - for (typename MESH_TYPE::VertexIterator v=m.vert.begin(); v!=m.vert.end(); v++) // if (!v->IsB()) + for (typename MESH_TYPE::VertexIterator v=m.vert.begin(); v!=m.vert.end(); v++) // if (!v->IsB()) { if (v->div>0) { v->T().P() = sum[v]/div[v]; } } - + div.Stop(); sum.Stop(); diff --git a/vcg/complex/algorithms/update/flag.h b/vcg/complex/algorithms/update/flag.h index 2a7957c2..75c6860c 100644 --- a/vcg/complex/algorithms/update/flag.h +++ b/vcg/complex/algorithms/update/flag.h @@ -23,6 +23,10 @@ #ifndef __VCG_TRI_UPDATE_FLAGS #define __VCG_TRI_UPDATE_FLAGS +#include +#include +#include + namespace vcg { namespace tri { /// \ingroup trimesh diff --git a/vcg/complex/algorithms/update/normal.h b/vcg/complex/algorithms/update/normal.h index cedd0434..e649e284 100644 --- a/vcg/complex/algorithms/update/normal.h +++ b/vcg/complex/algorithms/update/normal.h @@ -24,8 +24,13 @@ #ifndef __VCG_TRI_UPDATE_NORMALS #define __VCG_TRI_UPDATE_NORMALS +#include +#include + #include +#include "flag.h" + namespace vcg { namespace tri { diff --git a/vcg/complex/algorithms/update/selection.h b/vcg/complex/algorithms/update/selection.h index 221db704..48b90d22 100644 --- a/vcg/complex/algorithms/update/selection.h +++ b/vcg/complex/algorithms/update/selection.h @@ -23,6 +23,13 @@ #ifndef __VCG_TRI_UPDATE_SELECTION #define __VCG_TRI_UPDATE_SELECTION +#include + +#include +#include + +#include "flag.h" + namespace vcg { namespace tri { /// \ingroup trimesh diff --git a/vcg/complex/algorithms/update/topology.h b/vcg/complex/algorithms/update/topology.h index 3dcab7d6..a71f63e9 100644 --- a/vcg/complex/algorithms/update/topology.h +++ b/vcg/complex/algorithms/update/topology.h @@ -24,6 +24,12 @@ #ifndef __VCG_TRI_UPDATE_TOPOLOGY #define __VCG_TRI_UPDATE_TOPOLOGY +#include + +#include +#include +#include + namespace vcg { namespace tri { /// \ingroup trimesh diff --git a/vcg/complex/allocate.h b/vcg/complex/allocate.h index 5ada3e88..b4b337d6 100644 --- a/vcg/complex/allocate.h +++ b/vcg/complex/allocate.h @@ -23,9 +23,12 @@ #ifndef __VCGLIB_TRIALLOCATOR #define __VCGLIB_TRIALLOCATOR -#ifndef __VCG_MESH -#error "This file should not be included alone. It is automatically included by complex.h" -#endif +#include +#include + +#include + +#include "used_types.h" namespace vcg { namespace tri { @@ -1423,8 +1426,9 @@ public: public: - /*! \brief Check if an handle to a Per-Vertex Attribute is valid - */ + /** + * @brief Checks if a handle to a Per-Vertex Attribute is valid + */ template static bool IsValidHandle( const MeshType & m, const typename MeshType::template PerVertexAttributeHandle & a){ @@ -1434,6 +1438,18 @@ public: return false; } + /** + * @brief Checks if a const handle to a Per-Vertex Attribute is valid + */ + template + static + bool IsValidHandle( const MeshType & m, const typename MeshType::template ConstPerVertexAttributeHandle & a){ + if(a._handle == nullptr) return false; + for(AttrIterator i = m.vert_attr.begin(); i!=m.vert_attr.end();++i) + if ( (*i).n_attr == a.n_attr ) return true; + return false; + } + /*! \brief Add a Per-Vertex Attribute of the given ATTR_TYPE with the given name. No attribute with that name must exists (even of different type) @@ -1482,20 +1498,16 @@ public: } return AddPerVertexAttribute(m,name); } - - /*! \brief gives a handle to a per-vertex attribute with a given name and ATTR_TYPE + + /*! \brief gives a const handle to a per-vertex attribute with a given name and ATTR_TYPE \returns a valid handle. If the name is not empty and an attribute with that name and type exists returns a handle to it. Otherwise, returns an invalid handle (check it using IsValidHandle). */ template static - typename MeshType::template PerVertexAttributeHandle + typename MeshType::template ConstPerVertexAttributeHandle GetPerVertexAttribute( const MeshType & m, std::string name = std::string("")){ - typename MeshType::template PerVertexAttributeHandle h; - if(!name.empty()){ - return FindPerVertexAttribute(m,name); - } - return typename MeshType:: template PerVertexAttributeHandle(nullptr,0); + return FindPerVertexAttribute(m,name); } /*! \brief Try to retrieve an handle to an attribute with a given name and ATTR_TYPE @@ -1524,39 +1536,42 @@ public: } return typename MeshType:: template PerVertexAttributeHandle(nullptr,0); } - + /** - * Same as the one above, but without modifying the attribute if it is found. - * (A "find" function should never modify the container in which is looking for..) - * Input mesh is const. + * @brief Try to retrieve a const handle to an attribute with a given name + * and ATTR_TYPE, from the given const mesh. + * If not found, an invalid handle will be returned. + * Check it with the function IsValidHandle */ template - static typename MeshType::template PerVertexAttributeHandle + static typename MeshType::template ConstPerVertexAttributeHandle FindPerVertexAttribute( const MeshType & m, const std::string & name) { - assert(!name.empty()); - PointerToAttribute h1; h1._name = name; - typename std::set :: iterator i; + if(!name.empty()){ + PointerToAttribute h1; h1._name = name; + typename std::set :: iterator i; - i =m.vert_attr.find(h1); - if(i!=m.vert_attr.end()) - if((*i)._sizeof == sizeof(ATTR_TYPE) ){ - return typename MeshType::template PerVertexAttributeHandle((*i)._handle,(*i).n_attr); + i =m.vert_attr.find(h1); + if(i!=m.vert_attr.end()){ + if((*i)._sizeof == sizeof(ATTR_TYPE) ){ + return typename MeshType::template ConstPerVertexAttributeHandle((*i)._handle,(*i).n_attr); + } } - return typename MeshType:: template PerVertexAttributeHandle(nullptr,0); + } + return typename MeshType:: template ConstPerVertexAttributeHandle(nullptr,0); } /*! \brief query the mesh for all the attributes per vertex \returns the name of all attributes with a non-empy name. */ template - static void GetAllPerVertexAttribute(MeshType & m, std::vector &all){ + static void GetAllPerVertexAttribute(const MeshType & m, std::vector &all){ all.clear(); typename std::set ::const_iterator i; for(i = m.vert_attr.begin(); i != m.vert_attr.end(); ++i ) if(!(*i)._name.empty()) { - typename MeshType:: template PerVertexAttributeHandle hh; + typename MeshType:: template ConstPerVertexAttributeHandle hh; hh = Allocator:: template FindPerVertexAttribute (m,(*i)._name); if(IsValidHandle(m,hh)) all.push_back((*i)._name); @@ -1616,6 +1631,15 @@ public: return false; } + template + static + bool IsValidHandle( const MeshType & m, const typename MeshType::template ConstPerEdgeAttributeHandle & a){ + if(a._handle == nullptr) return false; + for(AttrIterator i = m.edge_attr.begin(); i!=m.edge_attr.end();++i) + if ( (*i).n_attr == a.n_attr ) return true; + return false; + } + template static typename MeshType::template PerEdgeAttributeHandle @@ -1662,6 +1686,12 @@ public: return AddPerEdgeAttribute(m,name); } + template + static + typename MeshType::template ConstPerEdgeAttributeHandle + GetPerEdgeAttribute( const MeshType & m, std::string name = std::string("")){ + return FindPerEdgeAttribute(m,name); + } template static @@ -1688,6 +1718,24 @@ public: return typename MeshType:: template PerEdgeAttributeHandle(nullptr,0); } + template + static + typename MeshType::template ConstPerEdgeAttributeHandle + FindPerEdgeAttribute( const MeshType & m, const std::string & name){ + if(!name.empty()){ + PointerToAttribute h1; h1._name = name; + typename std::set ::const_iterator i; + + i =m.edge_attr.find(h1); + if(i!=m.edge_attr.end()){ + if((*i)._sizeof == sizeof(ATTR_TYPE) ){ + return typename MeshType::template ConstPerEdgeAttributeHandle((*i)._handle,(*i).n_attr); + } + } + } + return typename MeshType:: template ConstPerEdgeAttributeHandle(nullptr,0); + } + template static void GetAllPerEdgeAttribute(const MeshType & m, std::vector &all){ all.clear(); @@ -1695,7 +1743,7 @@ public: for(i = m.edge_attr.begin(); i != m.edge_attr.end(); ++i ) if(!(*i)._name.empty()) { - typename MeshType:: template PerEdgeAttributeHandle hh; + typename MeshType:: template ConstPerEdgeAttributeHandle hh; hh = Allocator:: template FindPerEdgeAttribute (m,(*i)._name); if(IsValidHandle(m,hh)) all.push_back((*i)._name); @@ -1731,6 +1779,9 @@ public: } /// Per Face Attributes + /** + * @brief Checks if a handle to a Per-Face attribute is valid + */ template static bool IsValidHandle( const MeshType & m, const typename MeshType::template PerFaceAttributeHandle & a){ @@ -1740,6 +1791,18 @@ public: return false; } + /** + * @brief Checks if a const handle to a Per-Face attribute is valid + */ + template + static + bool IsValidHandle( const MeshType & m, const typename MeshType::template ConstPerFaceAttributeHandle & a){ + if(a._handle == nullptr) return false; + for(AttrIterator i = m.face_attr.begin(); i!=m.face_attr.end();++i) + if ( (*i).n_attr == a.n_attr ) return true; + return false; + } + template static typename MeshType::template PerFaceAttributeHandle @@ -1792,13 +1855,9 @@ public: */ template static - typename MeshType::template PerFaceAttributeHandle + typename MeshType::template ConstPerFaceAttributeHandle GetPerFaceAttribute( const MeshType & m, std::string name = std::string("")){ - typename MeshType::template PerFaceAttributeHandle h; - if(!name.empty()){ - return FindPerFaceAttribute(m,name); - } - return typename MeshType:: template PerFaceAttributeHandle(nullptr,0); + return FindPerFaceAttribute(m,name); } template @@ -1812,7 +1871,7 @@ public: i =m.face_attr.find(h1); if(i!=m.face_attr.end()) if((*i)._sizeof == sizeof(ATTR_TYPE) ){ - if( (*i)._padding != 0 ){ + if( (*i)._padding != 0 ){ PointerToAttribute attr = (*i); // copy the PointerToAttribute m.face_attr.erase(i); // remove it from the set FixPaddedPerFaceAttribute(m,attr); @@ -1826,34 +1885,37 @@ public: } /** - * Same as the one above, but without modifying the attribute if it is found. - * (A "find" function should never modify the container in which is looking for..) - * Input mesh is const. + * @brief Try to retrieve a const handle to an attribute with a given name + * and ATTR_TYPE, from the given const mesh. + * If not found, an invalid handle will be returned. + * Check it with the function IsValidHandle */ template static - typename MeshType::template PerFaceAttributeHandle + typename MeshType::template ConstPerFaceAttributeHandle FindPerFaceAttribute( const MeshType & m, const std::string & name){ - assert(!name.empty()); - PointerToAttribute h1; h1._name = name; - typename std::set ::iterator i; + if(!name.empty()){ + PointerToAttribute h1; h1._name = name; + typename std::set ::iterator i; - i =m.face_attr.find(h1); - if(i!=m.face_attr.end()) - if((*i)._sizeof == sizeof(ATTR_TYPE) ){ - return typename MeshType::template PerFaceAttributeHandle((*i)._handle,(*i).n_attr); + i =m.face_attr.find(h1); + if(i!=m.face_attr.end()){ + if((*i)._sizeof == sizeof(ATTR_TYPE) ){ + return typename MeshType::template ConstPerFaceAttributeHandle((*i)._handle,(*i).n_attr); + } } - return typename MeshType:: template PerFaceAttributeHandle(nullptr,0); + } + return typename MeshType:: template ConstPerFaceAttributeHandle(nullptr,0); } template - static void GetAllPerFaceAttribute(MeshType & m, std::vector &all){ + static void GetAllPerFaceAttribute(const MeshType & m, std::vector &all){ all.clear(); typename std::set :: const_iterator i; for(i = m.face_attr.begin(); i != m.face_attr.end(); ++i ) if(!(*i)._name.empty()) { - typename MeshType:: template PerFaceAttributeHandle hh; + typename MeshType:: template ConstPerFaceAttributeHandle hh; hh = Allocator:: template FindPerFaceAttribute (m,(*i)._name); if(IsValidHandle(m,hh)) all.push_back((*i)._name); @@ -1898,6 +1960,17 @@ public: return false; } + template + static bool IsValidHandle(const MeshType & m, const typename MeshType::template ConstPerTetraAttributeHandle & a) + { + if (a._handle == nullptr) + return false; + for (AttrIterator i = m.tetra_attr.begin(); i != m.tetra_attr.end(); ++i) + if ((*i).n_attr == a.n_attr) + return true; + return false; + } + template static typename MeshType::template PerTetraAttributeHandle AddPerTetraAttribute(MeshType & m, std::string name) { @@ -1943,6 +2016,12 @@ public: return AddPerTetraAttribute(m, name); } + template + static typename MeshType::template ConstPerTetraAttributeHandle GetPerTetraAttribute(const MeshType &m, std::string name = std::string("")) + { + return FindPerTetraAttribute(m, name); + } + template static typename MeshType::template PerTetraAttributeHandle FindPerTetraAttribute(MeshType &m, const std::string &name) { @@ -1970,14 +2049,33 @@ public: } template - static void GetAllPerTetraAttribute(MeshType &m, std::vector &all) + static typename MeshType::template ConstPerTetraAttributeHandle FindPerTetraAttribute(MeshType &m, const std::string &name) + { + if(!name.empty()){ + PointerToAttribute h1; + h1._name = name; + typename std::set::iterator i; + + i = m.tetra_attr.find(h1); + if (i != m.tetra_attr.end()){ + if ((*i)._sizeof == sizeof(ATTR_TYPE)) + { + return typename MeshType::template ConstPerTetraAttributeHandle((*i)._handle, (*i).n_attr); + } + } + } + return typename MeshType::template ConstPerTetraAttributeHandle(nullptr, 0); + } + + template + static void GetAllPerTetraAttribute(const MeshType &m, std::vector &all) { all.clear(); typename std::set::const_iterator i; for (i = m.tetra_attr.begin(); i != m.tetra_attr.end(); ++i) if (!(*i)._name.empty()) { - typename MeshType::template PerTetraAttributeHandle hh; + typename MeshType::template ConstPerTetraAttributeHandle hh; hh = Allocator::template FindPerTetraAttribute(m, (*i)._name); if (IsValidHandle(m, hh)) all.push_back((*i)._name); @@ -2026,6 +2124,15 @@ public: return false; } + template + static + bool IsValidHandle(const MeshType & m, const typename MeshType::template ConstPerMeshAttributeHandle & a){ + if(a._handle == nullptr) return false; + for(AttrIterator i = m.mesh_attr.begin(); i!=m.mesh_attr.end();++i) + if ( (*i).n_attr == a.n_attr ) return true; + return false; + } + template static typename MeshType::template PerMeshAttributeHandle @@ -2064,6 +2171,13 @@ public: return AddPerMeshAttribute(m,name); } + template + static + typename MeshType::template ConstPerMeshAttributeHandle + GetPerMeshAttribute(const MeshType & m, std::string name = std::string("")){ + return FindPerMeshAttribute(m,name); + } + template static typename MeshType::template PerMeshAttributeHandle @@ -2090,6 +2204,24 @@ public: return typename MeshType:: template PerMeshAttributeHandle(nullptr,0); } + template + static + typename MeshType::template ConstPerMeshAttributeHandle + FindPerMeshAttribute( const MeshType & m, const std::string & name){ + if (!name.empty()){ + PointerToAttribute h1; h1._name = name; + typename std::set ::iterator i; + i =m.mesh_attr.find(h1); + if(i!=m.mesh_attr.end()){ + if((*i)._sizeof == sizeof(ATTR_TYPE) ){ + return typename MeshType::template ConstPerMeshAttributeHandle((*i)._handle,(*i).n_attr); + } + } + } + + return typename MeshType:: template ConstPerMeshAttributeHandle(nullptr,0); + } + template static void GetAllPerMeshAttribute(const MeshType & m, std::vector &all){ typename std::set :: iterator i; @@ -2207,7 +2339,7 @@ public: pa._padding = 0; } - template + template static void FixPaddedPerTetraAttribute(MeshType &m, PointerToAttribute &pa) { @@ -2245,7 +2377,7 @@ public: // copy the padded container in the new one char * ptr = (char*)( ((Attribute *)pa._handle)->DataBegin()); - memcpy((void*)_handle->attribute ,(void*) &(ptr[0]) ,sizeof(ATTR_TYPE)); + memcpy((void*)_handle->DataBegin() ,(void*) &(ptr[0]) ,sizeof(ATTR_TYPE)); // remove the padded container delete ( (Attribute *) pa._handle); diff --git a/vcg/complex/append.h b/vcg/complex/append.h index 02580a4b..63c44684 100644 --- a/vcg/complex/append.h +++ b/vcg/complex/append.h @@ -23,9 +23,8 @@ #ifndef __VCGLIB_APPEND #define __VCGLIB_APPEND -#ifndef __VCG_MESH -#error "This file should not be included alone. It is automatically included by complex.h" -#endif +#include +#include namespace vcg { namespace tri { @@ -670,64 +669,76 @@ static void MeshAppendConst( // If the left mesh has attributes that are not in the right mesh, their values for the elements // of the right mesh will be uninitialized - unsigned int id_r; - typename std::set< PointerToAttribute >::iterator al, ar; + unsigned int id_r; + typename std::set< PointerToAttribute >::iterator al, ar; - // per vertex attributes - for(al = ml.vert_attr.begin(); al != ml.vert_attr.end(); ++al) - if(!(*al)._name.empty()){ - ar = mr.vert_attr.find(*al); - if(ar!= mr.vert_attr.end()){ - id_r = 0; - for (auto v: mr.vert){ - if( !v.IsD() && (!selected || v.IsS())) - (*al)._handle->CopyValue(remap.vert[Index(mr,v)], id_r, (*ar)._handle); - ++id_r; - } - } - } + // per vertex attributes + for (al = ml.vert_attr.begin(); al != ml.vert_attr.end(); ++al) + if(!(*al)._name.empty()) + { + ar = mr.vert_attr.find(*al); + if (ar != mr.vert_attr.end()) + { + id_r = 0; + for (const auto & v : mr.vert) + { + if( !v.IsD() && (!selected || v.IsS())) + (*al)._handle->CopyValue(remap.vert[Index(mr,v)], id_r, (*ar)._handle); + ++id_r; + } + } + } - // per edge attributes - for(al = ml.edge_attr.begin(); al != ml.edge_attr.end(); ++al) - if(!(*al)._name.empty()){ - ar = mr.edge_attr.find(*al); - if(ar!= mr.edge_attr.end()){ - id_r = 0; - for (auto e: mr.edge){ - if( !e.IsD() && (!selected || e.IsS())) - (*al)._handle->CopyValue(remap.edge[Index(mr,e)], id_r, (*ar)._handle); - ++id_r; - } - } - } + // per edge attributes + for (al = ml.edge_attr.begin(); al != ml.edge_attr.end(); ++al) + if (!(*al)._name.empty()) + { + ar = mr.edge_attr.find(*al); + if (ar!= mr.edge_attr.end()) + { + id_r = 0; + for (const auto & e : mr.edge) + { + if( !e.IsD() && (!selected || e.IsS())) + (*al)._handle->CopyValue(remap.edge[Index(mr,e)], id_r, (*ar)._handle); + ++id_r; + } + } + } - // per face attributes - for(al = ml.face_attr.begin(); al != ml.face_attr.end(); ++al) - if(!(*al)._name.empty()){ - ar = mr.face_attr.find(*al); - if(ar!= mr.face_attr.end()){ - id_r = 0; - for (auto f: mr.face) { - if( !f.IsD() && (!selected || f.IsS())) - (*al)._handle->CopyValue(remap.face[Index(mr,f)], id_r, (*ar)._handle); - ++id_r; - } - } - } + // per face attributes + for (al = ml.face_attr.begin(); al != ml.face_attr.end(); ++al) + if (!(*al)._name.empty()) + { + ar = mr.face_attr.find(*al); + if (ar!= mr.face_attr.end()) + { + id_r = 0; + for (const auto & f : mr.face) + { + if( !f.IsD() && (!selected || f.IsS())) + (*al)._handle->CopyValue(remap.face[Index(mr,f)], id_r, (*ar)._handle); + ++id_r; + } + } + } - // per tetra attributes - for(al = ml.tetra_attr.begin(); al != ml.tetra_attr.end(); ++al) - if(!(*al)._name.empty()){ - ar = mr.tetra_attr.find(*al); - if(ar!= mr.tetra_attr.end()){ - id_r = 0; - for (auto t: mr.tetra) { - if( !t.IsD() && (!selected || t.IsS())) - (*al)._handle->CopyValue(remap.tetra[Index(mr, t)], id_r, (*ar)._handle); - ++id_r; - } - } - } + // per tetra attributes + for (al = ml.tetra_attr.begin(); al != ml.tetra_attr.end(); ++al) + if (!(*al)._name.empty()) + { + ar = mr.tetra_attr.find(*al); + if (ar!= mr.tetra_attr.end()) + { + id_r = 0; + for (const auto & t: mr.tetra) + { + if( !t.IsD() && (!selected || t.IsS())) + (*al)._handle->CopyValue(remap.tetra[Index(mr, t)], id_r, (*ar)._handle); + ++id_r; + } + } + } // per mesh attributes // if both ml and mr have an attribute with the same name, no action is done diff --git a/vcg/complex/base.h b/vcg/complex/base.h index 828bdcae..88de7028 100644 --- a/vcg/complex/base.h +++ b/vcg/complex/base.h @@ -20,12 +20,17 @@ * for more details. * * * ****************************************************************************/ -#ifndef __VCG_MESH -#error "This file should not be included alone. It is automatically included by complex.h" -#endif + #ifndef __VCG_COMPLEX_BASE #define __VCG_COMPLEX_BASE +#include +#include + +#include + +#include "used_types.h" + namespace vcg { class PointerToAttribute @@ -297,6 +302,25 @@ public: void resize(size_t /*size*/) { }; }; + template + class ConstAttributeHandle{ + public: + ConstAttributeHandle(){_handle=(SimpleTempData *)nullptr;} + ConstAttributeHandle( const void *ah,const int & n):_handle ( (const SimpleTempData *)ah ),n_attr(n){} + + + //pointer to the SimpleTempData that stores the attribute + const SimpleTempData * _handle; + + // its attribute number + int n_attr; + + // access function + template + const ATTR_TYPE & operator [](const RefType & i) const {return (*_handle)[i];} + void resize(size_t /*size*/) { }; + }; + template class PerVertexAttributeHandle: public AttributeHandle{ public: @@ -304,6 +328,12 @@ public: PerVertexAttributeHandle( void *ah,const int & n):AttributeHandle(ah,n){} }; + template + class ConstPerVertexAttributeHandle: public ConstAttributeHandle{ + public: + ConstPerVertexAttributeHandle():ConstAttributeHandle(){} + ConstPerVertexAttributeHandle( const void *ah,const int & n):ConstAttributeHandle(ah,n){} + }; template class PerFaceAttributeHandle: public AttributeHandle{ @@ -312,6 +342,13 @@ public: PerFaceAttributeHandle( void *ah,const int & n):AttributeHandle(ah,n){} }; + template + class ConstPerFaceAttributeHandle: public ConstAttributeHandle{ + public: + ConstPerFaceAttributeHandle():ConstAttributeHandle(){} + ConstPerFaceAttributeHandle( void *ah,const int & n):ConstAttributeHandle(ah,n){} + }; + template class PerEdgeAttributeHandle: public AttributeHandle{ public: @@ -319,6 +356,13 @@ public: PerEdgeAttributeHandle( void *ah,const int & n):AttributeHandle(ah,n){} }; + template + class ConstPerEdgeAttributeHandle: public ConstAttributeHandle{ + public: + ConstPerEdgeAttributeHandle():ConstAttributeHandle(){} + ConstPerEdgeAttributeHandle( void *ah,const int & n):ConstAttributeHandle(ah,n){} + }; + template class PerTetraAttributeHandle : public AttributeHandle { @@ -327,6 +371,14 @@ public: PerTetraAttributeHandle(void *ah, const int &n) : AttributeHandle(ah, n) {} }; + template + class ConstPerTetraAttributeHandle : public ConstAttributeHandle + { + public: + ConstPerTetraAttributeHandle() : ConstAttributeHandle() {} + ConstPerTetraAttributeHandle(void *ah, const int &n) : ConstAttributeHandle(ah, n) {} + }; + template class PerMeshAttributeHandle{ public: @@ -340,7 +392,18 @@ public: Attribute * _handle; int n_attr; - ATTR_TYPE & operator ()(){ return *((Attribute *)_handle)->attribute;} + ATTR_TYPE & operator ()(){ return *((ATTR_TYPE*) (_handle->DataBegin()));} + }; + + template + class ConstPerMeshAttributeHandle{ + public: + ConstPerMeshAttributeHandle(){_handle=nullptr;} + ConstPerMeshAttributeHandle(const void *ah,const int & n):_handle ( (const Attribute *)ah ),n_attr(n){} + + const Attribute * _handle; + int n_attr; + const ATTR_TYPE & operator ()(){ return *((const ATTR_TYPE*)(_handle->DataBegin()));} }; // Some common Handle typedefs to simplify use @@ -538,7 +601,7 @@ template inline bool IsMarked(const MeshType & m,typename MeshT @param m the mesh containing the element @param t tetra pointer */ template -inline bool IsMarked(MeshType &m, typename MeshType::ConstTetraPointer t) { return t->cIMark() == m.imark; } +inline bool IsMarked(const MeshType &m, typename MeshType::ConstTetraPointer t) { return t->cIMark() == m.imark; } /** \brief Set the vertex incremental mark of the vertex to the one of the mesh. @param m the mesh containing the element diff --git a/vcg/complex/exception.h b/vcg/complex/exception.h index b42c4c37..36d5ef6d 100644 --- a/vcg/complex/exception.h +++ b/vcg/complex/exception.h @@ -23,6 +23,9 @@ #ifndef __VCG_EXCEPTION_H #define __VCG_EXCEPTION_H +#include +#include + namespace vcg { class MissingComponentException : public std::runtime_error diff --git a/vcg/complex/foreach.h b/vcg/complex/foreach.h index a062e41c..c2fa2cef 100644 --- a/vcg/complex/foreach.h +++ b/vcg/complex/foreach.h @@ -24,9 +24,7 @@ #ifndef VCG__FOREACH_H #define VCG__FOREACH_H -#ifndef __VCG_MESH -#error "This file should not be included alone. It is automatically included by complex.h" -#endif +#include namespace vcg { namespace tri { diff --git a/vcg/complex/used_types.h b/vcg/complex/used_types.h index 04daf9bb..570dd1ce 100755 --- a/vcg/complex/used_types.h +++ b/vcg/complex/used_types.h @@ -23,7 +23,6 @@ #ifndef VCG_USED_TYPES_H #define VCG_USED_TYPES_H -#include #include #include #include diff --git a/vcg/connectors/hedge.h b/vcg/connectors/hedge.h index e0785681..48f72a33 100644 --- a/vcg/connectors/hedge.h +++ b/vcg/connectors/hedge.h @@ -20,11 +20,18 @@ * for more details. * * * ****************************************************************************/ -#include #ifndef __VCG_HEDGE_ #define __VCG_HEDGE_ +#include +#include + +#include +#include + +#include "hedge_component.h" + namespace vcg { /*------------------------------------------------------------------*/ diff --git a/vcg/connectors/hedge_component.h b/vcg/connectors/hedge_component.h index 8c48a8d9..12c441a8 100644 --- a/vcg/connectors/hedge_component.h +++ b/vcg/connectors/hedge_component.h @@ -20,11 +20,14 @@ * for more details. * * * ****************************************************************************/ -#include #ifndef __VCG_HEDGE_COMPONENT #define __VCG_HEDGE_COMPONENT +#include +#include +#include + namespace vcg { namespace hedge { /* diff --git a/vcg/container/simple_temporary_data.h b/vcg/container/simple_temporary_data.h index 979e4357..4e91c195 100644 --- a/vcg/container/simple_temporary_data.h +++ b/vcg/container/simple_temporary_data.h @@ -24,6 +24,12 @@ #ifndef __VCGLIB_SIMPLE__ #define __VCGLIB_SIMPLE__ +#include +#include +#include +#include +#include + namespace vcg { @@ -36,45 +42,44 @@ public: virtual void Reorder(std::vector &newVertIndex) = 0; virtual size_t SizeOf() const = 0; virtual void *DataBegin() = 0; + virtual const void* DataBegin() const = 0; virtual void *At(size_t i) = 0; virtual const void *At(size_t i) const = 0; virtual void CopyValue(const size_t to, const size_t from, const SimpleTempDataBase *other) = 0; }; -template -class VectorNBW : public std::vector +template +class VectorNBW : public std::vector { }; -template <> -class VectorNBW +template +class VectorNBW { public: - VectorNBW() : data(0), datasize(0), datareserve(0) {} + VectorNBW() : booldata(nullptr), datasize(0), datareserve(0) {} ~VectorNBW() { - if (data) - delete[] data; + if (booldata) + delete[] booldata; } - bool *data; - - void reserve(const int &sz) + void reserve(size_t sz) { if (sz <= datareserve) return; bool *newdataLoc = new bool[sz]; if (datasize != 0) - memcpy(newdataLoc, data, sizeof(datasize)); - std::swap(data, newdataLoc); + memcpy(newdataLoc, booldata, sizeof(bool) * sizeof(datasize)); + std::swap(booldata, newdataLoc); if (newdataLoc != 0) delete[] newdataLoc; datareserve = sz; } - void resize(const int &sz) + void resize(size_t sz) { int oldDatasize = datasize; if (sz <= oldDatasize) @@ -82,12 +87,12 @@ public: if (sz > datareserve) reserve(sz); datasize = sz; - memset(&data[oldDatasize], 0, datasize - oldDatasize); + memset(&booldata[oldDatasize], 0, datasize - oldDatasize); } void push_back(const bool &v) { resize(datasize + 1); - data[datasize] = v; + booldata[datasize] = v; } void clear() { datasize = 0; } @@ -96,14 +101,16 @@ public: bool empty() const { return datasize == 0; } - bool *begin() const { return data; } + bool* data() {return booldata;} + const bool *data() const { return booldata; } - bool &operator[](const int &i) { return data[i]; } - const bool &operator[](const int &i) const { return data[i]; } + bool &operator[](size_t i) { return booldata[i]; } + const bool &operator[](size_t i) const { return booldata[i]; } private: - int datasize; - int datareserve; + bool *booldata; + size_t datasize; + size_t datareserve; }; template @@ -114,16 +121,16 @@ public: typedef SimpleTempData SimpTempDataType; typedef ATTR_TYPE AttrType; - STL_CONT &c; + const STL_CONT &c; VectorNBW data; int padding; - SimpleTempData(STL_CONT &_c) : c(_c), padding(0) + SimpleTempData(const STL_CONT &_c) : c(_c), padding(0) { data.reserve(c.capacity()); data.resize(c.size()); }; - SimpleTempData(STL_CONT &_c, const ATTR_TYPE &val) : c(_c) + SimpleTempData(const STL_CONT &_c, const ATTR_TYPE &val) : c(_c) { data.reserve(c.capacity()); data.resize(c.size()); @@ -142,11 +149,13 @@ public: // access to data ATTR_TYPE &operator[](const typename STL_CONT::value_type &v) { return data[&v - &*c.begin()]; } ATTR_TYPE &operator[](const typename STL_CONT::value_type *v) { return data[v - &*c.begin()]; } + ATTR_TYPE &operator[](const typename STL_CONT::const_iterator &cont) { return data[&(*cont) - &*c.begin()]; } ATTR_TYPE &operator[](const typename STL_CONT::iterator &cont) { return data[&(*cont) - &*c.begin()]; } ATTR_TYPE &operator[](size_t i) { return data[i]; } const ATTR_TYPE &operator[](const typename STL_CONT::value_type &v) const { return data[&v - &*c.begin()]; } const ATTR_TYPE &operator[](const typename STL_CONT::value_type *v) const { return data[v - &*c.begin()]; } + const ATTR_TYPE &operator[](const typename STL_CONT::const_iterator &cont) const { return data[&(*cont) - &*c.begin()]; } const ATTR_TYPE &operator[](const typename STL_CONT::iterator &cont) const { return data[&(*cont) - &*c.begin()]; } const ATTR_TYPE &operator[](size_t i) const { return data[i]; } @@ -177,7 +186,7 @@ public: void Reorder(std::vector &newVertIndex) { - for (unsigned int i = 0; i < data.size(); ++i) + for (size_t i = 0; i < data.size(); ++i) { if (newVertIndex[i] != (std::numeric_limits::max)()) data[newVertIndex[i]] = data[i]; @@ -185,7 +194,8 @@ public: } size_t SizeOf() const { return sizeof(ATTR_TYPE); } - void *DataBegin() { return data.empty() ? NULL : &(*data.begin()); } + void *DataBegin() { return data.empty() ? nullptr : data.data(); } + const void *DataBegin() const { return data.empty() ? nullptr : data.data(); } }; template @@ -193,11 +203,11 @@ class Attribute : public SimpleTempDataBase { public: typedef ATTR_TYPE AttrType; - AttrType *attribute; Attribute() { attribute = new ATTR_TYPE(); } ~Attribute() { delete attribute; } size_t SizeOf() const { return sizeof(ATTR_TYPE); } void *DataBegin() { return attribute; } + const void* DataBegin() const {return attribute;} void Resize(size_t) { assert(0); } void Reorder(std::vector &) { assert(0); } @@ -213,6 +223,8 @@ public: return (void *)0; } void CopyValue(const size_t, const size_t, const SimpleTempDataBase *) { assert(0); } +private: + AttrType *attribute; }; } // end namespace vcg diff --git a/vcg/math/base.h b/vcg/math/base.h index a2ca912a..e721194c 100644 --- a/vcg/math/base.h +++ b/vcg/math/base.h @@ -165,7 +165,7 @@ namespace math { /* Some files do not define M_PI... */ #ifndef M_PI -#define M_PI 3.14159265358979323846 +#define M_PI 3.14159265358979323846264338327950288 #endif #ifndef SQRT_TWO diff --git a/vcg/math/matrix44.h b/vcg/math/matrix44.h index cb2f8c7c..11d228d9 100644 --- a/vcg/math/matrix44.h +++ b/vcg/math/matrix44.h @@ -566,7 +566,7 @@ bool Decompose(Matrix44 &M, Point3 &ScaleV, Point3 &ShearV, Point3 & return false; if(math::Abs(M.Determinant())<1e-10) return false; // matrix should be at least invertible... - // First Step recover the traslation + // First Step recover the translation TranV=M.GetColumn3(3); // Second Step Recover Scale and Shearing interleaved diff --git a/vcg/math/shot.h b/vcg/math/shot.h index 978100b2..0eeda9cf 100644 --- a/vcg/math/shot.h +++ b/vcg/math/shot.h @@ -207,7 +207,7 @@ public: } /* multiply the current reference frame for the matrix passed - note: it is up to the caller to check the the matrix passed is a pure rototraslation + note: it is up to the caller to check the the matrix passed is a pure rototranslation */ void MultMatrix( vcg::Matrix44 m44) { @@ -218,7 +218,7 @@ public: } /* multiply the current reference frame for the similarity passed - note: it is up to the caller to check the the matrix passed is a pure rototraslation + note: it is up to the caller to check the the matrix passed is a pure rototranslation */ void MultSimilarity( const Similarity & s){ MultMatrix(s.Matrix());} diff --git a/vcg/simplex/edge/base.h b/vcg/simplex/edge/base.h index 472a635b..8f9a71b7 100644 --- a/vcg/simplex/edge/base.h +++ b/vcg/simplex/edge/base.h @@ -20,11 +20,19 @@ * for more details. * * * ****************************************************************************/ -#ifndef __VCG_MESH -#error "This file should not be included alone. It is automatically included by complex.h" -#endif + #ifndef __VCG_EDGE_PLUS #define __VCG_EDGE_PLUS + +#include +#include +#include + +#include +#include + +#include "component.h" + namespace vcg { /*------------------------------------------------------------------*/ /* diff --git a/vcg/simplex/edge/component.h b/vcg/simplex/edge/component.h index 69d32765..4e922ae3 100644 --- a/vcg/simplex/edge/component.h +++ b/vcg/simplex/edge/component.h @@ -20,12 +20,17 @@ * for more details. * * * ****************************************************************************/ -#ifndef __VCG_MESH -#error "This file should not be included alone. It is automatically included by complex.h" -#endif + #ifndef __VCG_EDGE_PLUS_COMPONENT #define __VCG_EDGE_PLUS_COMPONENT +#include +#include +#include + +#include + + namespace vcg { namespace edge { diff --git a/vcg/simplex/edge/pos.h b/vcg/simplex/edge/pos.h index 2b278f53..cc455bc9 100644 --- a/vcg/simplex/edge/pos.h +++ b/vcg/simplex/edge/pos.h @@ -24,6 +24,8 @@ #ifndef __VCG_EDGE_POS #define __VCG_EDGE_POS +#include + namespace vcg { namespace edge { diff --git a/vcg/simplex/edge/topology.h b/vcg/simplex/edge/topology.h index 6156a96d..b942c5a8 100644 --- a/vcg/simplex/edge/topology.h +++ b/vcg/simplex/edge/topology.h @@ -24,6 +24,12 @@ #ifndef _VCG_EDGE_TOPOLOGY #define _VCG_EDGE_TOPOLOGY +#include +#include + +#include "pos.h" +#include "component.h" + namespace vcg { namespace edge { /** \addtogroup edge */ diff --git a/vcg/simplex/face/base.h b/vcg/simplex/face/base.h index e96e541d..967c7dbc 100644 --- a/vcg/simplex/face/base.h +++ b/vcg/simplex/face/base.h @@ -20,12 +20,18 @@ * for more details. * * * ****************************************************************************/ -#ifndef __VCG_MESH -#error "This file should not be included alone. It is automatically included by complex.h" -#endif + #ifndef __VCG_FACE_PLUS #define __VCG_FACE_PLUS +#include +#include + +#include +#include + +#include "component.h" + namespace vcg { /*------------------------------------------------------------------*/ @@ -163,16 +169,16 @@ public: /// select the Face void SetS() {this->Flags() |=SELECTED;} /// Un-select a Face - void ClearS() {this->Flags() &= ~SELECTED;} + void ClearS() {this->Flags() &= ~SELECTED;} /// select the Face void SetV() {this->Flags() |=VISITED;} /// Un-select a Face - void ClearV() {this->Flags() &= ~VISITED;} + void ClearV() {this->Flags() &= ~VISITED;} /// This function checks if the face is selected bool IsB(int i) const {return (this->cFlags() & (BORDER0<Flags() |=(BORDER0<Flags() |=(BORDER0<Flags() &= (~(BORDER0< +#include +#include + +#include +#include namespace vcg { namespace face { @@ -36,12 +40,15 @@ namespace face { template class EmptyCore: public T { public: - inline typename T::VertexType * &V( const int ) { assert(0); static typename T::VertexType *vp=0; return vp; } - inline typename T::VertexType * cV( const int ) const { assert(0); static typename T::VertexType *vp=0; return vp; } - inline typename T::VertexType * &FVp( const int i ) { return this->V(i); } - inline typename T::VertexType * cFVp( const int i ) const { return this->cV(i); } - inline typename T::CoordType &P( const int ) { assert(0); static typename T::CoordType coord(0, 0, 0); return coord; } - inline typename T::CoordType cP( const int ) const { assert(0); static typename T::CoordType coord(0, 0, 0); return coord; } + inline typename T::VertexType * &V( const int ) { assert(0); static typename T::VertexType *vp=0; return vp; } + inline const typename T::VertexType * V( const int ) const { assert(0); static typename T::VertexType *vp=0; return vp; } + inline const typename T::VertexType * cV( const int ) const { assert(0); static typename T::VertexType *vp=0; return vp; } + inline typename T::VertexType * &FVp( const int i ) { return this->V(i); } + inline const typename T::VertexType * FVp( const int i ) const { return this->cV(i); } + inline const typename T::VertexType * cFVp( const int i ) const { return this->cV(i); } + inline typename T::CoordType &P( const int ) { assert(0); static typename T::CoordType coord(0, 0, 0); return coord; } + inline typename T::CoordType P( const int ) const { assert(0); static typename T::CoordType coord(0, 0, 0); return coord; } + inline typename T::CoordType cP( const int ) const { assert(0); static typename T::CoordType coord(0, 0, 0); return coord; } static bool HasVertexRef() { return false; } static bool HasFVAdjacency() { return false; } @@ -49,23 +56,28 @@ public: typedef typename T::VertexType::NormalType NormalType; typedef NormalType WedgeNormalType; NormalType &N() { static NormalType dummy_normal(0, 0, 0); assert(0); return dummy_normal; } - NormalType cN() const { static NormalType dummy_normal(0, 0, 0); return dummy_normal; } + const NormalType& N() const { static NormalType dummy_normal(0, 0, 0); return dummy_normal; } + const NormalType& cN() const { static NormalType dummy_normal(0, 0, 0); return dummy_normal; } WedgeNormalType &WN(int) { static NormalType dummy_normal(0, 0, 0); assert(0); return dummy_normal; } - WedgeNormalType cWN(int) const { static NormalType dummy_normal(0, 0, 0); return dummy_normal; } + const WedgeNormalType& WN(int) const { static NormalType dummy_normal(0, 0, 0); return dummy_normal; } + const WedgeNormalType& cWN(int) const { static NormalType dummy_normal(0, 0, 0); return dummy_normal; } typedef int WedgeTexCoordType; typedef vcg::TexCoord2 TexCoordType; TexCoordType &WT(const int) { static TexCoordType dummy_texture; assert(0); return dummy_texture;} - TexCoordType const &cWT(const int) const { static TexCoordType dummy_texture; return dummy_texture;} + const TexCoordType & WT(const int) const { static TexCoordType dummy_texture; return dummy_texture;} + const TexCoordType &cWT(const int) const { static TexCoordType dummy_texture; return dummy_texture;} typedef int FlagType; int &Flags() { static int dummyflags(0); assert(0); return dummyflags; } + int Flags() const { return 0; } int cFlags() const { return 0; } static bool HasFlags() { return false; } inline void InitIMark() { } inline int &IMark() { assert(0); static int tmp=-1; return tmp;} + inline int IMark() const { return 0;} inline int cIMark() const { return 0;} typedef int MarkType; @@ -74,13 +86,17 @@ public: typedef vcg::Color4b ColorType; typedef ColorType WedgeColorType; ColorType &C() { static ColorType dumcolor(vcg::Color4b::White); assert(0); return dumcolor; } - ColorType cC() const { static ColorType dumcolor(vcg::Color4b::White); assert(0); return dumcolor; } + const ColorType& C() const { static ColorType dumcolor(vcg::Color4b::White); assert(0); return dumcolor; } + const ColorType& cC() const { static ColorType dumcolor(vcg::Color4b::White); assert(0); return dumcolor; } WedgeColorType &WC(const int) { static ColorType dumcolor(vcg::Color4b::White); assert(0); return dumcolor; } - WedgeColorType cWC(const int) const { static ColorType dumcolor(vcg::Color4b::White); assert(0); return dumcolor; } + const WedgeColorType& WC(const int) const { static ColorType dumcolor(vcg::Color4b::White); assert(0); return dumcolor; } + const WedgeColorType& cWC(const int) const { static ColorType dumcolor(vcg::Color4b::White); assert(0); return dumcolor; } QualityType &Q() { static QualityType dummyQuality(0); assert(0); return dummyQuality; } - QualityType cQ() const { static QualityType dummyQuality(0); assert(0); return dummyQuality; } + const QualityType& Q() const { static QualityType dummyQuality(0); assert(0); return dummyQuality; } + const QualityType& cQ() const { static QualityType dummyQuality(0); assert(0); return dummyQuality; } Quality3Type &Q3() { static Quality3Type dummyQuality3(0,0,0); assert(0); return dummyQuality3; } - Quality3Type cQ3() const { static Quality3Type dummyQuality3(0,0,0); assert(0); return dummyQuality3; } + const Quality3Type& Q3() const { static Quality3Type dummyQuality3(0,0,0); assert(0); return dummyQuality3; } + const Quality3Type& cQ3() const { static Quality3Type dummyQuality3(0,0,0); assert(0); return dummyQuality3; } static bool HasColor() { return false; } static bool HasQuality() { return false; } @@ -106,17 +122,22 @@ public: typedef int VFAdjType; typename T::FacePointer &VFp(int) { static typename T::FacePointer fp=0; assert(0); return fp; } + typename T::FacePointer VFp(int) const { static typename T::FacePointer fp=0; assert(0); return fp; } typename T::FacePointer cVFp(int) const { static typename T::FacePointer fp=0; assert(0); return fp; } typename T::FacePointer &FFp(int) { static typename T::FacePointer fp=0; assert(0); return fp; } + typename T::FacePointer FFp(int) const { static typename T::FacePointer fp=0; assert(0); return fp; } typename T::FacePointer cFFp(int) const { static typename T::FacePointer fp=0; assert(0); return fp; } typename T::EdgePointer &FEp(int) { static typename T::EdgePointer fp=0; assert(0); return fp; } + typename T::EdgePointer FEp(int) const { static typename T::EdgePointer fp=0; assert(0); return fp; } typename T::EdgePointer cFEp(int) const { static typename T::EdgePointer fp=0; assert(0); return fp; } typename T::HEdgePointer &FHp() { static typename T::HEdgePointer fp=0; assert(0); return fp; } + typename T::HEdgePointer FHp() const { static typename T::HEdgePointer fp=0; assert(0); return fp; } typename T::HEdgePointer cFHp() const { static typename T::HEdgePointer fp=0; assert(0); return fp; } char &VFi(int) { static char z=0; assert(0); return z;} char VFi(int) const { static char z=0; assert(0); return z;} - char &FFi(int) { static char z=0; assert(0); return z;} char cVFi(int) const { static char z=0; assert(0); return z;} + char &FFi(int) { static char z=0; assert(0); return z;} + char FFi(int) const { static char z=0; assert(0); return z;} char cFFi(int) const { static char z=0; assert(0); return z;} bool IsVFInitialized(const int j) const {return static_cast(this)->cVFi(j)!=-1;} void VFClear(int j) { @@ -135,13 +156,17 @@ public: typedef typename T::ScalarType CurScalarType; CurVecType &PD1() { static typename T::CoordType dummy(0, 0, 0); assert(0); return dummy; } CurVecType &PD2() { static typename T::CoordType dummy(0, 0, 0); assert(0); return dummy; } - CurVecType cPD1() const { static typename T::CoordType dummy(0, 0, 0); assert(0); return dummy; } - CurVecType cPD2() const { static typename T::CoordType dummy(0, 0, 0); assert(0); return dummy; } + const CurVecType& PD1() const { static typename T::CoordType dummy(0, 0, 0); assert(0); return dummy; } + const CurVecType& PD2() const { static typename T::CoordType dummy(0, 0, 0); assert(0); return dummy; } + const CurVecType& cPD1() const { static typename T::CoordType dummy(0, 0, 0); assert(0); return dummy; } + const CurVecType& cPD2() const { static typename T::CoordType dummy(0, 0, 0); assert(0); return dummy; } CurScalarType &K1() { static typename T::ScalarType dummy(0); assert(0); return dummy; } CurScalarType &K2() { static typename T::ScalarType dummy(0); assert(0); return dummy; } - CurScalarType cK1() const { static typename T::ScalarType dummy(0); assert(0); return dummy; } - CurScalarType cK2() const { static typename T::ScalarType dummy(0); assert(0); return dummy; } + const CurScalarType& K1() const { static typename T::ScalarType dummy(0); assert(0); return dummy; } + const CurScalarType& K2() const { static typename T::ScalarType dummy(0); assert(0); return dummy; } + const CurScalarType& cK1() const { static typename T::ScalarType dummy(0); assert(0); return dummy; } + const CurScalarType& cK2() const { static typename T::ScalarType dummy(0); assert(0); return dummy; } static bool HasCurvatureDir() { return false; } @@ -175,10 +200,11 @@ public: inline typename T::VertexType * &V( const int j ) { assert(j>=0 && j<3); return v[j]; } /// \brief The pointer to the i-th vertex inline const typename T::VertexType * V (const int j) const { assert(j>=0 && j<3); return v[j]; } - inline typename T::VertexType * cV( const int j ) const { assert(j>=0 && j<3); return v[j]; } + inline const typename T::VertexType * cV( const int j ) const { assert(j>=0 && j<3); return v[j]; } - inline CoordType &P( const int j ) { assert(j>=0 && j<3); return v[j]->P(); } /// \brief Shortcut: the position of the i-th vertex (equivalent to \c V(i)->P() ) - inline CoordType cP( const int j ) const { assert(j>=0 && j<3); return v[j]->cP(); } + inline CoordType &P( const int j ) { assert(j>=0 && j<3); return v[j]->P(); } /// \brief Shortcut: the position of the i-th vertex (equivalent to \c V(i)->P() ) + inline const CoordType &P( const int j ) const { assert(j>=0 && j<3); return v[j]->P(); } + inline CoordType cP( const int j ) const { assert(j>=0 && j<3); return v[j]->cP(); } inline typename T::VertexType * & V0( const int j ) { return V(j);} /** \brief Return the pointer to the j-th vertex of the face. */ inline typename T::VertexType * & V1( const int j ) { return V((j+1)%3);} /** \brief Return the pointer to the ((j+1)%3)-th vertex of the face. */ @@ -186,13 +212,16 @@ public: inline const typename T::VertexType * V0( const int j ) const { return V(j);} /** \brief Return the pointer to the j-th vertex of the face. */ inline const typename T::VertexType * V1( const int j ) const { return V((j+1)%3);} /** \brief Return the pointer to the ((j+1)%3)-th vertex of the face. */ inline const typename T::VertexType * V2( const int j ) const { return V((j+2)%3);} /** \brief Return the pointer to the ((j+2)%3)-th vertex of the face. */ - inline typename T::VertexType * cV0( const int j ) const { return cV(j);} - inline typename T::VertexType * cV1( const int j ) const { return cV((j+1)%3);} - inline typename T::VertexType * cV2( const int j ) const { return cV((j+2)%3);} + inline const typename T::VertexType * cV0( const int j ) const { return cV(j);} + inline const typename T::VertexType * cV1( const int j ) const { return cV((j+1)%3);} + inline const typename T::VertexType * cV2( const int j ) const { return cV((j+2)%3);} inline CoordType & P0( const int j ) { return V(j)->P();} inline CoordType & P1( const int j ) { return V((j+1)%3)->P();} inline CoordType & P2( const int j ) { return V((j+2)%3)->P();} + inline const CoordType & P0( const int j ) const { return V(j)->P();} + inline const CoordType & P1( const int j ) const { return V((j+1)%3)->P();} + inline const CoordType & P2( const int j ) const { return V((j+2)%3)->P();} inline const CoordType & cP0( const int j ) const { return cV(j)->P();} inline const CoordType & cP1( const int j ) const { return cV((j+1)%3)->P();} inline const CoordType & cP2( const int j ) const { return cV((j+2)%3)->P();} @@ -240,7 +269,8 @@ template class WedgeNormal: public T { public: typedef typename T::VertexType::NormalType WedgeNormalType; inline WedgeNormalType &WN(int j) { return _wnorm[j]; } - inline WedgeNormalType cWN(int j) const { return _wnorm[j]; } + inline const WedgeNormalType& WN(int j) const { return _wnorm[j]; } + inline const WedgeNormalType& cWN(int j) const { return _wnorm[j]; } template void ImportData(const RightValueType & rightF){ if(rightF.IsWedgeNormalEnabled()) for (int i=0; i<3; ++i) { WN(i) = rightF.cWN(i); } T::ImportData(rightF);} inline void Alloc(const int & ns){T::Alloc(ns);} @@ -256,7 +286,8 @@ template class WedgeRealNormal: public T { public: typedef A WedgeNormalType; inline WedgeNormalType &WN(int i) { return _wn[i]; } - inline WedgeNormalType cWN(int i) const { return _wn[i]; } + inline const WedgeNormalType& WN(int i) const { return _wn[i]; } + inline const WedgeNormalType& cWN(int i) const { return _wn[i]; } template void ImportData(const RightValueType & rightF){ if(RightValueType::HasWedgeNormal()) for (int i=0; i<3; ++i) { WN(i) = rightF.cWN(i); } T::ImportData(rightF);} inline void Alloc(const int & ns){T::Alloc(ns);} @@ -293,7 +324,8 @@ public: typedef int WedgeTexCoordType; typedef A TexCoordType; TexCoordType &WT(const int i) { return _wt[i]; } - TexCoordType cWT(const int i) const { return _wt[i]; } + const TexCoordType& WT(const int i) const { return _wt[i]; } + const TexCoordType& cWT(const int i) const { return _wt[i]; } template void ImportData(const RightValueType & rightF){ if(rightF.IsWedgeTexCoordEnabled()) @@ -329,6 +361,7 @@ public: BitFlags():_flags(0) {} typedef int FlagType; int &Flags() {return _flags; } + int Flags() const {return _flags; } int cFlags() const {return _flags; } template void ImportData(const RightValueType & rightF){ @@ -351,7 +384,8 @@ public: typedef A ColorType; Color():_color(vcg::Color4b::White) {} ColorType &C() { return _color; } - ColorType cC() const { return _color; } + const ColorType& C() const { return _color; } + const ColorType& cC() const { return _color; } template void ImportData(const RightValueType & rightF){ if(rightF.IsColorEnabled()) C() = rightF.cC(); @@ -370,7 +404,8 @@ template class WedgeColor: public T { public: typedef A WedgeColorType; WedgeColorType &WC(int i) { return _color[i]; } - WedgeColorType cWC(int i) const { return _color[i]; } + const WedgeColorType& WC(int i) const { return _color[i]; } + const WedgeColorType& cWC(int i) const { return _color[i]; } template void ImportData(const RightValueType & rightF){ @@ -404,7 +439,8 @@ public: typedef A QualityType; Quality():_quality(0) {} QualityType &Q() { return _quality; } - QualityType cQ() const { return _quality; } + const QualityType& Q() const { return _quality; } + const QualityType& cQ() const { return _quality; } template void ImportData(const RightValueType & rightF){ if(rightF.IsQualityEnabled()) @@ -434,7 +470,8 @@ template class Quality3: public T { public: typedef vcg::Point3 Quality3Type; Quality3Type &Q3() { return _quality; } - Quality3Type cQ3() const { return _quality; } + const Quality3Type& Q3() const { return _quality; } + const Quality3Type& cQ3() const { return _quality; } template void ImportData(const RightValueType & rightF){ if(rightF.IsQuality3Enabled()) Q3() = rightF.cQ3(); @@ -468,6 +505,7 @@ template class Mark: public T { public: Mark():_imark(0){} inline int &IMark() { return _imark;} + inline int IMark() const { return _imark;} inline int cIMark() const { return _imark;} inline void InitIMark() { _imark = 0; } static bool HasMark() { return true; } @@ -501,11 +539,15 @@ public: CurVecType &PD1() { return _curv.max_dir;} CurVecType &PD2() { return _curv.min_dir;} + const CurVecType &PD1() const { return _curv.max_dir;} + const CurVecType &PD2() const { return _curv.min_dir;} CurVecType cPD1() const { return _curv.max_dir;} CurVecType cPD2() const { return _curv.min_dir;} CurScalarType &K1() { return _curv.k1;} CurScalarType &K2() { return _curv.k2;} + const CurScalarType &K1() const { return _curv.k1;} + const CurScalarType &K2() const { return _curv.k2;} CurScalarType cK1() const {return _curv.k1;} CurScalarType cK2() const {return _curv.k2;} template < class RightValueType> @@ -560,8 +602,10 @@ public: _vfi[2]=-1; } typename T::FacePointer &VFp(const int j) { assert(j>=0 && j<3); return _vfp[j]; } + typename T::FacePointer VFp(const int j) const { assert(j>=0 && j<3); return _vfp[j]; } typename T::FacePointer cVFp(const int j) const { assert(j>=0 && j<3); return _vfp[j]; } char &VFi(const int j) {return _vfi[j]; } + char VFi(const int j)const {return _vfi[j]; } char cVFi(const int j)const {return _vfi[j]; } template void ImportData(const RightValueType & rightF){T::ImportData(rightF);} @@ -589,6 +633,7 @@ public: typename T::FacePointer &EFp(const int j) { assert(j>=0 && j<3); return _efp[j]; } typename T::FacePointer cEFp(const int j) const { assert(j>=0 && j<3); return _efp[j]; } char &VFi(const int j) {return _efi[j]; } + char VFi(const int j) const {return _efi[j]; } template void ImportData(const RightValueType & rightF){T::ImportData(rightF);} inline void Alloc(const int & ns){T::Alloc(ns);} @@ -624,12 +669,16 @@ public: _ffp[2]=nullptr; } typename T::FacePointer &FFp(const int j) { assert(j>=0 && j<3); return _ffp[j]; } + typename T::FacePointer FFp(const int j) const { assert(j>=0 && j<3); return _ffp[j]; } typename T::FacePointer cFFp(const int j) const { assert(j>=0 && j<3); return _ffp[j]; } char &FFi(const int j) { return _ffi[j]; } + char FFi(const int j) const { return _ffi[j]; } char cFFi(const int j) const { return _ffi[j]; } typename T::FacePointer &FFp1( const int j ) { return FFp((j+1)%3);} typename T::FacePointer &FFp2( const int j ) { return FFp((j+2)%3);} + typename T::FacePointer FFp1( const int j ) const { return FFp((j+1)%3);} + typename T::FacePointer FFp2( const int j ) const { return FFp((j+2)%3);} typename T::FacePointer cFFp1( const int j ) const { return FFp((j+1)%3);} typename T::FacePointer cFFp2( const int j ) const { return FFp((j+2)%3);} @@ -657,6 +706,7 @@ public: } typename T::EdgePointer &FEp( int j) { assert(j>=0 && j<3); return _fep[j]; } + typename T::EdgePointer FEp( int j) const { assert(j>=0 && j<3); return _fep[j]; } typename T::EdgePointer cFEp( int j) const { assert(j>=0 && j<3); return _fep[j]; } typename T::EdgePointer &FEp1( int j ) { return FEp((j+1)%3);} @@ -682,6 +732,7 @@ template class FHAdj: public T { public: FHAdj(){_fh=0;} typename T::HEdgePointer &FHp( ) { return _fh; } + typename T::HEdgePointer FHp( ) const { return _fh; } typename T::HEdgePointer cFHp( ) const { return _fh; } template diff --git a/vcg/simplex/face/component_occ.h b/vcg/simplex/face/component_occ.h index 318e5852..a9eb739a 100644 --- a/vcg/simplex/face/component_occ.h +++ b/vcg/simplex/face/component_occ.h @@ -26,9 +26,6 @@ OCC = Optional Component Compact compare with OCF(Optional Component Fast) */ -#ifndef __VCG_MESH -#error "This file should not be included alone. It is automatically included by complex.h" -#endif #ifndef __VCG_FACE_PLUS_COMPONENT_OCC #define __VCG_FACE_PLUS_COMPONENT_OCC diff --git a/vcg/simplex/face/component_ocf.h b/vcg/simplex/face/component_ocf.h index 2707dc22..c0e0c0db 100644 --- a/vcg/simplex/face/component_ocf.h +++ b/vcg/simplex/face/component_ocf.h @@ -22,9 +22,12 @@ ****************************************************************************/ #ifndef __VCG_FACE_PLUS_COMPONENT_OCF #define __VCG_FACE_PLUS_COMPONENT_OCF -#ifndef __VCG_MESH -#error "This file should not be included alone. It is automatically included by complex.h" -#endif + +#include +#include + +#include +#include namespace vcg { namespace face { @@ -398,6 +401,11 @@ public: return (*this).Base().AV[(*this).Index()]._fp[j]; } + typename T::FacePointer VFp(const int j) const { + if(! (*this).Base().VFAdjacencyEnabled ) return 0; + else return (*this).Base().AV[(*this).Index()]._fp[j]; + } + typename T::FacePointer cVFp(const int j) const { if(! (*this).Base().VFAdjacencyEnabled ) return 0; else return (*this).Base().AV[(*this).Index()]._fp[j]; @@ -436,6 +444,11 @@ public: return (*this).Base().AF[(*this).Index()]._fp[j]; } + typename T::FacePointer FFp(const int j) const { + if(! (*this).Base().FFAdjacencyEnabled ) return 0; + else return (*this).Base().AF[(*this).Index()]._fp[j]; + } + typename T::FacePointer cFFp(const int j) const { if(! (*this).Base().FFAdjacencyEnabled ) return 0; else return (*this).Base().AF[(*this).Index()]._fp[j]; @@ -445,6 +458,12 @@ public: assert((*this).Base().FFAdjacencyEnabled); return (*this).Base().AF[(*this).Index()]._zp[j]; } + + char FFi(const int j) const { + assert((*this).Base().FFAdjacencyEnabled); + return (*this).Base().AF[(*this).Index()]._zp[j]; + } + char cFFi(const int j) const { assert((*this).Base().FFAdjacencyEnabled); return (*this).Base().AF[(*this).Index()]._zp[j]; @@ -452,11 +471,14 @@ public: typename T::FacePointer &FFp1( const int j ) { return FFp((j+1)%3);} typename T::FacePointer &FFp2( const int j ) { return FFp((j+2)%3);} + typename T::FacePointer FFp1( const int j ) const { return FFp((j+1)%3);} + typename T::FacePointer FFp2( const int j ) const { return FFp((j+2)%3);} typename T::FacePointer cFFp1( const int j ) const { return FFp((j+1)%3);} typename T::FacePointer cFFp2( const int j ) const { return FFp((j+2)%3);} typename T::FacePointer &Neigh( const int j ) { return FFp(j);} - typename T::FacePointer cNeigh( const int j ) const { return cFFp(j);} + typename T::FacePointer Neigh( const int j ) const { return FFp(j);} + typename T::FacePointer cNeigh( const int j ) const { return FFp(j);} unsigned int SizeNeigh(){return 3;} template @@ -479,7 +501,13 @@ public: // you cannot use Normals before enabling them with: yourmesh.face.EnableNormal() assert((*this).Base().NormalEnabled); return (*this).Base().NV[(*this).Index()]; } - NormalType cN() const { + + const NormalType& N() const { + // you cannot use Normals before enabling them with: yourmesh.face.EnableNormal() + assert((*this).Base().NormalEnabled); + return (*this).Base().NV[(*this).Index()]; } + + const NormalType& cN() const { // you cannot use Normals before enabling them with: yourmesh.face.EnableNormal() assert((*this).Base().NormalEnabled); return (*this).Base().NV[(*this).Index()]; } @@ -518,13 +546,17 @@ public: CurVecType &PD1() { assert((*this).Base().CurvatureDirEnabled); return (*this).Base().CDV[(*this).Index()].max_dir; } CurVecType &PD2() { assert((*this).Base().CurvatureDirEnabled); return (*this).Base().CDV[(*this).Index()].min_dir; } - CurVecType cPD1() const { assert((*this).Base().CurvatureDirEnabled); return (*this).Base().CDV[(*this).Index()].max_dir; } - CurVecType cPD2() const { assert((*this).Base().CurvatureDirEnabled); return (*this).Base().CDV[(*this).Index()].min_dir; } + const CurVecType& PD1() const { assert((*this).Base().CurvatureDirEnabled); return (*this).Base().CDV[(*this).Index()].max_dir; } + const CurVecType& PD2() const { assert((*this).Base().CurvatureDirEnabled); return (*this).Base().CDV[(*this).Index()].min_dir; } + const CurVecType& cPD1() const { assert((*this).Base().CurvatureDirEnabled); return (*this).Base().CDV[(*this).Index()].max_dir; } + const CurVecType& cPD2() const { assert((*this).Base().CurvatureDirEnabled); return (*this).Base().CDV[(*this).Index()].min_dir; } CurScalarType &K1() { assert((*this).Base().CurvatureDirEnabled); return (*this).Base().CDV[(*this).Index()].k1; } CurScalarType &K2() { assert((*this).Base().CurvatureDirEnabled); return (*this).Base().CDV[(*this).Index()].k2; } - CurScalarType cK1() const { assert((*this).Base().CurvatureDirEnabled); return (*this).Base().CDV[(*this).Index()].k1; } - CurScalarType cK2() const { assert((*this).Base().CurvatureDirEnabled); return (*this).Base().CDV[(*this).Index()].k2; } + const CurScalarType& K1() const { assert((*this).Base().CurvatureDirEnabled); return (*this).Base().CDV[(*this).Index()].k1; } + const CurScalarType& K2() const { assert((*this).Base().CurvatureDirEnabled); return (*this).Base().CDV[(*this).Index()].k2; } + const CurScalarType& cK1() const { assert((*this).Base().CurvatureDirEnabled); return (*this).Base().CDV[(*this).Index()].k1; } + const CurScalarType& cK2() const { assert((*this).Base().CurvatureDirEnabled); return (*this).Base().CDV[(*this).Index()].k2; } template void ImportData(const RightFaceType & rightF){ @@ -554,7 +586,11 @@ public: assert((*this).Base().QualityEnabled); return (*this).Base().QV[(*this).Index()]; } - QualityType cQ() const { + const QualityType& Q() const { + assert((*this).Base().QualityEnabled); + return (*this).Base().QV[(*this).Index()]; + } + const QualityType& cQ() const { assert((*this).Base().QualityEnabled); return (*this).Base().QV[(*this).Index()]; } @@ -580,7 +616,11 @@ public: assert((*this).Base()._ColorEnabled); return (*this).Base().CV[(*this).Index()]; } - ColorType cC() const { + const ColorType& C() const { + assert((*this).Base()._ColorEnabled); + return (*this).Base().CV[(*this).Index()]; + } + const ColorType& cC() const { assert((*this).Base()._ColorEnabled); return (*this).Base().CV[(*this).Index()]; } @@ -605,6 +645,10 @@ public: assert((*this).Base().MarkEnabled); return (*this).Base().MV[(*this).Index()]; } + inline int IMark() const { + assert((*this).Base().MarkEnabled); + return (*this).Base().MV[(*this).Index()]; + } inline int cIMark() const { assert((*this).Base().MarkEnabled); return (*this).Base().MV[(*this).Index()]; @@ -628,7 +672,8 @@ public: WedgeTexCoordOcf(){ } typedef A TexCoordType; TexCoordType &WT(const int i) { assert((*this).Base().WedgeTexEnabled); return (*this).Base().WTV[(*this).Index()].wt[i]; } - TexCoordType cWT(const int i) const { assert((*this).Base().WedgeTexEnabled); return (*this).Base().WTV[(*this).Index()].wt[i]; } + const TexCoordType& WT(const int i) const { assert((*this).Base().WedgeTexEnabled); return (*this).Base().WTV[(*this).Index()].wt[i]; } + const TexCoordType& cWT(const int i) const { assert((*this).Base().WedgeTexEnabled); return (*this).Base().WTV[(*this).Index()].wt[i]; } template void ImportData(const RightFaceType & rightF){ if(this->IsWedgeTexCoordEnabled() && rightF.IsWedgeTexCoordEnabled()) @@ -648,7 +693,8 @@ public: WedgeColorOcf(){ } typedef A WedgeColorType; WedgeColorType &WC(const int i) { assert((*this).Base().WedgeColorEnabled); return (*this).Base().WCV[(*this).Index()].wc[i]; } - const WedgeColorType cWC(const int i) const { assert((*this).Base().WedgeColorEnabled); return (*this).Base().WCV[(*this).Index()].wc[i]; } + const WedgeColorType& WC(const int i) const { assert((*this).Base().WedgeColorEnabled); return (*this).Base().WCV[(*this).Index()].wc[i]; } + const WedgeColorType& cWC(const int i) const { assert((*this).Base().WedgeColorEnabled); return (*this).Base().WCV[(*this).Index()].wc[i]; } template void ImportData(const RightFaceType & rightF){ if(this->IsWedgeColorEnabled() && rightF.IsWedgeColorEnabled()) @@ -668,7 +714,8 @@ public: WedgeNormalOcf(){ } typedef A WedgeNormalType; WedgeNormalType &WN(const int i) { assert((*this).Base().WedgeNormalEnabled); return (*this).Base().WNV[(*this).Index()].wn[i]; } - WedgeNormalType const &cWN(const int i) const { assert((*this).Base().WedgeNormalEnabled); return (*this).Base().WNV[(*this).Index()].wn[i]; } + const WedgeNormalType & WN(const int i) const { assert((*this).Base().WedgeNormalEnabled); return (*this).Base().WNV[(*this).Index()].wn[i]; } + const WedgeNormalType &cWN(const int i) const { assert((*this).Base().WedgeNormalEnabled); return (*this).Base().WNV[(*this).Index()].wn[i]; } template void ImportData(const RightFaceType & rightF){ if(this->IsWedgeNormalEnabled() && rightF.IsWedgeNormalEnabled()) diff --git a/vcg/simplex/face/component_polygon.h b/vcg/simplex/face/component_polygon.h index 8ac67f47..0a7cdd04 100644 --- a/vcg/simplex/face/component_polygon.h +++ b/vcg/simplex/face/component_polygon.h @@ -24,6 +24,10 @@ #ifndef __VCG_POLYGON_COMPONENT #define __VCG_POLYGON_COMPONENT +#include +#include +#include + namespace vcg { namespace face { @@ -60,30 +64,30 @@ public: typedef typename T::VertexType::ScalarType ScalarType; typedef typename T::VertexType VertexType; - PFVAdj(){ _vpoly = NULL; } + PFVAdj(){ _vpoly = nullptr; } /* Note: the destructor will not be called in general because there are no virtual destructors. * Instead, the job of deallocating the memory will be done by the face allocator. * This destructor is only done for those who istance a face alone (outside a mesh) */ // ~PFVAdj(){ __Dealloc(); } - inline typename T::VertexType * & V( const int j ) { assert(j>=0 && jVN()); return _vpoly[j]; } - inline typename T::VertexType * const & V( const int j ) const { assert(j>=0 && jVN()); return _vpoly[j]; } - inline typename T::VertexType * cV( const int j ) const { assert(j>=0 && jVN()); return _vpoly[j]; } + inline typename T::VertexType * & V( const int j ) { assert(j>=0 && jVN()); return _vpoly[j]; } + inline typename T::VertexType * V( const int j ) const { assert(j>=0 && jVN()); return _vpoly[j]; } + inline typename T::VertexType * cV( const int j ) const { assert(j>=0 && jVN()); return _vpoly[j]; } /** Return the pointer to the ((j+1)%3)-th vertex of the face. @param j Index of the face vertex. */ - inline VertexType * & V0( const int j ) { return V(j);} - inline VertexType * & V1( const int j ) { return V((j+1)%this->VN());} - inline VertexType * & V2( const int j ) { return V((j+2)%this->VN());} - inline const VertexType * const & V0( const int j ) const { return V(j);} - inline const VertexType * const & V1( const int j ) const { return V((j+1)%this->VN());} - inline const VertexType * const & V2( const int j ) const { return V((j+2)%this->VN());} - inline const VertexType * const & cV0( const int j ) const { return cV(j);} - inline const VertexType * const & cV1( const int j ) const { return cV((j+1)%this->VN());} - inline const VertexType * const & cV2( const int j ) const { return cV((j+2)%this->VN());} + inline VertexType * & V0( const int j ) { return V(j);} + inline VertexType * & V1( const int j ) { return V((j+1)%this->VN());} + inline VertexType * & V2( const int j ) { return V((j+2)%this->VN());} + inline const VertexType * V0( const int j ) const { return V(j);} + inline const VertexType * V1( const int j ) const { return V((j+1)%this->VN());} + inline const VertexType * V2( const int j ) const { return V((j+2)%this->VN());} + inline const VertexType * cV0( const int j ) const { return cV(j);} + inline const VertexType * cV1( const int j ) const { return cV((j+1)%this->VN());} + inline const VertexType * cV2( const int j ) const { return cV((j+2)%this->VN());} inline CoordType &P( const int j ) { assert(j>=0 && jVN()); return _vpoly[j]->P(); } inline CoordType cP( const int j ) const { assert(j>=0 && jVN()); return _vpoly[j]->cP(); } diff --git a/vcg/simplex/face/pos.h b/vcg/simplex/face/pos.h index bfc0103f..b745e95f 100644 --- a/vcg/simplex/face/pos.h +++ b/vcg/simplex/face/pos.h @@ -29,6 +29,8 @@ #ifndef __VCG_FACE_POS #define __VCG_FACE_POS +#include + namespace vcg { namespace face { @@ -66,19 +68,19 @@ public: /// Index of the edge int z; /// Pointer to the vertex - VertexType *v; + VertexType * v; /// Default constructor Pos() : f(0), z(-1), v(0) {} /// Constructor which associates the half-edge element with a face, its edge and its vertex /// \note that the input must be consistent, e.g. it should hold that \c vp==fp->V0(zp) or \c vp==fp->V1(zp) - Pos(FaceType * const fp, int const zp, VertexType * const vp) + Pos(FaceType * fp, int zp, VertexType * vp) { f=fp; z=zp; v=vp; assert((vp==fp->V0(zp))||(vp==fp->V1(zp))); } - Pos(FaceType * const fp, int const zp){f=fp; z=zp; v=f->V(zp);} - Pos(FaceType * const fp, VertexType * const vp) + Pos(FaceType * fp, int zp){f=fp; z=zp; v=f->V(zp);} + Pos(FaceType * fp, VertexType * vp) { f = fp; v = vp; @@ -217,15 +219,22 @@ public: } /// return the vertex that it should have if we make FlipV; - VertexType *VFlip() const + VertexType *VFlip() { - assert(f->cV(f->Prev(z))!=v && (f->cV(f->Next(z))==v || f->cV(z)==v)); - if(f->cV(f->Next(z))==v) return f->cV(z); - else return f->cV(f->Next(z)); + assert(f->V(f->Prev(z))!=v && (f->V(f->Next(z))==v || f->V(z)==v)); + if(f->V(f->Next(z))==v) return f->V(z); + else return f->V(f->Next(z)); } + const VertexType *VFlip() const + { + assert(f->V(f->Prev(z))!=v && (f->V(f->Next(z))==v || f->V(z)==v)); + if(f->V(f->Next(z))==v) return f->V(z); + else return f->V(f->Next(z)); + } + /// return the face that it should have if we make FlipF; - FaceType *FFlip() const + FaceType *FFlip() { // assert( f->FFp(z)->FFp(f->FFi(z))==f ); // assert(f->V(f->Prev(z))!=v); @@ -234,6 +243,15 @@ public: return nf; } + const FaceType *FFlip() const + { + // assert( f->FFp(z)->FFp(f->FFi(z))==f ); + // assert(f->V(f->Prev(z))!=v); + // assert(f->V(f->Next(z))==v || f->V((z+0)%f->VN())==v); + const FaceType *nf=f->FFp(z); + return nf; + } + // Trova il prossimo half-edge di bordo (nhe) // tale che diff --git a/vcg/simplex/face/topology.h b/vcg/simplex/face/topology.h index bd14e018..7caa961a 100644 --- a/vcg/simplex/face/topology.h +++ b/vcg/simplex/face/topology.h @@ -24,7 +24,9 @@ #ifndef _VCG_FACE_TOPOLOGY #define _VCG_FACE_TOPOLOGY -#include +#include "pos.h" + +#include namespace vcg { namespace face { diff --git a/vcg/simplex/tetrahedron/base.h b/vcg/simplex/tetrahedron/base.h index b5e9bc71..364cd857 100644 --- a/vcg/simplex/tetrahedron/base.h +++ b/vcg/simplex/tetrahedron/base.h @@ -30,16 +30,17 @@ added ****************************************************************************/ -// #ifndef __VCG_TETRA_MESH -// #error "This file should not be included alone. It is automatically included by complex.h" -// #endif + #ifndef __VCG_TETRA_PLUS #define __VCG_TETRA_PLUS -//#include -//#include -//#include -//#include +#include +#include + +#include +#include + +#include "component.h" namespace vcg { diff --git a/vcg/simplex/tetrahedron/component.h b/vcg/simplex/tetrahedron/component.h index 7cd9781d..cb1a6e87 100644 --- a/vcg/simplex/tetrahedron/component.h +++ b/vcg/simplex/tetrahedron/component.h @@ -34,6 +34,8 @@ added #define __VCG_TETRAHEDRON_PLUS_COMPONENT #include + +#include #include namespace vcg { diff --git a/vcg/simplex/tetrahedron/pos.h b/vcg/simplex/tetrahedron/pos.h index 005de26a..58cb329a 100644 --- a/vcg/simplex/tetrahedron/pos.h +++ b/vcg/simplex/tetrahedron/pos.h @@ -30,6 +30,11 @@ #ifndef __VCG_TETRA_POS #define __VCG_TETRA_POS +#include +#include + +#include "component.h" + namespace vcg { namespace tetra { @@ -87,7 +92,7 @@ public: return _vi; } - inline bool End(){return (Vt()==NULL);} + inline bool End(){return (Vt()==nullptr);} /// move on the next tetrahedron that share the vertex void operator++() @@ -97,7 +102,7 @@ public: Vt() = tw->VTp(vi); Vi() = tw->VTi(vi); - assert((Vt()==NULL)||((tw->V(vi))==(Vt()->V(Vi())))); + assert((Vt()==nullptr)||((tw->V(vi))==(Vt()->V(Vi())))); } }; diff --git a/vcg/simplex/tetrahedron/topology.h b/vcg/simplex/tetrahedron/topology.h index 5203af47..a72b8883 100644 --- a/vcg/simplex/tetrahedron/topology.h +++ b/vcg/simplex/tetrahedron/topology.h @@ -24,6 +24,8 @@ #ifndef _VCG_TETRA_TOPOLOGY #define _VCG_TETRA_TOPOLOGY +#include + namespace vcg { namespace tetrahedron { /** \addtogroup tetrahedron */ diff --git a/vcg/simplex/vertex/base.h b/vcg/simplex/vertex/base.h index 29ec6fb5..b12b0648 100644 --- a/vcg/simplex/vertex/base.h +++ b/vcg/simplex/vertex/base.h @@ -20,12 +20,15 @@ * for more details. * * * ****************************************************************************/ -#ifndef __VCG_MESH -#error "This file should not be included alone. It is automatically included by complex.h" -#endif + #ifndef __VCG_VERTEX_PLUS #define __VCG_VERTEX_PLUS +#include +#include + +#include "component.h" + namespace vcg { diff --git a/vcg/simplex/vertex/component.h b/vcg/simplex/vertex/component.h index 1914dbbd..dab25640 100644 --- a/vcg/simplex/vertex/component.h +++ b/vcg/simplex/vertex/component.h @@ -20,12 +20,16 @@ * for more details. * * * ****************************************************************************/ -#ifndef __VCG_MESH -#error "This file should not be included alone. It is automatically included by complex.h" -#endif + #ifndef __VCG_VERTEX_PLUS_COMPONENT #define __VCG_VERTEX_PLUS_COMPONENT +#include +#include + +#include +#include + namespace vcg { namespace vertex { /** \addtogroup VertexComponentGroup @@ -49,30 +53,35 @@ template class EmptyCore: public TT { public: typedef int FlagType; int &Flags() { assert(0); static int dummyflags(0); return dummyflags; } + int Flags() const { return 0; } int cFlags() const { return 0; } static bool HasFlags() { return false; } typedef vcg::Point3f CoordType; typedef CoordType::ScalarType ScalarType; CoordType &P() { assert(0); static CoordType coord(0, 0, 0); return coord; } + CoordType P() const { assert(0); static CoordType coord(0, 0, 0); assert(0); return coord; } CoordType cP() const { assert(0); static CoordType coord(0, 0, 0); assert(0); return coord; } static bool HasCoord() { return false; } inline bool IsCoordEnabled() const { return TT::VertexType::HasCoord();} typedef vcg::Point3s NormalType; NormalType &N() { assert(0); static NormalType dummy_normal(0, 0, 0); return dummy_normal; } + NormalType N() const { assert(0); static NormalType dummy_normal(0, 0, 0); return dummy_normal; } NormalType cN() const { assert(0); static NormalType dummy_normal(0, 0, 0); return dummy_normal; } static bool HasNormal() { return false; } inline bool IsNormalEnabled() const { return TT::VertexType::HasNormal();} typedef float QualityType; QualityType &Q() { assert(0); static QualityType dummyQuality(0); return dummyQuality; } + QualityType Q() const { assert(0); static QualityType dummyQuality(0); return dummyQuality; } QualityType cQ() const { assert(0); static QualityType dummyQuality(0); return dummyQuality; } static bool HasQuality() { return false; } inline bool IsQualityEnabled() const { return TT::VertexType::HasQuality();} typedef vcg::Color4b ColorType; ColorType &C() { static ColorType dumcolor(vcg::Color4b::White); assert(0); return dumcolor; } + ColorType C() const { static ColorType dumcolor(vcg::Color4b::White); assert(0); return dumcolor; } ColorType cC() const { static ColorType dumcolor(vcg::Color4b::White); assert(0); return dumcolor; } static bool HasColor() { return false; } inline bool IsColorEnabled() const { return TT::VertexType::HasColor();} @@ -80,18 +89,21 @@ public: typedef int MarkType; void InitIMark() { } int cIMark() const { assert(0); static int tmp=-1; return tmp;} + int IMark() const { assert(0); static int tmp=-1; return tmp;} int &IMark() { assert(0); static int tmp=-1; return tmp;} static bool HasMark() { return false; } inline bool IsMarkEnabled() const { return TT::VertexType::HasMark();} typedef ScalarType RadiusType; RadiusType &R() { static ScalarType v = 0.0; assert(0 && "the radius component is not available"); return v; } + RadiusType R() const { static const ScalarType v = 0.0; assert(0 && "the radius component is not available"); return v; } RadiusType cR() const { static const ScalarType v = 0.0; assert(0 && "the radius component is not available"); return v; } static bool HasRadius() { return false; } inline bool IsRadiusEnabled() const { return TT::VertexType::HasRadius();} typedef vcg::TexCoord2 TexCoordType; TexCoordType &T() { static TexCoordType dummy_texcoord; assert(0); return dummy_texcoord; } + TexCoordType T() const { static TexCoordType dummy_texcoord; assert(0); return dummy_texcoord; } TexCoordType cT() const { static TexCoordType dummy_texcoord; assert(0); return dummy_texcoord; } static bool HasTexCoord() { return false; } inline bool IsTexCoordEnabled() const { return TT::VertexType::HasTexCoord();} @@ -151,17 +163,23 @@ public: typedef Point2f CurvatureType; float &Kh() { static float dummy = 0.f; assert(0);return dummy;} float &Kg() { static float dummy = 0.f; assert(0);return dummy;} + float Kh() const { static float dummy = 0.f; assert(0); return dummy;} + float Kg() const { static float dummy = 0.f; assert(0); return dummy;} float cKh() const { static float dummy = 0.f; assert(0); return dummy;} float cKg() const { static float dummy = 0.f; assert(0); return dummy;} typedef CurvatureDirBaseType CurvatureDirType; CurVecType &PD1() {static CurVecType v(0,0,0); assert(0);return v;} CurVecType &PD2() {static CurVecType v(0,0,0); assert(0);return v;} + CurVecType PD1() const {static CurVecType v(0,0,0); assert(0);return v;} + CurVecType PD2() const {static CurVecType v(0,0,0); assert(0);return v;} CurVecType cPD1() const {static CurVecType v(0,0,0); assert(0);return v;} CurVecType cPD2() const {static CurVecType v(0,0,0); assert(0);return v;} CurScalarType &K1() { static ScalarType v = 0.0;assert(0);return v;} CurScalarType &K2() { static ScalarType v = 0.0;assert(0);return v;} + CurScalarType K1() const {static ScalarType v = 0.0;assert(0);return v;} + CurScalarType K2() const {static ScalarType v = 0.0;assert(0);return v;} CurScalarType cK1() const {static ScalarType v = 0.0;assert(0);return v;} CurScalarType cK2() const {static ScalarType v = 0.0;assert(0);return v;} diff --git a/vcg/simplex/vertex/component_occ.h b/vcg/simplex/vertex/component_occ.h index 80e0e124..e15f5e68 100644 --- a/vcg/simplex/vertex/component_occ.h +++ b/vcg/simplex/vertex/component_occ.h @@ -33,12 +33,15 @@ Working release (compilata solo su MSVC), component_occ � migrato da component ****************************************************************************/ -#ifndef __VCG_MESH -#error "This file should not be included alone. It is automatically included by complex.h" -#endif + #ifndef __VCG_VERTEX_PLUS_COMPONENT_OCC #define __VCG_VERTEX_PLUS_COMPONENT_OCC +#include + +#include +#include + namespace vcg { namespace vertex { /* diff --git a/vcg/simplex/vertex/component_ocf.h b/vcg/simplex/vertex/component_ocf.h index 35572cbc..c063308c 100644 --- a/vcg/simplex/vertex/component_ocf.h +++ b/vcg/simplex/vertex/component_ocf.h @@ -25,14 +25,16 @@ OCF = Optional Component Fast (hopefully) compare with OCC(Optional Component Compact) */ -#ifndef __VCG_MESH -#error "This file should not be included alone. It is automatically included by complex.h" -#endif + #ifndef __VCG_VERTEX_PLUS_COMPONENT_OCF #define __VCG_VERTEX_PLUS_COMPONENT_OCF -#ifndef __VCG_MESH -#error "This file should not be included alone. It is automatically included by complex.h" -#endif + +#include +#include + +#include +#include + namespace vcg { namespace vertex { diff --git a/vcg/space/box.h b/vcg/space/box.h index ad4bdf97..2cb77ab1 100644 --- a/vcg/space/box.h +++ b/vcg/space/box.h @@ -49,7 +49,7 @@ First working release. #ifndef __VCGLIB_BOX #define __VCGLIB_BOX -#include +#include #include #include @@ -107,7 +107,7 @@ public: { return _min!=p._min || _max!=p._max; } - /** Infaltes the box of a percentage.. + /** Infltes the box of a percentage.. @param s Scalar value. E.g if s=0.1 the box enlarges of 10% in every direction if S==0.5 box doubles (+50% in every direction) if S < 0 box shrinks @@ -133,12 +133,12 @@ public: _min -= delta; _max += delta; } - /// Initializing the box + /// Initializing the box void Set( const PointType & p ) { _min = _max = p; } - /// Set the box to a null value + /// Set the box to a null value void SetNull() { _min.X()= 1; _max.X()= -1; @@ -147,7 +147,7 @@ public: } /** Add two boxex: Returns minimal box that contains both operands. - @param b The box to add + @param b The box to add */ void Add( Box const & b ) { @@ -174,7 +174,7 @@ public: }; } } - /** Coputes intersection of Boxes: the minimal box containing both operands. + /** Computes intersection of Boxes: the minimal box containing both operands. @param b The other operand */ void Intersect( const Box & b ) @@ -190,7 +190,7 @@ public: if(_min.X()>_max.X() || _min.Y()>_max.Y() ) SetNull(); else if (N>2) if (_min.Z()>_max.Z()) SetNull(); } - /** Traslalate the box. + /** Translalate the box. @param p: the translation vector */ void Translate( const PointType & p ) @@ -198,7 +198,7 @@ public: _min += p; _max += p; } - /** Check wheter a point is inside box. + /** Check whether a point is inside box. @param p The point @returns True if inside, false otherwise */ @@ -214,7 +214,7 @@ public: _min.Z() <= p.Z() && p.Z() <= _max.Z() ); } - /** Check wheter a point is inside box, open at left and closed at right [min..max) + /** Check whether a point is inside box, open at left and closed at right [min..max) @param p The point 3D @returns True if inside, false otherwise */ @@ -283,7 +283,7 @@ public: (p[2]-_min[2])/(_max[2]-_min[2]) ); } - /// Computes the Volume for the box. + /// Computes the Volume for the box. inline S Volume() const { if (N==2) return (_max.X()-_min.X())*(_max.Y()-_min.Y()); @@ -356,7 +356,7 @@ public: //@} //@{ - /** @name Iporters (for boxes in different spaces and with different scalar types) + /** @name Importers (for boxes in different spaces and with different scalar types) **/ /// imports the box diff --git a/vcg/space/box2.h b/vcg/space/box2.h index 651c903c..ad0a5854 100644 --- a/vcg/space/box2.h +++ b/vcg/space/box2.h @@ -2,7 +2,7 @@ * VCGLib o o * * Visual and Computer Graphics Library o o * * _ O _ * -* Copyright(C) 2004-2016 \/)\/ * +* Copyright(C) 2004-2021 \/)\/ * * Visual Computing Lab /\/| * * ISTI - Italian National Research Council | * * \ * @@ -36,54 +36,51 @@ template class Segment2; /** \addtogroup space */ /*@{*/ /** - Templated class for a 2D bounding box. It is stored just as two Point2 + Templated class for a 2D bounding box. It is stored just as two Point2 @param BoxScalarType (Template Parameter) Specifies the scalar field. */ template class Box2 { public: - /// The scalar type + /// The scalar type typedef BoxScalarType ScalarType; - typedef Point2 PointType ; + typedef Point2 PointType; - /// min coordinate point - PointType min; - /// max coordinate point - PointType max; - /// Standard constructor + /// min coordinate point + PointType min; + /// max coordinate point + PointType max; + /// Standard constructor inline Box2() { min.X()= 1; max.X()= -1; min.Y()= 1; max.Y()= -1; } - /// Copy constructor - inline Box2( const Box2 & b ) { min=b.min; max=b.max; } - /// Min Max constructor - inline Box2( const Point2 & mi, const Point2 & ma ) { min = mi; max = ma; } + /// Min Max constructor + inline Box2(const Point2 & mi, const Point2 & ma ) { min = mi; max = ma; } - inline Box2(const Point2 & center, const BoxScalarType & radius) { - min = center-Point2(radius,radius); - max = center+Point2(radius,radius); - } + inline Box2(const Point2 & center, const BoxScalarType & radius) + { + min = center-Point2(radius,radius); + max = center+Point2(radius,radius); + } - /// Distructor - inline ~Box2() { } - /// Operator to compare two bounding box + /// Operator to compare two bounding box inline bool operator == ( Box2 const & p ) const { return min==p.min && max==p.max; } - /// Initializing the bounding box with a point + /// Initializing the bounding box with a point void Set( const PointType & p ) { min = max = p; } - Point2 P(const int & i) const + Point2 P(int i) const { - return Point2( - min[0]+ (i%2) * DimX(), + return Point2( + min[0]+ (i%2) * DimX(), min[1]+ ((i / 2)%2) * DimY()); } - // Initializing with the values + // Initializing with the values inline void Set( ScalarType minx, ScalarType miny, ScalarType maxx, ScalarType maxy ) { min[0] = minx; @@ -91,15 +88,15 @@ public: max[0] = maxx; max[1] = maxy; } - /// Set the bounding box to a null value + /// Set the bounding box to a null value void SetNull() { - min.X()= 1; max.X()= -1; min.Y()= 1; max.Y()= -1; + min.X()= 1; max.X()= -1; min.Y()= 1; max.Y()= -1; } - /** Function to add two bounding box - the bounding box expand to include the other bounding box (if necessary) - @param b The bounding box to be added - */ + /** @brief Function to add two bounding box + * the bounding box expand to include the other bounding box (if necessary) + * @param b The bounding box to be added + */ void Add( Box2 const & b ) { if(IsNull()) @@ -116,14 +113,15 @@ public: if(max.Y() < b.max.Y()) max.Y() = b.max.Y(); } } - /** Adds a point to the bouning box. - the bounding box expand to include the new point (if necessary) - @param p The point 2D - */ + /** + * @brief Adds a point to the bouning box. + * the bounding box expand to include the new point (if necessary) + * @param p The point 2D + */ void Add( const PointType & p ) { if(IsNull()) Set(p); - else + else { if(min.X() > p.X()) min.X() = p.X(); if(min.Y() > p.Y()) min.Y() = p.Y(); @@ -133,26 +131,29 @@ public: } } - /** Varies the dimension of the bounding box. - @param delta The size delta (if positive, box is enlarged) - */ - void Offset(const ScalarType s) + /** + * @brief Varies the dimension of the bounding box. + * @param delta The size delta (if positive, box is enlarged) + */ + void Offset(ScalarType s) { Offset(PointType(s, s)); } - /** Varies the dimension of the bounding box. - @param delta The size delta per dimension (if positive, box is enlarged) - */ + /** + * @brief Varies the dimension of the bounding box. + * @param delta The size delta per dimension (if positive, box is enlarged) + */ void Offset(const PointType & delta) { min -= delta; max += delta; } - /** Computes intersection between this and another bounding box - @param b The other bounding box - */ + /** + * @brief Computes intersection between this and another bounding box + * @param b The other bounding box + */ void Intersect( const Box2 & b ) { if(min.X() < b.min.X()) min.X() = b.min.X(); @@ -164,114 +165,118 @@ public: if(min.X()>max.X() || min.Y()>max.Y()) SetNull(); } - /** Traslate the bounding box by a vectore - @param p The transolation vector - */ + /** + * @brief Translate the bounding box by a vector + * @param p The translation vector + */ void Translate( const PointType & p ) { min += p; max += p; } - /** Checks whether a 2D point p is inside the box - @param p The point 2D - @return True iff p inside - */ - bool IsIn( PointType const & p ) const + /** + * @brief Checks whether a 2D point p is inside the box + * @param p The point 2D + * @return True iff p inside + */ + bool IsIn( const PointType & p ) const { return ( min.X() <= p.X() && p.X() <= max.X() && - min.Y() <= p.Y() && p.Y() <= max.Y() - ); + min.Y() <= p.Y() && p.Y() <= max.Y()); } - /** Checks whether a 2D point p is inside the box, closed at min but open at max - @param p The point in 2D - @return True iff p inside - */ - bool IsInEx( PointType const & p ) const + /** + * @brief Checks whether a 2D point p is inside the box, closed at min but open at max + * @param p The point in 2D + * @return True iff p inside + */ + bool IsInEx( const PointType & p ) const { - return ( + return ( min.X() <= p.X() && p.X() < max.X() && - min.Y() <= p.Y() && p.Y() < max.Y() - ); + min.Y() <= p.Y() && p.Y() < max.Y()); } - /** Check bbox collision. - Note: just adjiacent bbox won't collide - @param b A bounding box - @return True iff collision - */ - bool Collide( Box2 const &b ) + /** + * @brief Check bbox collision. + * Note: just adjiacent bbox won't collide + * @param b A bounding box + * @return True iff collision + */ + bool Collide( const Box2 &b ) const { Box2 bb=*this; bb.Intersect(b); return bb.IsValid(); } - /** Check if emptry. - @return True iff empty - */ + /** + * Check if empty. + * @return True iff empty + */ inline bool IsNull() const { return min.X()>max.X() || min.Y()>max.Y(); } - /** Check consistency. - @return True iff consistent - */ + /** + * Check consistency. + * @return True iff consistent + */ inline bool IsValid() const { return min.X() @@ -300,36 +305,36 @@ ScalarType DistancePoint2Box2(const Point2 &test, if ((test.X()<=bbox.min.X())&&(test.Y()<=bbox.min.Y())) return ((test-bbox.min).Norm()); else - if ((test.X()>=bbox.min.X())&& - (test.X()<=bbox.max.X())&& - (test.Y()<=bbox.min.Y())) - return (bbox.min.Y()-test.Y()); - else - if ((test.X()>=bbox.max.X())&& - (test.Y()<=bbox.min.Y())) - return ((test-vcg::Point2(bbox.max.X(),bbox.min.Y())).Norm()); - else - if ((test.Y()>=bbox.min.Y())&& - (test.Y()<=bbox.max.Y())&& - (test.X()>=bbox.max.X())) - return (test.X()-bbox.max.X()); - else - if ((test.X()>=bbox.max.X())&&(test.Y()>=bbox.max.Y())) - return ((test-bbox.max).Norm()); - else - if ((test.X()>=bbox.min.X())&& - (test.X()<=bbox.max.X())&& - (test.Y()>=bbox.max.Y())) - return (test.Y()-bbox.max.Y()); - else - if ((test.X()<=bbox.min.X())&& - (test.Y()>=bbox.max.Y())) - return ((test-vcg::Point2(bbox.min.X(),bbox.max.Y())).Norm()); - else - if ((test.X()<=bbox.min.X())&& - (test.Y()<=bbox.max.Y())&& - (test.Y()>=bbox.min.Y())) - return (bbox.min.X()-test.X()); + if ((test.X()>=bbox.min.X())&& + (test.X()<=bbox.max.X())&& + (test.Y()<=bbox.min.Y())) + return (bbox.min.Y()-test.Y()); + else + if ((test.X()>=bbox.max.X())&& + (test.Y()<=bbox.min.Y())) + return ((test-vcg::Point2(bbox.max.X(),bbox.min.Y())).Norm()); + else + if ((test.Y()>=bbox.min.Y())&& + (test.Y()<=bbox.max.Y())&& + (test.X()>=bbox.max.X())) + return (test.X()-bbox.max.X()); + else + if ((test.X()>=bbox.max.X())&&(test.Y()>=bbox.max.Y())) + return ((test-bbox.max).Norm()); + else + if ((test.X()>=bbox.min.X())&& + (test.X()<=bbox.max.X())&& + (test.Y()>=bbox.max.Y())) + return (test.Y()-bbox.max.Y()); + else + if ((test.X()<=bbox.min.X())&& + (test.Y()>=bbox.max.Y())) + return ((test-vcg::Point2(bbox.min.X(),bbox.max.Y())).Norm()); + else + if ((test.X()<=bbox.min.X())&& + (test.Y()<=bbox.max.Y())&& + (test.Y()>=bbox.min.Y())) + return (bbox.min.X()-test.X()); } else { @@ -372,13 +377,13 @@ Point2 ClosestPoint2Box2(const Point2 &test, return closest; } - /// Specificazione di box of short +/// Specificazione di box of short typedef Box2 Box2s; - /// Specificazione di box of int +/// Specificazione di box of int typedef Box2 Box2i; - /// Specificazione di box of float +/// Specificazione di box of float typedef Box2 Box2f; - /// Specificazione di box of double +/// Specificazione di box of double typedef Box2 Box2d; /*@}*/ diff --git a/vcg/space/box3.h b/vcg/space/box3.h index 4fd6de3a..862767db 100644 --- a/vcg/space/box3.h +++ b/vcg/space/box3.h @@ -46,29 +46,27 @@ public: typedef BoxScalarType ScalarType; /// min coordinate point - Point3 min; + Point3 min; /// max coordinate point Point3 max; /// The bounding box constructor inline Box3() { this->SetNull(); } - /// Copy constructor - //inline Box3( const Box3 & b ) { min=b.min; max=b.max; } /// Min Max constructor inline Box3( const Point3 & mi, const Point3 & ma ) { min = mi; max = ma; } /// Point Radius Constructor - inline Box3(const Point3 & center, const BoxScalarType & radius) { - min = center-Point3(radius,radius,radius); - max = center+Point3(radius,radius,radius); - } + inline Box3(const Point3 & center, const BoxScalarType & radius) { + min = center-Point3(radius,radius,radius); + max = center+Point3(radius,radius,radius); + } /// The bounding box distructor inline ~Box3() { } /// Operator to compare two bounding box - inline bool operator == ( Box3 const & p ) const + inline bool operator == ( const Box3 & p ) const { return min==p.min && max==p.max; } /// Operator to dispare two bounding box - inline bool operator != ( Box3 const & p ) const + inline bool operator != ( const Box3 & p ) const { return min!=p.min || max!=p.max; } @@ -103,7 +101,7 @@ public: /** Modify the current bbox to contain also the passed box. * Adding a null bounding box does nothing */ - void Add( Box3 const & b ) + void Add( const Box3 & b ) { if(b.IsNull()) return; // Adding a null bbox should do nothing if(IsNull()) *this=b; @@ -137,20 +135,20 @@ public: /** Modify the current bbox to contain also the passed sphere */ -void Add( const Point3 & p, const BoxScalarType radius ) -{ - if(IsNull()) Set(p); - else + void Add( const Point3 & p, const BoxScalarType radius ) { - min.X() = std::min(min.X(),p.X()-radius); - min.Y() = std::min(min.Y(),p.Y()-radius); - min.Z() = std::min(min.Z(),p.Z()-radius); + if(IsNull()) Set(p); + else + { + min.X() = std::min(min.X(),p.X()-radius); + min.Y() = std::min(min.Y(),p.Y()-radius); + min.Z() = std::min(min.Z(),p.Z()-radius); - max.X() = std::max(max.X(),p.X()+radius); - max.Y() = std::max(max.Y(),p.Y()+radius); - max.Z() = std::max(max.Z(),p.Z()+radius); + max.X() = std::max(max.X(),p.X()+radius); + max.Y() = std::max(max.Y(),p.Y()+radius); + max.Z() = std::max(max.Z(),p.Z()+radius); + } } -} /** Modify the current bbox to contain also the box b transformed according to the matrix m */ void Add( const Matrix44 &m, const Box3 & b ) @@ -193,7 +191,7 @@ void Add( const Point3 & p, const BoxScalarType radius ) } /** true if the point belong to the closed box */ - bool IsIn( Point3 const & p ) const + bool IsIn( const Point3 & p ) const { return ( min.X() <= p.X() && p.X() <= max.X() && @@ -204,7 +202,7 @@ void Add( const Point3 & p, const BoxScalarType radius ) /** true if the point belong to the open box (open on the max side) * e.g. if p in [min,max) */ - bool IsInEx( Point3 const & p ) const + bool IsInEx( const Point3 & p ) const { return ( min.X() <= p.X() && p.X() < max.X() && @@ -225,7 +223,7 @@ void Add( const Point3 & p, const BoxScalarType radius ) return bb.IsValid(); } */ - bool Collide(Box3 const &b) const + bool Collide( const Box3 &b) const { return b.min.X()min.X() && b.min.Y()min.Y() && @@ -259,14 +257,14 @@ void Add( const Point3 & p, const BoxScalarType radius ) return (max-min); } /// Returns global coords of a local point expressed in [0..1]^3 - Point3 LocalToGlobal(Point3 const & p) const{ + Point3 LocalToGlobal(const Point3 & p) const{ return Point3( min[0] + p[0]*(max[0]-min[0]), min[1] + p[1]*(max[1]-min[1]), min[2] + p[2]*(max[2]-min[2])); } /// Returns local coords expressed in [0..1]^3 of a point in 3D - Point3 GlobalToLocal(Point3 const & p) const{ + Point3 GlobalToLocal(const Point3 & p) const{ return Point3( (p[0]-min[0])/(max[0]-min[0]), (p[1]-min[1])/(max[1]-min[1]), @@ -313,7 +311,7 @@ void Add( const Point3 & p, const BoxScalarType radius ) } /// gives the ith box vertex in order: (x,y,z),(X,y,z),(x,Y,z),(X,Y,z),(x,y,Z),(X,y,Z),(x,Y,Z),(X,Y,Z) - Point3 P(const int & i) const { + Point3 P(int i) const { return Point3( min[0]+ (i%2) * DimX(), min[1]+ ((i / 2)%2) * DimY(), diff --git a/vcg/space/color4.h b/vcg/space/color4.h index f9d2b9d0..d97e7480 100644 --- a/vcg/space/color4.h +++ b/vcg/space/color4.h @@ -259,8 +259,8 @@ inline static Color4 ColorRamp(const float &minf,const float &maxf ,float v ) return rc; } -inline static unsigned short ToUnsignedB5G5R5(Color4 &) { return 0;} -inline static unsigned short ToUnsignedR5G5B5(Color4 &) { return 0;} +inline static unsigned short ToUnsignedB5G5R5(const Color4 &) { return 0;} +inline static unsigned short ToUnsignedR5G5B5(const Color4 &) { return 0;} inline static Color4 FromUnsignedB5G5R5(unsigned short) { @@ -420,7 +420,7 @@ typedef Color4 Color4d; template<> -inline unsigned short Color4::ToUnsignedB5G5R5(Color4 &cc) +inline unsigned short Color4::ToUnsignedB5G5R5(const Color4 &cc) { unsigned short r = cc[0]/8; unsigned short g = cc[1]/8; @@ -430,7 +430,7 @@ inline unsigned short Color4::ToUnsignedB5G5R5(Color4 -inline unsigned short Color4::ToUnsignedR5G5B5(Color4 &cc) +inline unsigned short Color4::ToUnsignedR5G5B5(const Color4 &cc) { unsigned short r = cc[0]/8; unsigned short g = cc[1]/8; diff --git a/vcg/space/deprecated_point3.h b/vcg/space/deprecated_point3.h index dd32ebfd..a5e75494 100644 --- a/vcg/space/deprecated_point3.h +++ b/vcg/space/deprecated_point3.h @@ -253,7 +253,7 @@ public: assert(i>=0 && i<3); return _v[i]; } - inline const P3ScalarType &X() const { return _v[0]; } + inline const P3ScalarType &X() const { return _v[0]; } inline const P3ScalarType &Y() const { return _v[1]; } inline const P3ScalarType &Z() const { return _v[2]; } inline P3ScalarType &X() { return _v[0]; } diff --git a/vcg/space/deprecated_point4.h b/vcg/space/deprecated_point4.h index a932f43d..39b5d135 100644 --- a/vcg/space/deprecated_point4.h +++ b/vcg/space/deprecated_point4.h @@ -97,10 +97,8 @@ public: { _v[0] = p[0]; _v[1]= p[1]; _v[2] = p[2]; _v[3]= p[3]; } - inline Point4 ( const Point4 & p ) - { - _v[0]= p._v[0]; _v[1]= p._v[1]; _v[2]= p._v[2]; _v[3]= p._v[3]; - } + inline Point4 ( const Point4 & p ) = default; + inline void SetZero() { _v[0] = _v[1] = _v[2] = _v[3]= 0; diff --git a/vcg/space/line2.h b/vcg/space/line2.h index 2ef87d13..68314006 100644 --- a/vcg/space/line2.h +++ b/vcg/space/line2.h @@ -108,7 +108,7 @@ public: { if (NORM) return ScalarType((p-_ori).dot(_dir)); else return ScalarType((p-_ori).dot(_dir)/_dir.SquaredNorm()); } - /// returns wheter this type is normalized or not + /// returns whether this type is normalized or not static bool IsNormalized() {return NORM;}; /// calculates the point of parameter t on the line. inline PointType P( const ScalarType t ) const @@ -167,7 +167,7 @@ public: Line2 (const Line2 &r) { Import(r); }; /// assignment - inline LineType & operator = ( Line2 const &r) + inline LineType & operator = ( const Line2 &r) { Import(r); return *this; }; //@} diff --git a/vcg/space/line3.h b/vcg/space/line3.h index f16a411e..fc5cad6c 100644 --- a/vcg/space/line3.h +++ b/vcg/space/line3.h @@ -124,7 +124,7 @@ public: { if (NORM) return ScalarType((p-_ori).dot(_dir)); else return ScalarType((p-_ori).dot(_dir)/_dir.SquaredNorm()); } - /// returns wheter this type is normalized or not + /// returns whether this type is normalized or not static bool IsNormalized() {return NORM;}; /// calculates the point of parameter t on the line. inline PointType P( const ScalarType t ) const diff --git a/vcg/space/rasterized_outline2_packer.h b/vcg/space/rasterized_outline2_packer.h index ace38df7..29578e15 100644 --- a/vcg/space/rasterized_outline2_packer.h +++ b/vcg/space/rasterized_outline2_packer.h @@ -305,7 +305,7 @@ public: std::vector& leftHorizon() { return mLeftHorizon; } vcg::Point2i& size() { return mSize; } - //returns the score relative to the left horizon of that poly in that particular position, taking into account the choosen algo + //returns the score relative to the left horizon of that poly in that particular position, taking into account the chosen algo int getCostX(RasterizedOutline2& poly, Point2i pos, int rast_i) { switch (params.costFunction) { case CostFuncEnum::MinWastedSpace: return emptyCellBetweenPolyAndLeftHorizon(poly, pos, rast_i); @@ -315,7 +315,7 @@ public: return 0; } - //returns the score relative to the bottom horizon of that poly in that particular position, taking into account the choosen algo + //returns the score relative to the bottom horizon of that poly in that particular position, taking into account the chosen algo int getCostY(RasterizedOutline2& poly, Point2i pos, int rast_i) { switch (params.costFunction) { case CostFuncEnum::MinWastedSpace: return emptyCellBetweenPolyAndBottomHorizon(poly, pos, rast_i); diff --git a/vcg/space/ray2.h b/vcg/space/ray2.h index fb8defe8..fe38ea93 100644 --- a/vcg/space/ray2.h +++ b/vcg/space/ray2.h @@ -109,7 +109,7 @@ public: { if (NORM) return ScalarType((p-_ori)*_dir); else return ScalarType((p-_ori)*_dir/_dir.SquaredNorm()); } - /// returns wheter this type is normalized or not + /// returns whether this type is normalized or not static bool IsNormalized() {return NORM;}; /// calculates the point of parameter t on the ray. inline PointType P( const ScalarType t ) const diff --git a/vcg/space/ray3.h b/vcg/space/ray3.h index dc76fc2b..b3b7c047 100644 --- a/vcg/space/ray3.h +++ b/vcg/space/ray3.h @@ -115,7 +115,7 @@ public: { if (NORM) return ScalarType((p-_ori).dot(_dir)); else return ScalarType((p-_ori).dot(_dir)/_dir.SquaredNorm()); } - /// returns wheter this type is normalized or not + /// returns whether this type is normalized or not static bool IsNormalized() {return NORM;}; /// calculates the point of parameter t on the ray. inline PointType P( const ScalarType t ) const diff --git a/wrap/dae/colladaformat.h b/wrap/dae/colladaformat.h index 29b6dfe7..3b6c6f8e 100644 --- a/wrap/dae/colladaformat.h +++ b/wrap/dae/colladaformat.h @@ -38,9 +38,9 @@ template struct CoordNumber{public: static unsigned int coord() { return 0; }}; -template<> struct CoordNumber { public: static unsigned int coord() { return 2; } }; -template<> struct CoordNumber { public: static unsigned int coord() { return 3; } }; -template<> struct CoordNumber { public: static unsigned int coord() { return 4; } }; +template struct CoordNumber> { public: static unsigned int coord() { return 2; } }; +template struct CoordNumber> { public: static unsigned int coord() { return 3; } }; +template struct CoordNumber> { public: static unsigned int coord() { return 4; } }; template<> struct CoordNumber { public: static unsigned int coord() { return 4; } }; diff --git a/wrap/gui/activecoordinateframe.cpp b/wrap/gui/activecoordinateframe.cpp index 9891d18e..a3f65db7 100644 --- a/wrap/gui/activecoordinateframe.cpp +++ b/wrap/gui/activecoordinateframe.cpp @@ -68,16 +68,16 @@ void ActiveCoordinateFrame::Render(QGLWidget* glw) manipulator->center=position; manipulator->GetView(); manipulator->Apply(); - + MovableCoordinateFrame::Render(glw); - + // got nothing to draw if(!drawmoves && !drawrotations){ glPopMatrix(); - return; + return; } - int current_mode=manipulator->current_button; + int current_mode=manipulator->current_button; bool rotating=(current_mode==rotx)||(current_mode==roty)||(current_mode==rotz); bool moving=(current_mode==movx)||(current_mode==movy)||(current_mode==movz); @@ -89,18 +89,18 @@ void ActiveCoordinateFrame::Render(QGLWidget* glw) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_LINE_SMOOTH); glEnable(GL_POINT_SMOOTH); - + QString message("this should never be seen"); char axis_name; float verse; - + if(current_mode==x_modifier){ glColor(xcolor); message = QString("move or rotate on X axis"); } else if(current_mode==y_modifier){ glColor(ycolor); message = QString("move or rotate on Y axis"); } else if(current_mode==z_modifier){ glColor(zcolor); message = QString("move or rotate on Z axis"); - } else + } else if(rotating && drawrotations){ // draw a rotation Point3f axis, arc_point; float angle; @@ -126,15 +126,15 @@ void ActiveCoordinateFrame::Render(QGLWidget* glw) .arg(axis_name); Quaternionf arc_rot; arc_rot.FromAxis(angle/18.0,axis); - glBegin(GL_POLYGON); + glBegin(GL_POLYGON); glVertex(position); glVertex(position+arc_point); for(int i=0;i<18;i++){ arc_point = arc_rot.Rotate(arc_point); glVertex(position+arc_point); } - glEnd(); - } else if(moving && drawmoves){ // draw a traslation + glEnd(); + } else if(moving && drawmoves){ // draw a translation Point3f ntra=manipulator->track.tra; ntra.Normalize(); if(current_mode==movx){ @@ -159,11 +159,11 @@ void ActiveCoordinateFrame::Render(QGLWidget* glw) glEnd(); glBegin(GL_POINTS); glVertex(old_pos); - glEnd(); + glEnd(); } else { // got nothing to draw glPopAttrib(); glPopMatrix(); - return; + return; } // draw message below cursor font.setBold(true); @@ -179,7 +179,7 @@ void ActiveCoordinateFrame::Reset(bool reset_position,bool reset_alignment) { MovableCoordinateFrame::Reset(reset_position, reset_alignment); Update(); - manipulator->Reset(); + manipulator->Reset(); } void ActiveCoordinateFrame::SetPosition(const Point3f newpos) @@ -215,7 +215,7 @@ void ActiveCoordinateFrame::MouseMove(int x, int y) manipulator->MouseMove(x,y); } -void ActiveCoordinateFrame::MouseUp(int x, int y, /*Button */ int button) +void ActiveCoordinateFrame::MouseUp(int x, int y, /*Button */ int button) { Move(manipulator->track); manipulator->Reset(); @@ -263,9 +263,9 @@ void ActiveCoordinateFrame::Update() x_axis=r.Rotate(Point3f(1,0,0)); y_axis=r.Rotate(Point3f(0,1,0)); z_axis=r.Rotate(Point3f(0,0,1)); - + manipulator->ClearModes(); - manipulator->modes[0] = NULL; + manipulator->modes[0] = NULL; manipulator->modes[movx] = new AxisMode(p,x_axis); manipulator->modes[movy] = new AxisMode(p,y_axis); manipulator->modes[movz] = new AxisMode(p,z_axis); diff --git a/wrap/gui/activecoordinateframe.h b/wrap/gui/activecoordinateframe.h index d5a1dc8b..715fa3c2 100644 --- a/wrap/gui/activecoordinateframe.h +++ b/wrap/gui/activecoordinateframe.h @@ -87,7 +87,7 @@ public: @param new_rotation the new rotation of the coordinate frame. */ virtual void SetRotation(const Quaternionf rotation); - + /*! @brief Align the coordinate frame to one or two directions. @@ -99,8 +99,8 @@ public: @param primary the primary direction of alignment. @param secondary the secondary direction of alignment. - @param axis_1 the name of the axis to align to the primary direction, must be a char choosen from 'X', 'Y' and 'Z' - @param axis_2 the name of the axis to align to the secondary direction, must be different from axis_1 and must be a char choosen from 'X', 'Y', 'Z' and ' '; if the char is ' ' the axis is choosen automatically. + @param axis_1 the name of the axis to align to the primary direction, must be a char chosen from 'X', 'Y' and 'Z' + @param axis_2 the name of the axis to align to the secondary direction, must be different from axis_1 and must be a char chosen from 'X', 'Y', 'Z' and ' '; if the char is ' ' the axis is chosen automatically. */ virtual void AlignWith(const Point3f primary, const Point3f secondary, const char axis_1, const char axis_2); @@ -119,7 +119,7 @@ public: @param x the x coordinate of the cursor. @param y the y coordinate of the cursor. */ - void MouseMove(int x, int y); + void MouseMove(int x, int y); /*! @brief Interface function relative to mouse up event in QT. @@ -143,20 +143,20 @@ public: @param button the keyboard modifiers state. */ void ButtonDown(int button); - + /*! @brief Set rotational snap value. - + @param value the new rotational snap value, in degrees. */ void SetSnap(float value); /// The eulerian trackball. Trackball *manipulator; - + /// The flag that enables moves feedback rendering bool drawmoves; - + /// The flag that enables rotations feedback rendering bool drawrotations; protected: @@ -165,7 +165,7 @@ protected: const int x_modifier,y_modifier,z_modifier; Point3f x_axis,y_axis,z_axis; float rot_snap_rad,mov_snap; - // functions: + // functions: virtual void Move(const Similarityf); void Update(); private: diff --git a/wrap/gui/coordinateframe.h b/wrap/gui/coordinateframe.h index fb2098aa..56aa4256 100644 --- a/wrap/gui/coordinateframe.h +++ b/wrap/gui/coordinateframe.h @@ -212,8 +212,8 @@ public: @param primary the primary direction of alignment. @param secondary the secondary direction of alignment. - @param axis_1 the name of the axis to align to the primary direction, must be a char choosen from 'X', 'Y' and 'Z' - @param axis_2 the name of the axis to align to the secondary direction, must be different from axis_1 and must be a char choosen from 'X', 'Y', 'Z' and ' '; if the char is ' ' the axis is choosen automatically. + @param axis_1 the name of the axis to align to the primary direction, must be a char chosen from 'X', 'Y' and 'Z' + @param axis_2 the name of the axis to align to the secondary direction, must be different from axis_1 and must be a char chosen from 'X', 'Y', 'Z' and ' '; if the char is ' ' the axis is chosen automatically. */ virtual void AlignWith(const Point3f primary, const Point3f secondary, const char axis_1, const char axis_2); diff --git a/wrap/gui/trackball.h b/wrap/gui/trackball.h index 9d3a87f2..9b43e175 100644 --- a/wrap/gui/trackball.h +++ b/wrap/gui/trackball.h @@ -110,9 +110,9 @@ public: /// A trackball stores a transformation called 'track' that effectively rototranslate the object. Similarityf track; /// track position in model space. - Point3f center; + Point3f center; /// size of the widget in model space. - float radius; + float radius; }; /*! @@ -160,7 +160,7 @@ mesh->Render(); Note on the typical use: - - Perspective and glulookat are choosed to frame the origin centered 1-radius trackball. + - Perspective and glulookat are chosen to frame the origin centered 1-radius trackball. - The final scale and translate are just to fit a generic mesh to the 1sized origin centered where the trackball stays box. - The trackball works also on Orthographic projections \b but that are not centered around origin (just move it back along the Z) */ @@ -199,7 +199,7 @@ public: @warning The destructor does not deallocate the memory allocated by setDefaultMapping(), because the application can change the modes map. This can lead to small memory leaks, so please explicitally delete any manipulator in the modes map if you are going to repeatly allocate and deallocate Trackball instances. */ ~Trackball(); - + private: // Trackball must not be copied. Use Append (see vcg/complex/trimesh/append.h) Trackball operator =(const Trackball & /*m*/) = delete; @@ -273,7 +273,7 @@ public: void ApplyInverse(); // DrawIcon() has been moved to trackutils.h //void DrawIcon(); - + // T(c) S R T(t) T(-c) => S R T(S^(-1) R^(-1)(c) + t - c) Matrix44f Matrix() const; Matrix44f InverseMatrix() const; @@ -315,7 +315,7 @@ public: @param x The horizontal coordinate of the mouse pointer. @param y The vertical coordinate of the mouse pointer. */ - void MouseMove(int x, int y); + void MouseMove(int x, int y); /*! @brief Interface function relative to mouse down event in QT/SDL. @@ -323,7 +323,7 @@ public: @param y The vertical coordinate of the mouse pointer. @param button The new state. */ - void MouseUp(int x, int y, /*Button */ int button); + void MouseUp(int x, int y, /*Button */ int button); /*! @brief Old interface function relative to mouse down event in QT/SDL. @@ -367,9 +367,9 @@ public: void SetSpinnable(bool on); - + // returns if it is animating or not - // + // bool IsAnimating(unsigned int msec=0); // Animate: either takes an absolute time (if default not specified, then it is automeasured) @@ -424,7 +424,7 @@ public: /* //internals // commented out no more used this stuff! enum Action { NONE = 0, VIEW_ROTATE = 1, - // Axis Constrained Rotation + // Axis Constrained Rotation TRACK_ROTATE_X = 3, TRACK_ROTATE_Y = 4, TRACK_ROTATE_Z = 5, // Drag constrained to an axis (trackball axis) DRAG_X = 6, DRAG_Y = 7, DRAG_Z = 8, @@ -469,9 +469,9 @@ public: /// The inactive manipulator. It is drawn when Trackball is inactive. TrackMode *inactive_mode; - + // The manipulator to deal with timer events and key events - TrackMode *idle_and_keys_mode; + TrackMode *idle_and_keys_mode; /*! @brief Reset modes to default mapping. @@ -493,7 +493,7 @@ public: /// Transformation before current user action. Similarityf last_track; /// track after an Undo() call. - Similarityf undo_track; + Similarityf undo_track; /// Currently not in use. Similarityf last_view; /// Mouse cursor coordinates before current action. diff --git a/wrap/io_tetramesh/io_ply.h b/wrap/io_tetramesh/io_ply.h index c2e9d472..848e4e49 100644 --- a/wrap/io_tetramesh/io_ply.h +++ b/wrap/io_tetramesh/io_ply.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. * @@ -52,9 +52,9 @@ namespace vcg { namespace tetra { namespace io { - + /** Additional data needed or useful for parsing a ply mesh. -This class can be passed to the ImporterPLY::Open() function for +This class can be passed to the ImporterPLY::Open() function for - retrieving additional per-vertex per-tetra data - specifying a callback for long ply parsing - knowing what data is contained in a ply file @@ -74,10 +74,10 @@ public: } /// Store the error codes enconutered when parsing a ply int status; - /// It returns a bit mask describing the field preesnt in the ply file - int mask; + /// It returns a bit mask describing the field present in the ply file + int mask; - /// a Simple callback that can be used for long ply parsing. + /// a Simple callback that can be used for long ply parsing. // it returns the current position, and formats a string with a description of what th efunction is doing (loading vertexes, faces...) CallBackPos *cb; @@ -87,7 +87,7 @@ public: PropDescriptor *VertexData; /// the number of per-face descriptor (usually 0) int fdn; - + /// The additional vertex descriptor that a user can specify to load additional per-face non-standard data stored in a ply PropDescriptor *TetraData; diff --git a/wrap/io_trimesh/export_3ds.h b/wrap/io_trimesh/export_3ds.h index 69e4bd15..82424005 100644 --- a/wrap/io_trimesh/export_3ds.h +++ b/wrap/io_trimesh/export_3ds.h @@ -149,7 +149,7 @@ namespace io { /* function which saves in 3DS file format */ - static int SaveBinary(SaveMeshType &m, const char * filename, const int &mask, CallBackPos *cb=0) + static int SaveBinary(const SaveMeshType &m, const char * filename, const int &mask, CallBackPos *cb=0) { if(m.vn > MAX_POLYGONS)//check max polygons return E_NOTNUMBERVERTVALID; @@ -222,28 +222,29 @@ namespace io { int nface = 0; if(HasPerWedgeTexCoord(m) && (mask & vcg::tri::io::Mask::IOM_WEDGTEXCOORD) ) { - FaceIterator fi; - for(fi=m.face.begin(); fi!=m.face.end(); ++fi) if( !(*fi).IsD() ) - { - for(unsigned int k=0;k<3;k++) + for(const auto& f : m.face) { + if( !f.IsD() ) { - int i = GetIndexVertex(m, (*fi).V(k)); - vcg::TexCoord2 t = (*fi).WT(k); - if(!m.vert[i].IsD()) + for(unsigned int k=0;k<3;k++) { - if(AddDuplexVertexCoord(ListOfDuplexVert,Key(i,t))) + int i = GetIndexVertex(m, f.cV(k)); + vcg::TexCoord2 t = f.cWT(k); + if(!m.vert[i].IsD()) { - VectorOfVertexType.push_back((*(*fi).V(k))); - ListOfDuplexVert[Key(i,t)] = int(VectorOfVertexType.size()-1); - count++; + if(AddDuplexVertexCoord(ListOfDuplexVert,Key(i,t))) + { + VectorOfVertexType.push_back((*f.V(k))); + ListOfDuplexVert[Key(i,t)] = int(VectorOfVertexType.size()-1); + count++; + } } } - } - if (cb !=NULL) - (*cb)(100.0 * (float)++nface/(float)m.face.size(), "calc duplex vertex ..."); - else - return E_ABORTED; + if (cb !=NULL) + (*cb)(100.0 * (float)++nface/(float)m.face.size(), "calc duplex vertex ..."); + else + return E_ABORTED; + } } } @@ -267,7 +268,6 @@ namespace io { lib3ds_mesh_new_texel_list(mesh,m.vn + number_vertex_to_duplicate); //set number of textures int v_index = 0; - VertexIterator vi; //saves vert if(HasPerWedgeTexCoord(m) && (mask & vcg::tri::io::Mask::IOM_WEDGTEXCOORD )) { @@ -288,134 +288,139 @@ namespace io { } else { - VertRemap.resize(m.vert.size(),-1); - for(vi=m.vert.begin(); vi!=m.vert.end(); ++vi) if( !(*vi).IsD() ) - { - Lib3dsPoint point; - point.pos[0] = (*vi).P()[0]; - point.pos[1] = (*vi).P()[1]; - point.pos[2] = (*vi).P()[2]; + VertRemap.resize(m.vert.size(),-1); + unsigned int vi = 0; + for(const auto& v : m.vert) { + if( !v.IsD() ) + { + Lib3dsPoint point; + point.pos[0] = v.P()[0]; + point.pos[1] = v.P()[1]; + point.pos[2] = v.P()[2]; - mesh->pointL[v_index] = point; - VertRemap[vi-m.vert.begin()]=v_index; - if (cb !=NULL) - (*cb)(100.0 * (float)++current/(float)max, "writing vertices "); - else - return E_ABORTED; - v_index++; + mesh->pointL[v_index] = point; + VertRemap[vi]=v_index; + if (cb !=NULL) + (*cb)(100.0 * (float)++current/(float)max, "writing vertices "); + else + return E_ABORTED; + v_index++; + } + vi++; } } lib3ds_mesh_new_face_list (mesh, m.face.size());//set number of faces int f_index = 0;//face index //int t_index = 0;//texture index - FaceIterator fi; - for(fi=m.face.begin(); fi!=m.face.end(); ++fi) if( !(*fi).IsD() ) - { - vcg::TexCoord2 t0(0,0),t1(0,0),t2(0,0); - int i0 = GetIndexVertex(m, (*fi).V(0)); - int i1 = GetIndexVertex(m, (*fi).V(1)); - int i2 = GetIndexVertex(m, (*fi).V(2)); - if(HasPerWedgeTexCoord(m) && (mask & vcg::tri::io::Mask::IOM_WEDGTEXCOORD ) ) + for(const auto& f : m.face) { + if( !f.IsD() ) { - t0 = (*fi).WT(0); - t1 = (*fi).WT(1); - t2 = (*fi).WT(2); - } - - Lib3dsFace face; - if(HasPerWedgeTexCoord(m) && (mask & vcg::tri::io::Mask::IOM_WEDGTEXCOORD )) - { - face.points[0] = GetIndexDuplexVertex(ListOfDuplexVert,Key(i0,t0)); - face.points[1] = GetIndexDuplexVertex(ListOfDuplexVert,Key(i1,t1)); - face.points[2] = GetIndexDuplexVertex(ListOfDuplexVert,Key(i2,t2)); - } - else - { - face.points[0] = VertRemap[i0]; - face.points[1] = VertRemap[i1]; - face.points[2] = VertRemap[i2]; - } - - //saves coord textures - if(HasPerWedgeTexCoord(m) && (mask & vcg::tri::io::Mask::IOM_WEDGTEXCOORD ) ) - { - mesh->texelL[face.points[0]][0] = t0.u(); - mesh->texelL[face.points[0]][1] = t0.v(); - mesh->texelL[face.points[1]][0] = t1.u(); - mesh->texelL[face.points[1]][1] = t1.v(); - mesh->texelL[face.points[2]][0] = t2.u(); - mesh->texelL[face.points[2]][1] = t2.v(); - } - - if(mask & vcg::tri::io::Mask::IOM_FACEFLAGS) - face.flags = 0; - - face.smoothing = 10; - - if((mask & vcg::tri::io::Mask::IOM_FACENORMAL) | (mask & vcg::tri::io::Mask::IOM_WEDGNORMAL) ) - { - face.normal[0] = (*fi).N()[0]; - face.normal[1] = (*fi).N()[1]; - face.normal[2] = (*fi).N()[2]; - } - - if((mask & vcg::tri::io::Mask::IOM_FACECOLOR) | (mask & vcg::tri::io::Mask::IOM_WEDGTEXCOORD)) - { - int material_index = vcg::tri::io::Materials::CreateNewMaterial(m, materials, fi); - if(material_index == (int)materials.size()) + vcg::TexCoord2 t0(0,0),t1(0,0),t2(0,0); + int i0 = GetIndexVertex(m, f.cV(0)); + int i1 = GetIndexVertex(m, f.cV(1)); + int i2 = GetIndexVertex(m, f.cV(2)); + if(HasPerWedgeTexCoord(m) && (mask & vcg::tri::io::Mask::IOM_WEDGTEXCOORD ) ) { - Lib3dsMaterial *material = lib3ds_material_new();//creates a new material - - std::string name = qnamematerial.arg(material_index-1).toStdString(); - strcpy(material->name,name.c_str());//copy new name of material + t0 = f.cWT(0); + t1 = f.cWT(1); + t2 = f.cWT(2); + } - if(mask & vcg::tri::io::Mask::IOM_FACECOLOR) - { - //ambient - material->ambient[0] = materials[materials.size()-1].Ka[0]; - material->ambient[1] = materials[materials.size()-1].Ka[1]; - material->ambient[2] = materials[materials.size()-1].Ka[2]; - material->ambient[3] = materials[materials.size()-1].Tr; - - //diffuse - material->diffuse[0] = materials[materials.size()-1].Kd[0]; - material->diffuse[1] = materials[materials.size()-1].Kd[1]; - material->diffuse[2] = materials[materials.size()-1].Kd[2]; - material->diffuse[3] = materials[materials.size()-1].Tr; - - //specular - material->specular[0] = materials[materials.size()-1].Ks[0]; - material->specular[1] = materials[materials.size()-1].Ks[1]; - material->specular[2] = materials[materials.size()-1].Ks[2]; - material->specular[3] = materials[materials.size()-1].Tr; - - //shininess - material->shininess = materials[materials.size()-1].Ns; - } - - //texture - if(HasPerWedgeTexCoord(m) && (mask & vcg::tri::io::Mask::IOM_WEDGTEXCOORD ) ) - strcpy(material->texture1_map.name,materials[materials.size()-1].map_Kd.c_str()); - - lib3ds_file_insert_material(file,material);//inserts the material inside the file - strcpy(face.material,name.c_str()); + Lib3dsFace face; + if(HasPerWedgeTexCoord(m) && (mask & vcg::tri::io::Mask::IOM_WEDGTEXCOORD )) + { + face.points[0] = GetIndexDuplexVertex(ListOfDuplexVert,Key(i0,t0)); + face.points[1] = GetIndexDuplexVertex(ListOfDuplexVert,Key(i1,t1)); + face.points[2] = GetIndexDuplexVertex(ListOfDuplexVert,Key(i2,t2)); } else - { - std::string name = qnamematerial.arg(material_index).toStdString(); - strcpy(face.material,name.c_str());//set name of material + { + face.points[0] = VertRemap[i0]; + face.points[1] = VertRemap[i1]; + face.points[2] = VertRemap[i2]; } + + //saves coord textures + if(HasPerWedgeTexCoord(m) && (mask & vcg::tri::io::Mask::IOM_WEDGTEXCOORD ) ) + { + mesh->texelL[face.points[0]][0] = t0.u(); + mesh->texelL[face.points[0]][1] = t0.v(); + mesh->texelL[face.points[1]][0] = t1.u(); + mesh->texelL[face.points[1]][1] = t1.v(); + mesh->texelL[face.points[2]][0] = t2.u(); + mesh->texelL[face.points[2]][1] = t2.v(); + } + + if(mask & vcg::tri::io::Mask::IOM_FACEFLAGS) + face.flags = 0; + + face.smoothing = 10; + + if((mask & vcg::tri::io::Mask::IOM_FACENORMAL) | (mask & vcg::tri::io::Mask::IOM_WEDGNORMAL) ) + { + face.normal[0] = f.cN()[0]; + face.normal[1] = f.cN()[1]; + face.normal[2] = f.cN()[2]; + } + + if((mask & vcg::tri::io::Mask::IOM_FACECOLOR) | (mask & vcg::tri::io::Mask::IOM_WEDGTEXCOORD)) + { + int material_index = vcg::tri::io::Materials::CreateNewMaterial(m, materials, f); + if(material_index == (int)materials.size()) + { + Lib3dsMaterial *material = lib3ds_material_new();//creates a new material + + std::string name = qnamematerial.arg(material_index-1).toStdString(); + strcpy(material->name,name.c_str());//copy new name of material + + if(mask & vcg::tri::io::Mask::IOM_FACECOLOR) + { + //ambient + material->ambient[0] = materials[materials.size()-1].Ka[0]; + material->ambient[1] = materials[materials.size()-1].Ka[1]; + material->ambient[2] = materials[materials.size()-1].Ka[2]; + material->ambient[3] = materials[materials.size()-1].Tr; + + //diffuse + material->diffuse[0] = materials[materials.size()-1].Kd[0]; + material->diffuse[1] = materials[materials.size()-1].Kd[1]; + material->diffuse[2] = materials[materials.size()-1].Kd[2]; + material->diffuse[3] = materials[materials.size()-1].Tr; + + //specular + material->specular[0] = materials[materials.size()-1].Ks[0]; + material->specular[1] = materials[materials.size()-1].Ks[1]; + material->specular[2] = materials[materials.size()-1].Ks[2]; + material->specular[3] = materials[materials.size()-1].Tr; + + //shininess + material->shininess = materials[materials.size()-1].Ns; + } + + //texture + if(HasPerWedgeTexCoord(m) && (mask & vcg::tri::io::Mask::IOM_WEDGTEXCOORD ) ) + strcpy(material->texture1_map.name,materials[materials.size()-1].map_Kd.c_str()); + + lib3ds_file_insert_material(file,material);//inserts the material inside the file + strcpy(face.material,name.c_str()); + } + else + { + std::string name = qnamematerial.arg(material_index).toStdString(); + strcpy(face.material,name.c_str());//set name of material + } + } + + mesh->faceL[f_index]=face; + + if (cb !=NULL) + (*cb)(100.0 * (float)++current/(float)max, "writing faces "); + else + return E_ABORTED; + f_index++; + } - - mesh->faceL[f_index]=face; - - if (cb !=NULL) - (*cb)(100.0 * (float)++current/(float)max, "writing faces "); - else - return E_ABORTED; - f_index++; - } lib3ds_file_insert_mesh(file, mesh);//inserts the Mesh into file @@ -435,7 +440,7 @@ namespace io { /* function which saves in 3DS format */ - static int Save(SaveMeshType &m, const char * filename, const int &mask, CallBackPos *cb=0) + static int Save(const SaveMeshType &m, const char * filename, const int &mask, CallBackPos *cb=0) { return SaveBinary(m,filename,mask,cb); } @@ -443,7 +448,7 @@ namespace io { /* returns index of the vertex */ - inline static int GetIndexVertex(SaveMeshType &m, VertexType *p) + inline static int GetIndexVertex(const SaveMeshType &m, const VertexType *p) { return p-&*(m.vert.begin()); } diff --git a/wrap/io_trimesh/export_dxf.h b/wrap/io_trimesh/export_dxf.h index 7f4e8557..08d21bb0 100644 --- a/wrap/io_trimesh/export_dxf.h +++ b/wrap/io_trimesh/export_dxf.h @@ -41,7 +41,7 @@ class ExporterDXF typedef typename SaveMeshType::CoordType CoordType; public: ///Standard call for saving a mesh - static int Save(SaveMeshType &m, const char * filename) + static int Save(const SaveMeshType &m, const char * filename) { if(m.fn==0 && m.en != 0) return SaveEdge(m,filename); @@ -55,7 +55,7 @@ public: fprintf(o,"2\n"); fprintf(o,"ENTITIES\n"); - typename SaveMeshType::FaceIterator fi; + typename SaveMeshType::ConstFaceIterator fi; for(fi=m.face.begin(); fi!=m.face.end(); ++fi) { if (!fi->IsD()) @@ -109,7 +109,7 @@ public: } - static bool SaveEdge(SaveMeshType &m, const char * filename) + static bool SaveEdge(const SaveMeshType &m, const char * filename) { FILE * o = fopen(filename,"w"); if(o==NULL) return 1; @@ -121,7 +121,7 @@ public: fprintf(o,"2\n"); fprintf(o,"ENTITIES\n"); - typename SaveMeshType::EdgeIterator ei; + typename SaveMeshType::ConstEdgeIterator ei; for(ei=m.edge.begin(); ei!=m.edge.end();++ei) { CoordType p1 = (*ei).V(0)->P(); @@ -155,7 +155,7 @@ public: return true; } - static bool writeHeader(FILE* o, SaveMeshType &mp) + static bool writeHeader(FILE* o, const SaveMeshType &mp) { // standard DXF header // most of data is meaningless, but required by a lot of importers diff --git a/wrap/io_trimesh/export_gts.h b/wrap/io_trimesh/export_gts.h index 4af571cb..f08719f0 100644 --- a/wrap/io_trimesh/export_gts.h +++ b/wrap/io_trimesh/export_gts.h @@ -34,6 +34,7 @@ #include #include #include +#include #include @@ -45,15 +46,15 @@ namespace vcg { { public: - typedef typename SaveMeshType::VertexPointer VertexPointer; + typedef typename SaveMeshType::ConstVertexPointer VertexPointer; typedef typename SaveMeshType::ScalarType ScalarType; typedef typename SaveMeshType::VertexType VertexType; typedef typename SaveMeshType::FaceType FaceType; - typedef typename SaveMeshType::FacePointer FacePointer; - typedef typename SaveMeshType::VertexIterator VertexIterator; - typedef typename SaveMeshType::FaceIterator FaceIterator; + typedef typename SaveMeshType::ConstFacePointer FacePointer; + typedef typename SaveMeshType::ConstVertexIterator VertexIterator; + typedef typename SaveMeshType::ConstFaceIterator FaceIterator; - static int Save(SaveMeshType &m, const char * filename, int /*mask*/ ) + static int Save(const SaveMeshType &m, const char * filename, int /*mask*/ ) { QFile device(filename); if (!device.open(QFile::WriteOnly)) @@ -62,17 +63,19 @@ namespace vcg { QTextStream stream(&device); // update vertex indices - std::vector FlagV; + //std::vector FlagV; + std::unordered_map vertFlags; VertexPointer vp; VertexIterator vi; int j; for(j=0,vi=m.vert.begin(); vi!=m.vert.end(); ++vi) { vp = &(*vi); - FlagV.push_back(vp->Flags()); + //FlagV.push_back(vp->Flags()); if (!vp->IsD()) { - vp->Flags() = j; + vertFlags[vp] = j; + //vp->Flags() = j; j++; } } @@ -94,8 +97,8 @@ namespace vcg { { for (int k=0; k<3; ++k) { - int a = fp->cV(k)->Flags(); - int b = fp->cV((k+1)%3)->Flags(); + int a = vertFlags[fp->cV(k)];//fp->cV(k)->Flags(); + int b = vertFlags[fp->cV((k+1)%3)];//fp->cV((k+1)%3)->Flags(); if (a>b) std::swap(a,b); Edge e(a,b); @@ -132,8 +135,8 @@ namespace vcg { { for (int k=0; k<3; ++k) { - int a = fp->cV(k)->Flags(); - int b = fp->cV((k+1)%3)->Flags(); + int a = vertFlags[fp->cV(k)];//fp->cV(k)->Flags(); + int b = vertFlags[fp->cV((k+1)%3)];//fp->cV((k+1)%3)->Flags(); if (a>b) std::swap(a,b); Edge e(a,b); @@ -154,8 +157,8 @@ namespace vcg { { for (int k=0; k<3; ++k) { - int a = fp->cV(k)->Flags(); - int b = fp->cV((k+1)%3)->Flags(); + int a = vertFlags[fp->cV(k)];//fp->cV(k)->Flags(); + int b = vertFlags[fp->cV((k+1)%3)];//fp->cV((k+1)%3)->Flags(); if (a>b) std::swap(a,b); Edge e(a,b); @@ -170,8 +173,8 @@ namespace vcg { } // Recupera i flag originali - for(j=0,vi=m.vert.begin();vi!=m.vert.end();++vi) - (*vi).Flags()=FlagV[j++]; + //for(j=0,vi=m.vert.begin();vi!=m.vert.end();++vi) + // (*vi).Flags()=FlagV[j++]; int result = 0; diff --git a/wrap/io_trimesh/export_obj.h b/wrap/io_trimesh/export_obj.h index c34d4b80..ce0626fe 100644 --- a/wrap/io_trimesh/export_obj.h +++ b/wrap/io_trimesh/export_obj.h @@ -42,7 +42,9 @@ class ExporterOBJ { public: typedef typename SaveMeshType::FaceIterator FaceIterator; + typedef typename SaveMeshType::ConstFaceIterator ConstFaceIterator; typedef typename SaveMeshType::EdgeIterator EdgeIterator; + typedef typename SaveMeshType::ConstEdgeIterator ConstEdgeIterator; typedef typename SaveMeshType::VertexIterator VertexIterator; typedef typename SaveMeshType::VertexType VertexType; typedef typename SaveMeshType::ScalarType ScalarType; @@ -212,13 +214,13 @@ public: int curMatIndex = -1; std::vector materialVec; //used if we do not have material attributes - for(FaceIterator fi=m.face.begin(); fi!=m.face.end(); ++fi) if( !(*fi).IsD() ) + for(ConstFaceIterator fi=m.face.begin(); fi!=m.face.end(); ++fi) if( !(*fi).IsD() ) { if((mask & Mask::IOM_FACECOLOR) || (mask & Mask::IOM_WEDGTEXCOORD) || (mask & Mask::IOM_VERTTEXCOORD)) { int index=-1; if(useMaterialAttribute) index = materialIndexHandle[fi]; - else index = Materials::CreateNewMaterial(m,materialVec,fi); + else index = Materials::CreateNewMaterial(m,materialVec,*fi); if(index != curMatIndex) { fprintf(fp,"\nusemtl material_%d\n", index); @@ -269,7 +271,7 @@ public: } // end for faces - for(EdgeIterator ei=m.edge.begin(); ei!=m.edge.end(); ++ei) if( !(*ei).IsD() ) + for(ConstEdgeIterator ei=m.edge.begin(); ei!=m.edge.end(); ++ei) if( !(*ei).IsD() ) { fprintf(fp,"l %i %i\n", VertexId[tri::Index(m, (*ei).V(0))] + 1, @@ -312,7 +314,7 @@ public: /* returns index of the vertex normal */ - inline static int GetIndexVertexNormal(SaveMeshType &/*m*/, std::map &mapNormToInt, const CoordType &norm ) + inline static int GetIndexVertexNormal(const SaveMeshType &/*m*/, std::map &mapNormToInt, const CoordType &norm ) { typename std::map::iterator iter= mapNormToInt.find(norm); if(iter != mapNormToInt.end()) return (*iter).second; @@ -358,7 +360,7 @@ public: adds a new index to the normal per vertex if it is the first time which is otherwise met does not execute anything */ - inline static bool AddNewNormalVertex(typename std::map &m, CoordType &n ,int value) + inline static bool AddNewNormalVertex(typename std::map &m, const CoordType &n ,int value) { int index = m[n]; if(index==0){m[n]=value;return true;} diff --git a/wrap/io_trimesh/export_ply.h b/wrap/io_trimesh/export_ply.h index c1f45e01..d2c9d3cf 100644 --- a/wrap/io_trimesh/export_ply.h +++ b/wrap/io_trimesh/export_ply.h @@ -70,30 +70,30 @@ namespace vcg { public: typedef ::vcg::ply::PropDescriptor PropDescriptor ; - typedef typename SaveMeshType::VertexPointer VertexPointer; + typedef typename SaveMeshType::ConstVertexPointer VertexPointer; typedef typename SaveMeshType::ScalarType ScalarType; typedef typename SaveMeshType::VertexType VertexType; typedef typename SaveMeshType::FaceType FaceType; - typedef typename SaveMeshType::FacePointer FacePointer; - typedef typename SaveMeshType::VertexIterator VertexIterator; - typedef typename SaveMeshType::FaceIterator FaceIterator; - typedef typename SaveMeshType::EdgeIterator EdgeIterator; + typedef typename SaveMeshType::ConstFacePointer FacePointer; + typedef typename SaveMeshType::ConstVertexIterator VertexIterator; + typedef typename SaveMeshType::ConstFaceIterator FaceIterator; + typedef typename SaveMeshType::ConstEdgeIterator EdgeIterator; typedef typename vcg::Shot::ScalarType ShotScalarType; - static int Save(SaveMeshType &m, const char * filename, bool binary=true) + static int Save(const SaveMeshType &m, const char * filename, bool binary=true) { PlyInfo pi; return Save(m,filename,binary,pi); } - static int Save(SaveMeshType &m, const char * filename, int savemask, bool binary = true, CallBackPos *cb=0 ) + static int Save(const SaveMeshType &m, const char * filename, int savemask, bool binary = true, CallBackPos *cb=0 ) { PlyInfo pi; pi.mask=savemask; return Save(m,filename,binary,pi,cb); } - static int Save(SaveMeshType &m, const char * filename, bool binary, PlyInfo &pi, CallBackPos *cb=0) // V1.0 + static int Save(const SaveMeshType &m, const char * filename, bool binary, const PlyInfo &pi, CallBackPos *cb=0) // V1.0 { FILE * fpout; const char * hbin = "binary_little_endian"; @@ -112,7 +112,7 @@ namespace vcg { fpout = fopen(filename,"wb"); if(fpout==NULL) { - pi.status=::vcg::ply::E_CANTOPEN; + //pi.status=::vcg::ply::E_CANTOPEN; return ::vcg::ply::E_CANTOPEN; } fprintf(fpout, @@ -360,12 +360,12 @@ namespace vcg { VertexIterator vi; SimpleTempData indices(m.vert); - std::vector > thfv(pi.VertDescriptorVec.size()); - std::vector > thdv(pi.VertDescriptorVec.size()); - std::vector > thiv(pi.VertDescriptorVec.size()); - std::vector > thsv(pi.VertDescriptorVec.size()); - std::vector > thcv(pi.VertDescriptorVec.size()); - std::vector > thuv(pi.VertDescriptorVec.size()); + std::vector > thfv(pi.VertDescriptorVec.size()); + std::vector > thdv(pi.VertDescriptorVec.size()); + std::vector > thiv(pi.VertDescriptorVec.size()); + std::vector > thsv(pi.VertDescriptorVec.size()); + std::vector > thcv(pi.VertDescriptorVec.size()); + std::vector > thuv(pi.VertDescriptorVec.size()); for(size_t i=0;i::template FindPerVertexAttribute(m,pi.VertAttrNameVec[i]); break; - case ply::T_DOUBLE : thdv[i] = vcg::tri::Allocator::template FindPerVertexAttribute(m,pi.VertAttrNameVec[i]); break; + case ply::T_DOUBLE : thdv[i] = vcg::tri::Allocator::template FindPerVertexAttribute(m,pi.VertAttrNameVec[i]); break; case ply::T_INT : thiv[i] = vcg::tri::Allocator::template FindPerVertexAttribute(m,pi.VertAttrNameVec[i]); break; case ply::T_SHORT : thsv[i] = vcg::tri::Allocator::template FindPerVertexAttribute(m,pi.VertAttrNameVec[i]); break; case ply::T_CHAR : thcv[i] = vcg::tri::Allocator::template FindPerVertexAttribute(m,pi.VertAttrNameVec[i]); break; @@ -384,12 +384,12 @@ namespace vcg { } } } - std::vector > thff(pi.FaceDescriptorVec.size()); - std::vector > thdf(pi.FaceDescriptorVec.size()); - std::vector > thif(pi.FaceDescriptorVec.size()); - std::vector > thsf(pi.FaceDescriptorVec.size()); - std::vector > thcf(pi.FaceDescriptorVec.size()); - std::vector > thuf(pi.FaceDescriptorVec.size()); + std::vector > thff(pi.FaceDescriptorVec.size()); + std::vector > thdf(pi.FaceDescriptorVec.size()); + std::vector > thif(pi.FaceDescriptorVec.size()); + std::vector > thsf(pi.FaceDescriptorVec.size()); + std::vector > thcf(pi.FaceDescriptorVec.size()); + std::vector > thuf(pi.FaceDescriptorVec.size()); for(size_t i=0;iFlags()),sizeof(int),1,fpout); - if( HasPerVertexColor(m) && (pi.mask & Mask::IOM_VERTCOLOR) ) - fwrite(&( vp->C() ),sizeof(char),4,fpout); + if( HasPerVertexColor(m) && (pi.mask & Mask::IOM_VERTCOLOR) ){ + auto c = vp->C(); + fwrite(&c,sizeof(char),4,fpout); + } - if( HasPerVertexQuality(m) && (pi.mask & Mask::IOM_VERTQUALITY) ) - fwrite(&( vp->Q() ),sizeof(typename VertexType::QualityType),1,fpout); + if( HasPerVertexQuality(m) && (pi.mask & Mask::IOM_VERTQUALITY) ){ + auto q = vp->Q(); + fwrite(&q, sizeof(typename VertexType::QualityType),1,fpout); + } - if( HasPerVertexRadius(m) && (pi.mask & Mask::IOM_VERTRADIUS) ) - fwrite(&( vp->R() ),sizeof(typename VertexType::RadiusType),1,fpout); + if( HasPerVertexRadius(m) && (pi.mask & Mask::IOM_VERTRADIUS) ){ + auto r = vp->R(); + fwrite(&r,sizeof(typename VertexType::RadiusType),1,fpout); + } if( HasPerVertexTexCoord(m) && (pi.mask & Mask::IOM_VERTTEXCOORD) ) { @@ -489,7 +495,7 @@ namespace vcg { fprintf(fpout,"%.*g %.*g %.*g " ,DGT,vp->P()[0],DGT,vp->P()[1],DGT,vp->P()[2]); if( HasPerVertexNormal(m) && (pi.mask & Mask::IOM_VERTNORMAL) ) - fprintf(fpout,"%.*g %.*g %.*g " ,DGT,ScalarType(vp->N()[0]),DGT,ScalarType(vp->N()[1]),DGT,ScalarType(vp->N()[2])); + fprintf(fpout,"%.*g %.*g %.*g " ,DGT,ScalarType(vp->N()[0]),DGT,ScalarType(vp->N()[1]),DGT,ScalarType(vp->N()[2])); if( HasPerVertexFlags(m) && (pi.mask & Mask::IOM_VERTFLAGS)) fprintf(fpout,"%d ",vp->Flags()); @@ -571,8 +577,10 @@ namespace vcg { fwrite(&b3char,sizeof(char),1,fpout); fwrite(vv,sizeof(int),3,fpout); - if(HasPerFaceFlags(m)&&( pi.mask & Mask::IOM_FACEFLAGS) ) - fwrite(&(fp->Flags()),sizeof(int),1,fpout); + if(HasPerFaceFlags(m)&&( pi.mask & Mask::IOM_FACEFLAGS) ){ + auto fl = fp->Flags(); + fwrite(&fl,sizeof(int),1,fpout); + } if( HasPerVertexTexCoord(m) && (!HasPerWedgeTexCoord(m)) && (pi.mask & Mask::IOM_WEDGTEXCOORD) ) // Note that you can save VT as WT if you really want it... { diff --git a/wrap/io_trimesh/export_stl.h b/wrap/io_trimesh/export_stl.h index 50859273..0ed6d9c9 100644 --- a/wrap/io_trimesh/export_stl.h +++ b/wrap/io_trimesh/export_stl.h @@ -75,14 +75,14 @@ public: typedef typename SaveMeshType::FaceType FaceType; typedef unsigned short CallBackSTLFaceAttribute(const SaveMeshType &m, const FaceType &f); -static int Save(SaveMeshType &m, const char * filename, const int &mask, CallBackPos *) +static int Save(const SaveMeshType &m, const char * filename, const int &mask, CallBackPos *) { return Save(m,filename,true,mask); } -static int Save(SaveMeshType &m, const char * filename , bool binary =true, int mask=0, const char *objectname=0, bool magicsMode=0) +static int Save(const SaveMeshType &m, const char * filename , bool binary =true, int mask=0, const char *objectname=0, bool magicsMode=0) { - typedef typename SaveMeshType::FaceIterator FaceIterator; + typedef typename SaveMeshType::ConstFaceIterator FaceIterator; FILE *fp; fp = fopen(filename,"wb"); diff --git a/wrap/io_trimesh/export_vrml.h b/wrap/io_trimesh/export_vrml.h index 4348ef86..117fbd4a 100644 --- a/wrap/io_trimesh/export_vrml.h +++ b/wrap/io_trimesh/export_vrml.h @@ -57,15 +57,15 @@ namespace vcg { class ExporterWRL { public: - typedef typename SaveMeshType::VertexPointer VertexPointer; + typedef typename SaveMeshType::ConstVertexPointer VertexPointer; typedef typename SaveMeshType::ScalarType ScalarType; typedef typename SaveMeshType::VertexType VertexType; typedef typename SaveMeshType::FaceType FaceType; - typedef typename SaveMeshType::VertexIterator VertexIterator; - typedef typename SaveMeshType::FaceIterator FaceIterator; + typedef typename SaveMeshType::ConstVertexIterator VertexIterator; + typedef typename SaveMeshType::ConstFaceIterator FaceIterator; ///Standard call for saving a mesh - static int Save(SaveMeshType &m, const char * filename, const int &mask, CallBackPos * /*cb=0*/) + static int Save(const SaveMeshType &m, const char * filename, const int &mask, CallBackPos * /*cb=0*/) { FILE *fp; fp = fopen(filename,"wb"); @@ -321,4 +321,4 @@ namespace vcg { } // end Namespace tri } // end Namespace vcg -#endif \ No newline at end of file +#endif diff --git a/wrap/io_trimesh/import.h b/wrap/io_trimesh/import.h index 96d161bb..0961f3d8 100644 --- a/wrap/io_trimesh/import.h +++ b/wrap/io_trimesh/import.h @@ -115,7 +115,12 @@ static int Open(OpenMeshType &m, const char *filename, CallBackPos *cb=0) static int Open(OpenMeshType &m, const char *filename, int &loadmask, CallBackPos *cb=0) { int err; - if(FileExtension(filename,"ply")) + if (strlen(filename) < 3) + { + err = -1; + LastType()=KT_UNKNOWN; + } + else if(FileExtension(filename,"ply")) { err = ImporterPLY::Open(m, filename, loadmask, cb); LastType()=KT_PLY; @@ -140,7 +145,7 @@ static int Open(OpenMeshType &m, const char *filename, int &loadmask, CallBackPo err = ImporterVMI::Open(m, filename, loadmask, cb); LastType()=KT_VMI; } - else { + else { err=1; LastType()=KT_UNKNOWN; } @@ -152,7 +157,7 @@ static bool ErrorCritical(int error) { switch(LastType()) { - case KT_PLY : return (error>0); break; + case KT_PLY : return ImporterPLY::ErrorCritical(error); break; case KT_STL : return (error>0); break; case KT_OFF : return (error>0); break; case KT_OBJ : return ImporterOBJ::ErrorCritical(error); break; diff --git a/wrap/io_trimesh/import_ptx.h b/wrap/io_trimesh/import_ptx.h index f049d398..79a43960 100644 --- a/wrap/io_trimesh/import_ptx.h +++ b/wrap/io_trimesh/import_ptx.h @@ -67,7 +67,7 @@ public: flipfaces = false; } - /// a bit mask describing the field preesnt in the ply file + /// a bit mask describing the field present in the ply file int mask; /// index of mesh to be imported @@ -189,8 +189,8 @@ public: if ( ( colnum <=0 ) || ( rownum <=0 ) ) return false; // initial 4 lines - if (!fscanf(fp, "%lf %lf %lf\n", &xx, &yy, &zz)) return false; // scanner registered position - if (!fscanf(fp, "%lf %lf %lf\n", &xx, &yy, &zz)) return false; // scanner registered axis 'X' + if (!fscanf(fp, "%lf %lf %lf\n", &xx, &yy, &zz)) return false; // scanner registered position + if (!fscanf(fp, "%lf %lf %lf\n", &xx, &yy, &zz)) return false; // scanner registered axis 'X' if (!fscanf(fp, "%lf %lf %lf\n", &xx, &yy, &zz)) return false; // scanner registered axis 'Y' if (!fscanf(fp, "%lf %lf %lf\n", &xx, &yy, &zz)) return false; // scanner registered axis 'Z' // now the transformation matrix @@ -434,7 +434,7 @@ public: tri::Clean::RemoveUnreferencedVertex(m); } } - Matrix44x tr; + Matrix44x tr; tr.Import(currtrasf); tri::UpdatePosition::Matrix(m,tr,true); tri::Allocator::CompactVertexVector(m); diff --git a/wrap/io_trimesh/import_stl.h b/wrap/io_trimesh/import_stl.h index 11eb57c3..8225d13a 100644 --- a/wrap/io_trimesh/import_stl.h +++ b/wrap/io_trimesh/import_stl.h @@ -24,7 +24,7 @@ #ifndef __VCGLIB_IMPORT_STL #define __VCGLIB_IMPORT_STL #include -#include +#include #include namespace vcg { @@ -140,6 +140,7 @@ static bool IsSTLColored(const char * filename, bool &coloredFlag, bool &magicsM } } + fclose(fp); return true; } @@ -150,34 +151,36 @@ static bool IsSTLColored(const char * filename, bool &coloredFlag, bool &magicsM static bool IsSTLBinary(const char * filename, bool &binaryFlag) { binaryFlag=false; - FILE *fp = fopen(filename, "r"); + FILE *fp = fopen(filename, "rb"); /* Find size of file */ fseek(fp, 0, SEEK_END); - long file_size = ftell(fp); + std::size_t file_size = ftell(fp); unsigned int facenum; /* Check for binary or ASCII file */ fseek(fp, STL_LABEL_SIZE, SEEK_SET); fread(&facenum, sizeof(unsigned int), 1, fp); - long expected_file_size=STL_LABEL_SIZE + 4 + (sizeof(short)+sizeof(STLFacet) )*facenum ; + std::size_t expected_file_size=STL_LABEL_SIZE + 4 + (sizeof(short)+sizeof(STLFacet) )*facenum ; if(file_size == expected_file_size) { binaryFlag = true; + fclose(fp); return true; } // second check, sometimes the size is a bit wrong, // lets'make a test to check that we find only ascii stuff before assuming it is ascii unsigned char tmpbuf[1000]; - int byte_to_read = std::min(int(sizeof(tmpbuf)), int(file_size - 80)); + std::size_t byte_to_read = std::min(sizeof(tmpbuf), (size_t)file_size - 80); fread(tmpbuf, byte_to_read,1,fp); fclose(fp); - for(int i = 0; i < byte_to_read; i++) + for(std::size_t i = 0; i < byte_to_read; i++) { if(tmpbuf[i] > 127) { binaryFlag=true; - if(abs(file_size-expected_file_size) > file_size/20 ) + std::size_t diff = (file_size > expected_file_size) ? file_size-expected_file_size : expected_file_size-file_size; + if(diff > file_size/20 ) return false; // break; } diff --git a/wrap/io_trimesh/io_mask.h b/wrap/io_trimesh/io_mask.h index 8fa7d251..aafff054 100644 --- a/wrap/io_trimesh/io_mask.h +++ b/wrap/io_trimesh/io_mask.h @@ -66,7 +66,7 @@ public: enum { IOM_NONE = 0x00000, - IOM_VERTCOORD = 0x00001, + IOM_VERTCOORD = 0x00001, IOM_VERTFLAGS = 0x00002, IOM_VERTCOLOR = 0x00004, IOM_VERTQUALITY = 0x00008, diff --git a/wrap/io_trimesh/io_material.h b/wrap/io_trimesh/io_material.h index 993be356..9471a5bd 100644 --- a/wrap/io_trimesh/io_material.h +++ b/wrap/io_trimesh/io_material.h @@ -85,7 +85,8 @@ struct Material template class Materials { -public: +public: + typedef typename SaveMeshType::FaceType FaceType; typedef typename SaveMeshType::FaceIterator FaceIterator; typedef typename SaveMeshType::VertexIterator VertexIterator; typedef typename SaveMeshType::VertexType VertexType; @@ -93,20 +94,20 @@ public: /* creates a new meterial */ - inline static int CreateNewMaterial(SaveMeshType &m, std::vector &materials, FaceIterator &fi) - { + inline static int CreateNewMaterial(const SaveMeshType &m, std::vector &materials, const FaceType& f) + { Material mtl; - + if(HasPerFaceColor(m)){ - mtl.Kd = Point3f((float)((*fi).C()[0])/255.0f,(float)((*fi).C()[1])/255.0f,(float)((*fi).C()[2])/255.0f);//diffuse - mtl.Tr = (float)((*fi).C()[3])/255.0f;//alpha + mtl.Kd = Point3f((float)(f.C()[0])/255.0f,(float)(f.C()[1])/255.0f,(float)(f.C()[2])/255.0f);//diffuse + mtl.Tr = (float)(f.C()[3])/255.0f;//alpha } - - if(m.textures.size() && (*fi).WT(0).n() >=0 ) - mtl.map_Kd = m.textures[(*fi).WT(0).n()]; + + if(m.textures.size() && f.WT(0).n() >=0 ) + mtl.map_Kd = m.textures[f.WT(0).n()]; else mtl.map_Kd = ""; - + int matInd = MaterialsCompare(materials,mtl); if(matInd == -1) { diff --git a/wrap/io_trimesh/io_ply.h b/wrap/io_trimesh/io_ply.h index d0cfc042..f52547e8 100644 --- a/wrap/io_trimesh/io_ply.h +++ b/wrap/io_trimesh/io_ply.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. * @@ -54,9 +54,9 @@ namespace io { - + /** Additional data needed or useful for parsing a ply mesh. -This class can be passed to the ImporterPLY::Open() function for +This class can be passed to the ImporterPLY::Open() function for - retrieving additional per-vertex per-face data - specifying a callback for long ply parsing - knowing what data is contained in a ply file @@ -65,13 +65,13 @@ class PlyInfo { public: typedef ::vcg::ply::PropDescriptor PropDescriptor ; - + void AddPerElemFloatAttribute(int elemType, const char *attrName, const char * propName=0) { static const char *elemStr[2]={"vertex","face"}; - static std::vector *elemDescVec[2]={&(this->VertDescriptorVec), &(this->FaceDescriptorVec)}; - static std::vector *elemNameVec[2]={&(this->VertAttrNameVec), &(this->FaceAttrNameVec)}; - + std::vector *elemDescVec[2]={&(this->VertDescriptorVec), &(this->FaceDescriptorVec)}; + std::vector *elemNameVec[2]={&(this->VertAttrNameVec), &(this->FaceAttrNameVec)}; + if(propName==0) propName=attrName; elemDescVec[elemType]->push_back(PropDescriptor()); elemNameVec[elemType]->push_back(attrName); @@ -80,71 +80,71 @@ public: elemDescVec[elemType]->back().stotype1 = vcg::ply::T_FLOAT; elemDescVec[elemType]->back().memtype1 = vcg::ply::T_FLOAT; } - - void AddPerVertexFloatAttribute(const char *attrName, const char *propName=0) { - AddPerElemFloatAttribute(0,attrName,propName); + + void AddPerVertexFloatAttribute(const char *attrName, const char *propName=0) { + AddPerElemFloatAttribute(0,attrName,propName); } - void AddPerFaceFloatAttribute(const char *attrName, const char *propName=0) { - AddPerElemFloatAttribute(1,attrName,propName); + void AddPerFaceFloatAttribute(const char *attrName, const char *propName=0) { + AddPerElemFloatAttribute(1,attrName,propName); } - - - /* Note that saving a per vertex point3 attribute is a mess. + + + /* Note that saving a per vertex point3 attribute is a mess. * Actually require to allocate 3 float attribute and save them. And they are never deallocated... */ template void AddPerVertexPoint3fAttribute(MeshType &m, const char *attrName, const char *propName="") { if(propName==0) propName=attrName; - + const char *attrxyz[3] = { strdup((std::string(attrName)+std::string("_x")).c_str()), strdup((std::string(attrName)+std::string("_y")).c_str()), strdup((std::string(attrName)+std::string("_z")).c_str()), }; - typename MeshType::template PerVertexAttributeHandle + typename MeshType::template PerVertexAttributeHandle ht = vcg::tri::Allocator:: template GetPerVertexAttribute (m,attrName); - + typename MeshType::template PerVertexAttributeHandle htt[3]; - + for(int i=0;i<3;++i) - { + { htt[i] = vcg::tri::Allocator:: template GetPerVertexAttribute (m,std::string(attrxyz[i])); // ForEachVertex (m, [&](typename MeshType::VertexType &v) { // htt[i][v] = ht[v][i]; -// }); +// }); for(auto vi=m.vert.begin();vi!=m.vert.end();++vi) - if(!vi->IsD()) + if(!vi->IsD()) htt[i][vi] = ht[vi][i]; - AddPerVertexFloatAttribute(attrxyz[i]); + AddPerVertexFloatAttribute(attrxyz[i]); } } - - + + PlyInfo() { status=0; mask=0; - cb=0; + cb=0; } /// Store the error codes enconutered when parsing a ply int status; - /// It returns a bit mask describing the field preesnt in the ply file - int mask; + /// It returns a bit mask describing the field present in the ply file + int mask; - /// a Simple callback that can be used for long ply parsing. + /// a Simple callback that can be used for long ply parsing. // it returns the current position, and formats a string with a description of what th efunction is doing (loading vertexes, faces...) CallBackPos *cb; /// The additional vertex descriptor that a user can specify to load additional per-vertex non-standard data stored in a ply std::vector VertDescriptorVec; - /// AttributeName is an array, externally allocated, containing the names of the attributes to be saved (loaded). + /// AttributeName is an array, externally allocated, containing the names of the attributes to be saved (loaded). /// We assume that AttributeName[], if not empty, is exactly of the same size of VertexdData[] /// If AttributeName[i] is not empty we use it to retrieve/store the info instead of the offsetted space in the current vertex - std::vector VertAttrNameVec; - + std::vector VertAttrNameVec; + /// The additional vertex descriptor that a user can specify to load additional per-face non-standard data stored in a ply std::vector FaceDescriptorVec; - std::vector FaceAttrNameVec; + std::vector FaceAttrNameVec; /// a string containing the current ply header. Useful for showing it to the user. std::string header; diff --git a/wrap/math/sparse_matrix.h b/wrap/math/sparse_matrix.h index cef43843..802c6ad9 100644 --- a/wrap/math/sparse_matrix.h +++ b/wrap/math/sparse_matrix.h @@ -15,10 +15,10 @@ public: std::vector _Ap; std::vector _Ai; std::vector _Ax; - + typedef typename std::pair IndexType; - - int _dimension; + + int _dimension; public: @@ -26,16 +26,16 @@ public: virtual void Initalize(int dimension) {_dimension=dimension;} -///create a sparse matrix given a set of entries as vector +///create a sparse matrix given a set of entries as vector ///of pair of int virtual void CreateSparse(std::vector Entries) {} -///return the value of the matrix +///return the value of the matrix virtual ScalarType &A(int row,int col) {return (_Ax[0]);} -///return true if the rapresention of sparse matriz is symmetric +///return true if the represention of sparse matriz is symmetric virtual bool IsSymmetric() {return false;} @@ -45,4 +45,4 @@ virtual void Zero() ///return the dimension of the matrix virtual int Size(){return _dimension;} -}; \ No newline at end of file +};