├── .gitattributes ├── .gitmodules ├── Code ├── Build │ ├── CMakeLists.txt │ ├── Common │ │ ├── BuildSetup.cmake │ │ ├── CMakeLists.txt │ │ └── FindTheaDependencies.cmake │ ├── Plugins │ │ ├── ARPACK │ │ │ └── CMakeLists.txt │ │ ├── CSPARSE │ │ │ └── CMakeLists.txt │ │ └── GL │ │ │ └── CMakeLists.txt │ ├── Test │ │ └── CMakeLists.txt │ └── Tools │ │ └── CMakeLists.txt ├── Documentation │ ├── Doxyfile │ ├── images │ │ ├── header.jpg │ │ └── remesh.jpg │ ├── notes.txt │ └── samples │ │ └── remesh.cpp ├── Install │ ├── install-thea-win32-express.bat │ ├── install-thea-win32.bat │ ├── install-thea-win64-express.bat │ ├── install-thea-win64.bat │ └── install-thea.sh ├── Resources │ ├── Icons │ │ ├── Custom │ │ │ ├── 48x48 │ │ │ │ ├── view-shaded-wireframe.png │ │ │ │ ├── view-shaded.png │ │ │ │ └── view-wireframe.png │ │ │ └── Source │ │ │ │ ├── view-shaded-wireframe.odg │ │ │ │ ├── view-shaded-wireframe.pdf │ │ │ │ ├── view-shaded.odg │ │ │ │ ├── view-shaded.pdf │ │ │ │ ├── view-wireframe.odg │ │ │ │ └── view-wireframe.pdf │ │ └── Tango │ │ │ ├── 16x16 │ │ │ └── zoom-fit-best.png │ │ │ ├── 22x22 │ │ │ └── zoom-fit-best.png │ │ │ ├── 32x32 │ │ │ └── zoom-fit-best.png │ │ │ ├── 48x48 │ │ │ └── zoom-fit-best.png │ │ │ └── scalable │ │ │ ├── document-open.svg │ │ │ ├── document-save-as.svg │ │ │ ├── go-next.svg │ │ │ ├── go-previous.svg │ │ │ └── zoom-fit-best.svg │ ├── Images │ │ └── background.jpg │ └── Materials │ │ ├── FlatTextureFrag.glsl │ │ ├── FlatTextureVert.glsl │ │ ├── MatcapFrag.glsl │ │ ├── PhongFrag.glsl │ │ └── PhongVert.glsl └── Source │ ├── AffineTransform2.hpp │ ├── AffineTransform3.hpp │ ├── AffineTransformN.hpp │ ├── Algorithms │ ├── ApproximateConvexDecomposition.cpp │ ├── ApproximateConvexDecomposition.hpp │ ├── BagOfWords.hpp │ ├── BestFitBox3.cpp │ ├── BestFitBox3.hpp │ ├── BestFitEllipsoid3.cpp │ ├── BestFitEllipsoid3.hpp │ ├── BestFitSphere3.hpp │ ├── BestFitSphereN.hpp │ ├── BiasedNormalizedCuts.hpp │ ├── BoundedTraitsN.hpp │ ├── BoundedTraitsN_Transform.hpp │ ├── BvhN.hpp │ ├── CentroidN.hpp │ ├── Clustering.hpp │ ├── ConnectedComponents.hpp │ ├── ConvexHull3.cpp │ ├── ConvexHull3.hpp │ ├── DiscreteExponentialMap.cpp │ ├── DiscreteExponentialMap.hpp │ ├── Filter.hpp │ ├── FurthestPointSampling.cpp │ ├── FurthestPointSampling.hpp │ ├── GeodesicExtrema.hpp │ ├── GeodesicSphere3.cpp │ ├── GeodesicSphere3.hpp │ ├── Histogram.hpp │ ├── HoughForest.cpp │ ├── HoughForest.hpp │ ├── IAnalyticD1ScalarFunction.hpp │ ├── IAnalyticD2ScalarFunction.hpp │ ├── IEigenSolver.cpp │ ├── IEigenSolver.hpp │ ├── ILinearSolver.cpp │ ├── ILinearSolver.hpp │ ├── INumericalOptimizer.cpp │ ├── INumericalOptimizer.hpp │ ├── IScalarConstraint.hpp │ ├── IScalarFunction.hpp │ ├── Icp3.hpp │ ├── ImageFeatures │ │ ├── ShapeContext.cpp │ │ └── ShapeContext.hpp │ ├── ImlsSurface.cpp │ ├── ImlsSurface.hpp │ ├── ImplicitSurfaceMesher.hpp │ ├── IntersectionTester.hpp │ ├── IntersectionTester_Transform.hpp │ ├── Iterators.hpp │ ├── JointBoost.cpp │ ├── JointBoost.hpp │ ├── KMeans.cpp │ ├── KMeans.hpp │ ├── LaplaceBeltrami.hpp │ ├── LinearLeastSquares2.hpp │ ├── LinearLeastSquares3.hpp │ ├── LogisticRegression.cpp │ ├── LogisticRegression.hpp │ ├── Manifold.cpp │ ├── Manifold.hpp │ ├── MeshBvh.hpp │ ├── MeshSampler.hpp │ ├── MeshTriangles.hpp │ ├── MetricL2.hpp │ ├── MetricL2_Transform.hpp │ ├── Metrics.hpp │ ├── NormalTraitsN.hpp │ ├── PcaN.hpp │ ├── PointCollectorN.hpp │ ├── PointPairs.hpp │ ├── PointSet3.cpp │ ├── PointSet3.hpp │ ├── PointTraitsN.hpp │ ├── ProximityQueryStructureN.hpp │ ├── PyramidMatch.cpp │ ├── PyramidMatch.hpp │ ├── RangeQueryStructure.hpp │ ├── RayIntersectionTester.hpp │ ├── RayQueryStructureN.hpp │ ├── SamplePoint3.hpp │ ├── ShortestPaths.hpp │ ├── SparsePcaN.hpp │ ├── StdLinearSolver.cpp │ ├── StdLinearSolver.hpp │ ├── SurfaceFeatures │ │ ├── Global │ │ │ ├── DistanceHistogram.cpp │ │ │ └── DistanceHistogram.hpp │ │ └── Local │ │ │ ├── AverageDistance.cpp │ │ │ ├── AverageDistance.hpp │ │ │ ├── Curvature.cpp │ │ │ ├── Curvature.hpp │ │ │ ├── LocalDistanceHistogram.cpp │ │ │ ├── LocalDistanceHistogram.hpp │ │ │ ├── LocalPca.cpp │ │ │ ├── LocalPca.hpp │ │ │ ├── RandomWalks.cpp │ │ │ ├── RandomWalks.hpp │ │ │ ├── ShapeDiameter.hpp │ │ │ ├── SpinImage.cpp │ │ │ ├── SpinImage.hpp │ │ │ └── Visibility.hpp │ ├── SurfaceParametrization.hpp │ ├── Symmetry3.hpp │ ├── TransformedObject.hpp │ ├── Transformer.hpp │ ├── Zernike2.cpp │ └── Zernike2.hpp │ ├── AlignedAllocator.hpp │ ├── Application.cpp │ ├── Application.hpp │ ├── Array.hpp │ ├── AttributedObject.hpp │ ├── AxisAlignedBox3.hpp │ ├── AxisAlignedBoxN.hpp │ ├── Ball3.hpp │ ├── BallN.hpp │ ├── BasicStringAlg.hpp │ ├── BezierN.hpp │ ├── BinaryInputStream.cpp │ ├── BinaryInputStream.hpp │ ├── BinaryOutputStream.cpp │ ├── BinaryOutputStream.hpp │ ├── BoundedArrayN.hpp │ ├── BoundedSortedArray.hpp │ ├── BoundedSortedArrayN.hpp │ ├── Box3.hpp │ ├── BoxN.hpp │ ├── Codec.cpp │ ├── Codec.hpp │ ├── ColorL.cpp │ ├── ColorL.hpp │ ├── ColorL8.cpp │ ├── ColorL8.hpp │ ├── ColorRgb.cpp │ ├── ColorRgb.hpp │ ├── ColorRgb8.cpp │ ├── ColorRgb8.hpp │ ├── ColorRgba.cpp │ ├── ColorRgba.hpp │ ├── ColorRgba8.cpp │ ├── ColorRgba8.hpp │ ├── Colors.hpp │ ├── Common.hpp │ ├── CommonEnums.hpp │ ├── Concept.hpp │ ├── Cone3.hpp │ ├── ConeN.hpp │ ├── CoordinateFrame2.hpp │ ├── CoordinateFrame3.hpp │ ├── CoordinateFrameN.hpp │ ├── Crypto.cpp │ ├── Crypto.hpp │ ├── Cylinder3.hpp │ ├── CylinderN.hpp │ ├── Deque.hpp │ ├── DynLib.cpp │ ├── DynLib.hpp │ ├── EnumClass.hpp │ ├── Error.hpp │ ├── FilePath.cpp │ ├── FilePath.hpp │ ├── FileSystem.cpp │ ├── FileSystem.hpp │ ├── GraphType.hpp │ ├── Graphics │ ├── Camera.cpp │ ├── Camera.hpp │ ├── DcelFace.hpp │ ├── DcelHalfedge.hpp │ ├── DcelMesh.hpp │ ├── DcelVertex.hpp │ ├── DefaultMeshCodecs.hpp │ ├── DisplayMesh.cpp │ ├── DisplayMesh.hpp │ ├── EdgeWelder.cpp │ ├── EdgeWelder.hpp │ ├── GeneralMesh.hpp │ ├── GeneralMeshEdge.hpp │ ├── GeneralMeshFace.hpp │ ├── GeneralMeshVertex.hpp │ ├── GraphicsAttributes.hpp │ ├── IBuffer.hpp │ ├── IBufferPool.hpp │ ├── IDrawable.hpp │ ├── IFramebuffer.hpp │ ├── IMesh.hpp │ ├── IRenderSystem.cpp │ ├── IRenderSystem.hpp │ ├── IShader.hpp │ ├── ITexture.hpp │ ├── IncrementalDcelMeshBuilder.hpp │ ├── IncrementalDisplayMeshBuilder.hpp │ ├── IncrementalGeneralMeshBuilder.hpp │ ├── IncrementalMeshBuilder.hpp │ ├── MeshCodec.hpp │ ├── MeshCodec3ds.hpp │ ├── MeshCodecObj.hpp │ ├── MeshCodecOff.hpp │ ├── MeshCodecPly.hpp │ ├── MeshGroup.hpp │ ├── MeshType.hpp │ ├── RenderOptions.hpp │ ├── TextureFormat.cpp │ ├── TextureFormat.hpp │ ├── VertexWelder.cpp │ └── VertexWelder.hpp │ ├── Hash.hpp │ ├── Hyperplane3.hpp │ ├── HyperplaneN.hpp │ ├── IAddressableMatrix.hpp │ ├── ICompressedSparseMatrix.hpp │ ├── IDenseMatrix.hpp │ ├── IImage.hpp │ ├── IMatrix.hpp │ ├── IPlugin.cpp │ ├── IPlugin.hpp │ ├── IRowOrColumnMajorMatrix.hpp │ ├── ISparseMatrix.hpp │ ├── Image.cpp │ ├── Image.hpp │ ├── ImageMatrix.hpp │ ├── Iostream.hpp │ ├── Line2.hpp │ ├── Line3.hpp │ ├── LineN.hpp │ ├── LineSegment2.hpp │ ├── LineSegment3.hpp │ ├── LineSegmentN.hpp │ ├── List.hpp │ ├── Log.cpp │ ├── Log.hpp │ ├── Map.hpp │ ├── MappedMatrix.hpp │ ├── MatVec.hpp │ ├── Math.cpp │ ├── Math.hpp │ ├── MathTables.cpp │ ├── MatrixFormat.hpp │ ├── MatrixIO.hpp │ ├── MatrixUtil.hpp │ ├── MatrixWrapper.hpp │ ├── Memory.hpp │ ├── NamedObject.hpp │ ├── Noncopyable.hpp │ ├── NumericType.hpp │ ├── Options.hpp │ ├── ParametricCurve3.hpp │ ├── ParametricCurveN.hpp │ ├── Plane3.hpp │ ├── Platform.hpp │ ├── Plugins │ ├── ARPACK │ │ ├── ArpackCommon.hpp │ │ ├── ArpackEigenSolver.cpp │ │ ├── ArpackEigenSolver.hpp │ │ ├── ArpackEigenSolverDense.cpp │ │ ├── ArpackEigenSolverSparse.cpp │ │ ├── ArpackPlugin.cpp │ │ ├── ArpackPlugin.hpp │ │ └── ArpackSymbolVisibility.hpp │ ├── CSPARSE │ │ ├── CsparseCommon.hpp │ │ ├── CsparseLinearSolver.cpp │ │ ├── CsparseLinearSolver.hpp │ │ ├── CsparsePlugin.cpp │ │ ├── CsparsePlugin.hpp │ │ └── CsparseSymbolVisibility.hpp │ └── GL │ │ ├── GlBuffer.cpp │ │ ├── GlBuffer.hpp │ │ ├── GlBufferPool.cpp │ │ ├── GlBufferPool.hpp │ │ ├── GlCaps.cpp │ │ ├── GlCaps.hpp │ │ ├── GlCommon.hpp │ │ ├── GlFramebuffer.cpp │ │ ├── GlFramebuffer.hpp │ │ ├── GlHeaders.hpp │ │ ├── GlPlugin.cpp │ │ ├── GlPlugin.hpp │ │ ├── GlRenderSystem.cpp │ │ ├── GlRenderSystem.hpp │ │ ├── GlShader.cpp │ │ ├── GlShader.hpp │ │ ├── GlSymbolVisibility.hpp │ │ ├── GlTexture.cpp │ │ └── GlTexture.hpp │ ├── Polygon2.cpp │ ├── Polygon2.hpp │ ├── Polygon3.cpp │ ├── Polygon3.hpp │ ├── Queue.hpp │ ├── Random.cpp │ ├── Random.hpp │ ├── Ray3.hpp │ ├── RayIntersectable3.hpp │ ├── RayIntersectableN.hpp │ ├── RayN.hpp │ ├── RigidTransform2.hpp │ ├── RigidTransform3.hpp │ ├── RigidTransformN.hpp │ ├── ScopedLock.hpp │ ├── Serializable.cpp │ ├── Serializable.hpp │ ├── Set.hpp │ ├── SortedArray.hpp │ ├── SparseMatVec.hpp │ ├── SparseMatrixWrapper.hpp │ ├── Spinlock.hpp │ ├── SplineN.hpp │ ├── Stack.hpp │ ├── Stopwatch.hpp │ ├── StringAlg.cpp │ ├── StringAlg.hpp │ ├── SymbolVisibility.hpp │ ├── System.cpp │ ├── System.hpp │ ├── Test │ ├── TestARPACK.cpp │ ├── TestBagOfWords.cpp │ ├── TestBezier.cpp │ ├── TestBvh.cpp │ ├── TestCSPARSE.cpp │ ├── TestDisplayMesh.cpp │ ├── TestGL.cpp │ ├── TestHoughForest.cpp │ ├── TestIterators.cpp │ ├── TestJointBoost.cpp │ ├── TestLaplaceBeltrami.cpp │ ├── TestMath.cpp │ ├── TestMesh.cpp │ ├── TestMetrics.cpp │ ├── TestPCA.cpp │ ├── TestParam.cpp │ ├── TestPyramidMatch.cpp │ └── TestZernike.cpp │ ├── TextInputStream.cpp │ ├── TextInputStream.hpp │ ├── TextOutputStream.cpp │ ├── TextOutputStream.hpp │ ├── ThirdParty │ ├── BloomenthalPolygonizer │ │ ├── polygonizer.cpp │ │ └── polygonizer.h │ ├── CLI11 │ │ └── CLI11.hpp │ ├── CSPARSE │ │ ├── csparse.c │ │ └── csparse.h │ ├── GLEW │ │ ├── eglew.h │ │ ├── glew.c │ │ ├── glew.h │ │ ├── glxew.h │ │ └── wglew.h │ ├── NNLS │ │ ├── nnls.c │ │ └── nnls.h │ ├── StanHull │ │ ├── hull.cpp │ │ └── hull.h │ ├── Triangle │ │ ├── triangle.c │ │ └── triangle.h │ ├── arpackpp │ │ ├── README │ │ ├── arbgcomp.h │ │ ├── arbgnsym.h │ │ ├── arbgsym.h │ │ ├── arbnsmat.h │ │ ├── arbnspen.h │ │ ├── arbscomp.h │ │ ├── arbsmat.h │ │ ├── arbsnsym.h │ │ ├── arbspen.h │ │ ├── arbssym.h │ │ ├── arch.h │ │ ├── arcomp.h │ │ ├── ardfmat.h │ │ ├── ardgcomp.h │ │ ├── ardgnsym.h │ │ ├── ardgsym.h │ │ ├── ardnsmat.h │ │ ├── ardnspen.h │ │ ├── ardscomp.h │ │ ├── ardsmat.h │ │ ├── ardsnsym.h │ │ ├── ardspen.h │ │ ├── ardssym.h │ │ ├── arerror.h │ │ ├── argcomp.h │ │ ├── argeig.h │ │ ├── argnsym.h │ │ ├── argsym.h │ │ ├── arhbmat.h │ │ ├── arlcomp.h │ │ ├── arlgcomp.h │ │ ├── arlgnsym.h │ │ ├── arlgsym.h │ │ ├── arlnames.h │ │ ├── arlnsmat.h │ │ ├── arlnspen.h │ │ ├── arlscomp.h │ │ ├── arlsmat.h │ │ ├── arlsnsym.h │ │ ├── arlspdef.h │ │ ├── arlspen.h │ │ ├── arlssym.h │ │ ├── arlsupm.h │ │ ├── arlutil.h │ │ ├── armat.h │ │ ├── arpackf.h │ │ ├── arrgcomp.h │ │ ├── arrgeig.h │ │ ├── arrgnsym.h │ │ ├── arrgsym.h │ │ ├── arrscomp.h │ │ ├── arrseig.h │ │ ├── arrsnsym.h │ │ ├── arrssym.h │ │ ├── arscomp.h │ │ ├── arseig.h │ │ ├── arsnsym.h │ │ ├── arssym.h │ │ ├── arugcomp.h │ │ ├── arugnsym.h │ │ ├── arugsym.h │ │ ├── arunsmat.h │ │ ├── arunspen.h │ │ ├── aruscomp.h │ │ ├── arusmat.h │ │ ├── arusnsym.h │ │ ├── aruspen.h │ │ ├── arussym.h │ │ ├── blas1c.h │ │ ├── blas1f.h │ │ ├── caupp.h │ │ ├── ceupp.h │ │ ├── debug.h │ │ ├── lapackc.h │ │ ├── lapackf.h │ │ ├── naupp.h │ │ ├── neupp.h │ │ ├── saupp.h │ │ ├── seupp.h │ │ ├── superluc.h │ │ ├── umfpackc.h │ │ └── umfpackf.h │ ├── dx │ │ ├── dx.h │ │ ├── error.h │ │ ├── memory.h │ │ ├── memorystubs.c │ │ ├── simplesurf.c │ │ └── simplesurf.h │ ├── fibheap │ │ ├── fibheap.cpp │ │ ├── fibheap.hpp │ │ └── fibheap_private.hpp │ ├── miniball │ │ ├── Seb-inl.h │ │ ├── Seb.h │ │ ├── Seb_configure.h │ │ ├── Seb_debug.cpp │ │ ├── Seb_debug.h │ │ ├── Seb_point.h │ │ ├── Subspan-inl.h │ │ └── Subspan.h │ └── stb │ │ ├── stb_image.h │ │ ├── stb_image_resize.h │ │ └── stb_image_write.h │ ├── ThreadGroup.hpp │ ├── Tools │ ├── Browse3D │ │ ├── App.cpp │ │ ├── App.hpp │ │ ├── Common.hpp │ │ ├── GraphicsWidget.cpp │ │ ├── GraphicsWidget.hpp │ │ ├── MainWindow.cpp │ │ ├── MainWindow.hpp │ │ ├── Math.cpp │ │ ├── Math.hpp │ │ ├── Mesh.cpp │ │ ├── Mesh.hpp │ │ ├── MeshFwd.hpp │ │ ├── Model.cpp │ │ ├── Model.hpp │ │ ├── ModelDisplay.cpp │ │ ├── ModelDisplay.hpp │ │ ├── PointCloud.cpp │ │ ├── PointCloud.hpp │ │ ├── Segment.cpp │ │ ├── Segment.hpp │ │ ├── Util.cpp │ │ └── Util.hpp │ ├── GIP │ │ └── gip.cpp │ ├── GeoSphere │ │ └── GeoSphere.cpp │ ├── ImageFeatures │ │ └── ImageFeatures.cpp │ ├── MeshConv │ │ └── MeshConv.cpp │ ├── MeshFix │ │ └── MeshFix.cpp │ ├── MeshGlobalFeatures │ │ └── MeshGlobalFeatures.cpp │ ├── MeshLocalFeatures │ │ └── MeshLocalFeatures.cpp │ ├── MeshSample │ │ └── MeshSample.cpp │ ├── Register │ │ └── Register.cpp │ ├── RenderShape │ │ ├── ShapeRenderer.cpp │ │ ├── ShapeRenderer.hpp │ │ └── main.cpp │ ├── SampleGraph │ │ └── SampleGraph.cpp │ ├── SegmentSDF │ │ ├── Graph.hpp │ │ └── main.cpp │ └── ShapeAlign │ │ └── ShapeAlign.cpp │ ├── Torus3.hpp │ ├── TorusN.hpp │ ├── Transformable.hpp │ ├── Triangle3.hpp │ ├── TriangleN.hpp │ ├── UnionFind.hpp │ ├── UnorderedMap.hpp │ ├── UnorderedSet.hpp │ └── VariantMatrix.hpp ├── Data ├── Misc │ └── iris.txt └── Models │ ├── cube.obj │ ├── sphere.obj │ └── teapot.obj ├── LICENSE.txt └── README.md /.gitattributes: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/dealing-with-line-endings 2 | 3 | # Set default behaviour, in case users don't have core.autocrlf set. 4 | * text=auto 5 | 6 | # Explicitly declare text files we want to always be normalized and converted 7 | # to native line endings on checkout. 8 | *.c text 9 | *.C text 10 | *.cc text 11 | *.cmake text 12 | *.cpp text 13 | *.css text 14 | *.cxx text 15 | *.h text 16 | *.H text 17 | *.hh text 18 | *.hpp text 19 | *.html text 20 | *.hxx text 21 | *.md text 22 | *.txt text 23 | 24 | # Declare files that will always have CRLF line endings on checkout. 25 | *.bat text eol=crlf 26 | *.sln text eol=crlf 27 | 28 | # Denote all files that are truly binary and should not be modified. 29 | *.3ds binary 30 | *.7z binary 31 | *.bmp binary 32 | *.bz2 binary 33 | *.gif binary 34 | *.jpg binary 35 | *.jpeg binary 36 | *.obj binary 37 | *.off binary 38 | *.off.bin binary 39 | *.mbp binary 40 | *.patch binary 41 | *.png binary 42 | *.rtf binary 43 | *.seg binary 44 | *.tar binary 45 | *.tar.gz binary 46 | *.tif binary 47 | *.zip binary 48 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "Code/Build/Common/CMake"] 2 | path = Code/Build/Common/CMake 3 | url = https://github.com/sidch/CMake.git 4 | -------------------------------------------------------------------------------- /Code/Build/Plugins/ARPACK/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #=============================================================================================================================== 2 | # 3 | # Build script for the Thea ARPACK eigensolver plugin. 4 | # 5 | # Copyright (C) 2010, Siddhartha Chaudhuri/Stanford University 6 | # 7 | #=============================================================================================================================== 8 | 9 | # Setup build 10 | GET_FILENAME_COMPONENT(Thea_PROJECT_ROOT ../../.. ABSOLUTE) 11 | SET(Thea_FIND_ALL TRUE) 12 | INCLUDE(${Thea_PROJECT_ROOT}/Build/Common/BuildSetup.cmake NO_POLICY_SCOPE) 13 | 14 | PROJECT(TheaPluginARPACK CXX C) 15 | 16 | # Dependency: ARPACK 17 | IF(EXISTS ${THEA_DEPS_ROOT}/installed-arpack) 18 | SET(ARPACK_ROOT ${THEA_DEPS_ROOT}/installed-arpack) 19 | ELSE() 20 | SET(ARPACK_ROOT ${THEA_DEPS_ROOT}) 21 | ENDIF() 22 | FIND_PACKAGE(ARPACK) 23 | 24 | # If we can't find ARPACK, don't build this plugin 25 | IF(ARPACK_FOUND) 26 | 27 | # Dependency: SuperLU (optional) 28 | IF(EXISTS ${THEA_DEPS_ROOT}/installed-superlu) 29 | SET(SuperLU_ROOT ${THEA_DEPS_ROOT}/installed-superlu) 30 | ELSE() 31 | SET(SuperLU_ROOT ${THEA_DEPS_ROOT}) 32 | ENDIF() 33 | SET(SuperLU_LIBS_ONLY TRUE) 34 | FIND_PACKAGE(SuperLU) 35 | 36 | IF(SuperLU_FOUND) 37 | ADD_DEFINITIONS(-DTHEA_HAVE_SUPERLU) 38 | ELSE() 39 | SET(SuperLU_INCLUDE_DIRS "") 40 | SET(SuperLU_LIBRARIES "") 41 | ENDIF() 42 | 43 | # Shared library flags 44 | ADD_DEFINITIONS(-DTHEA_ARPACK_DLL -DTHEA_ARPACK_DLL_EXPORTS) 45 | IF(THEA_DLL) 46 | ADD_DEFINITIONS(-DTHEA_DLL -DTHEA_DLL_IMPORTS) 47 | ENDIF() 48 | 49 | # ARPACK++ throws a bunch of harmless (?) warnings which are easier to ignore than to fix 50 | IF(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") 51 | SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-overloaded-virtual") 52 | ENDIF() 53 | 54 | # Source file lists 55 | FILE(GLOB TheaPluginARPACKSources ${SourceRoot}/Plugins/ARPACK/*.cpp) 56 | 57 | # Libraries to link to 58 | SET(TheaPluginARPACKLibraries 59 | Thea 60 | ${SuperLU_LIBRARIES} 61 | ${ARPACK_LIBRARIES} 62 | ${Thea_DEPS_LIBRARIES}) 63 | 64 | # Build products 65 | ADD_LIBRARY(TheaPluginARPACK SHARED ${TheaPluginARPACKSources}) 66 | 67 | # Additional libraries to be linked 68 | TARGET_LINK_LIBRARIES(TheaPluginARPACK ${TheaPluginARPACKLibraries}) 69 | SET_TARGET_PROPERTIES(TheaPluginARPACK PROPERTIES LINK_FLAGS "${Thea_DEPS_LDFLAGS}") 70 | 71 | # Fix library install names on OS X 72 | IF(APPLE) 73 | INCLUDE(${CMAKE_MODULE_PATH}/OSXFixDylibReferences.cmake) 74 | OSX_FIX_DYLIB_REFERENCES(TheaPluginARPACK "${TheaPluginARPACKLibraries}") 75 | ENDIF() 76 | 77 | # Install rules 78 | SET_TARGET_PROPERTIES(TheaPluginARPACK 79 | PROPERTIES 80 | INSTALL_RPATH_USE_LINK_PATH TRUE 81 | INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib") 82 | 83 | INSTALL(TARGETS TheaPluginARPACK DESTINATION lib) 84 | INSTALL(TARGETS TheaPluginARPACK DESTINATION share/Thea/Build/Output/lib) # for tools to use 85 | 86 | ELSE(ARPACK_FOUND) 87 | 88 | MESSAGE(STATUS "ARPACK not found: ARPACK plugin will not be built") 89 | 90 | ENDIF(ARPACK_FOUND) 91 | -------------------------------------------------------------------------------- /Code/Build/Plugins/CSPARSE/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | #=============================================================================================================================== 2 | # 3 | # Build script for the Thea CSPARSE linear solver plugin. 4 | # 5 | # Copyright (C) 2011, Siddhartha Chaudhuri/Stanford University 6 | # 7 | #=============================================================================================================================== 8 | 9 | # Setup build 10 | GET_FILENAME_COMPONENT(Thea_PROJECT_ROOT ../../.. ABSOLUTE) 11 | SET(Thea_FIND_ALL TRUE) 12 | INCLUDE(${Thea_PROJECT_ROOT}/Build/Common/BuildSetup.cmake NO_POLICY_SCOPE) 13 | 14 | PROJECT(TheaPluginCSPARSE CXX C) 15 | 16 | # Shared library flags 17 | ADD_DEFINITIONS(-DTHEA_CSPARSE_DLL -DTHEA_CSPARSE_DLL_EXPORTS) 18 | IF(THEA_DLL) 19 | ADD_DEFINITIONS(-DTHEA_DLL -DTHEA_DLL_IMPORTS) 20 | ENDIF() 21 | 22 | # Source file lists 23 | FILE(GLOB TheaPluginCSPARSESources 24 | ${ThirdPartyRoot}/CSPARSE/*.c 25 | ${SourceRoot}/Plugins/CSPARSE/*.cpp) 26 | 27 | # Libraries to link to 28 | SET(TheaPluginCSPARSELibraries 29 | Thea 30 | ${Thea_DEPS_LIBRARIES}) 31 | 32 | # Build products 33 | ADD_LIBRARY(TheaPluginCSPARSE SHARED ${TheaPluginCSPARSESources}) 34 | 35 | # Additional libraries to be linked 36 | TARGET_LINK_LIBRARIES(TheaPluginCSPARSE ${TheaPluginCSPARSELibraries}) 37 | SET_TARGET_PROPERTIES(TheaPluginCSPARSE PROPERTIES LINK_FLAGS "${Thea_DEPS_LDFLAGS}") 38 | 39 | # Fix library install names on OS X 40 | IF(APPLE) 41 | INCLUDE(${CMAKE_MODULE_PATH}/OSXFixDylibReferences.cmake) 42 | OSX_FIX_DYLIB_REFERENCES(TheaPluginCSPARSE "${TheaPluginCSPARSELibraries}") 43 | ENDIF() 44 | 45 | # Install rules 46 | SET_TARGET_PROPERTIES(TheaPluginCSPARSE 47 | PROPERTIES 48 | INSTALL_RPATH_USE_LINK_PATH TRUE 49 | INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib") 50 | 51 | INSTALL(TARGETS TheaPluginCSPARSE DESTINATION lib) 52 | INSTALL(TARGETS TheaPluginCSPARSE DESTINATION share/Thea/Build/Output/lib) # for tools to use 53 | -------------------------------------------------------------------------------- /Code/Documentation/images/header.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sidch/Thea/b0b24a8b0000fe9e43f61d482a4295f6f1db7474/Code/Documentation/images/header.jpg -------------------------------------------------------------------------------- /Code/Documentation/images/remesh.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sidch/Thea/b0b24a8b0000fe9e43f61d482a4295f6f1db7474/Code/Documentation/images/remesh.jpg -------------------------------------------------------------------------------- /Code/Documentation/notes.txt: -------------------------------------------------------------------------------- 1 | - GPU-accelerated meshes should somehow release their GPU buffers when they are destroyed, but the destructor is not provided a rendersystem reference. 2 | -------------------------------------------------------------------------------- /Code/Install/install-thea-win32-express.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | echo !!! Please ensure all support libraries have already been installed !!! 4 | echo. 5 | echo To specify a installation directory for Thea other than the directory 6 | echo containing this script, pass this directory as the first argument to 7 | echo the script. This should also be the directory containing the support 8 | echo libraries. 9 | echo. 10 | echo Installing Thea... 11 | 12 | pushd %~dp0 13 | 14 | if "%1"=="" ( 15 | set THEA_PREFIX="%CD%" 16 | ) else ( 17 | set THEA_PREFIX="%1" 18 | ) 19 | 20 | cd ..\Build 21 | cmake "-DCMAKE_INSTALL_PREFIX=%THEA_PREFIX%" -G "Visual Studio 10" . 22 | 23 | msbuild Thea.sln /p:Configuration="Release" 24 | msbuild INSTALL.vcxproj /p:Configuration="Release" 25 | 26 | msbuild Thea.sln /p:Configuration="Debug" 27 | msbuild INSTALL.vcxproj /p:Configuration="Debug" 28 | 29 | set THEA_PREFIX= 30 | 31 | popd 32 | -------------------------------------------------------------------------------- /Code/Install/install-thea-win32.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | echo !!! Please ensure all support libraries have already been installed !!! 4 | echo. 5 | echo To specify a installation directory for Thea other than the directory 6 | echo containing this script, pass this directory as the first argument to 7 | echo the script. This should also be the directory containing the support 8 | echo libraries. 9 | echo. 10 | echo Installing Thea... 11 | 12 | pushd %~dp0 13 | 14 | if "%1"=="" ( 15 | set THEA_PREFIX="%CD%" 16 | ) else ( 17 | set THEA_PREFIX="%1" 18 | ) 19 | 20 | cd ..\Build 21 | cmake "-DCMAKE_INSTALL_PREFIX=%THEA_PREFIX%" -G "Visual Studio 10" . 22 | 23 | devenv /Build Release Thea.sln 24 | devenv /Build Release /Project INSTALL Thea.sln 25 | 26 | devenv /Build Debug Thea.sln 27 | devenv /Build Debug /Project INSTALL Thea.sln 28 | 29 | set THEA_PREFIX= 30 | 31 | popd 32 | -------------------------------------------------------------------------------- /Code/Install/install-thea-win64-express.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | echo !!! Please ensure all support libraries have already been installed !!! 4 | echo. 5 | echo To specify a installation directory for Thea other than the directory 6 | echo containing this script, pass this directory as the first argument to 7 | echo the script. This should also be the directory containing the support 8 | echo libraries. 9 | echo. 10 | echo Installing Thea... 11 | 12 | pushd %~dp0 13 | 14 | if "%1"=="" ( 15 | set THEA_PREFIX="%CD%" 16 | ) else ( 17 | set THEA_PREFIX="%1" 18 | ) 19 | 20 | cd ..\Build 21 | cmake "-DCMAKE_INSTALL_PREFIX=%THEA_PREFIX%" -G "Visual Studio 10 Win64" . 22 | 23 | msbuild Thea.sln /p:Configuration="Release" 24 | msbuild INSTALL.vcxproj /p:Configuration="Release" 25 | 26 | msbuild Thea.sln /p:Configuration="Debug" 27 | msbuild INSTALL.vcxproj /p:Configuration="Debug" 28 | 29 | set THEA_PREFIX= 30 | 31 | popd 32 | -------------------------------------------------------------------------------- /Code/Install/install-thea-win64.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | echo !!! Please ensure all support libraries have already been installed !!! 4 | echo. 5 | echo To specify a installation directory for Thea other than the directory 6 | echo containing this script, pass this directory as the first argument to 7 | echo the script. This should also be the directory containing the support 8 | echo libraries. 9 | echo. 10 | echo Installing Thea... 11 | 12 | pushd %~dp0 13 | 14 | if "%1"=="" ( 15 | set THEA_PREFIX="%CD%" 16 | ) else ( 17 | set THEA_PREFIX="%1" 18 | ) 19 | 20 | cd ..\Build 21 | rem cmake "-DCMAKE_INSTALL_PREFIX=%THEA_PREFIX%" -DBOOST_ROOT=C:\Boost32 -DQT_QMAKE_EXECUTABLE=C:\Qt32\4.8.2\bin\qmake.exe -DCGAL_ROOT=C:\CGAL-3.7-32 -G "Visual Studio 10 Win64" . 22 | cmake "-DCMAKE_INSTALL_PREFIX=%THEA_PREFIX%" -G "Visual Studio 10 Win64" . 23 | 24 | devenv /Build Release Thea.sln 25 | devenv /Build Release /Project INSTALL Thea.sln 26 | 27 | devenv /Build Debug Thea.sln 28 | devenv /Build Debug /Project INSTALL Thea.sln 29 | 30 | set THEA_PREFIX= 31 | 32 | popd 33 | -------------------------------------------------------------------------------- /Code/Resources/Icons/Custom/48x48/view-shaded-wireframe.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sidch/Thea/b0b24a8b0000fe9e43f61d482a4295f6f1db7474/Code/Resources/Icons/Custom/48x48/view-shaded-wireframe.png -------------------------------------------------------------------------------- /Code/Resources/Icons/Custom/48x48/view-shaded.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sidch/Thea/b0b24a8b0000fe9e43f61d482a4295f6f1db7474/Code/Resources/Icons/Custom/48x48/view-shaded.png -------------------------------------------------------------------------------- /Code/Resources/Icons/Custom/48x48/view-wireframe.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sidch/Thea/b0b24a8b0000fe9e43f61d482a4295f6f1db7474/Code/Resources/Icons/Custom/48x48/view-wireframe.png -------------------------------------------------------------------------------- /Code/Resources/Icons/Custom/Source/view-shaded-wireframe.odg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sidch/Thea/b0b24a8b0000fe9e43f61d482a4295f6f1db7474/Code/Resources/Icons/Custom/Source/view-shaded-wireframe.odg -------------------------------------------------------------------------------- /Code/Resources/Icons/Custom/Source/view-shaded-wireframe.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sidch/Thea/b0b24a8b0000fe9e43f61d482a4295f6f1db7474/Code/Resources/Icons/Custom/Source/view-shaded-wireframe.pdf -------------------------------------------------------------------------------- /Code/Resources/Icons/Custom/Source/view-shaded.odg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sidch/Thea/b0b24a8b0000fe9e43f61d482a4295f6f1db7474/Code/Resources/Icons/Custom/Source/view-shaded.odg -------------------------------------------------------------------------------- /Code/Resources/Icons/Custom/Source/view-shaded.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sidch/Thea/b0b24a8b0000fe9e43f61d482a4295f6f1db7474/Code/Resources/Icons/Custom/Source/view-shaded.pdf -------------------------------------------------------------------------------- /Code/Resources/Icons/Custom/Source/view-wireframe.odg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sidch/Thea/b0b24a8b0000fe9e43f61d482a4295f6f1db7474/Code/Resources/Icons/Custom/Source/view-wireframe.odg -------------------------------------------------------------------------------- /Code/Resources/Icons/Custom/Source/view-wireframe.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sidch/Thea/b0b24a8b0000fe9e43f61d482a4295f6f1db7474/Code/Resources/Icons/Custom/Source/view-wireframe.pdf -------------------------------------------------------------------------------- /Code/Resources/Icons/Tango/16x16/zoom-fit-best.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sidch/Thea/b0b24a8b0000fe9e43f61d482a4295f6f1db7474/Code/Resources/Icons/Tango/16x16/zoom-fit-best.png -------------------------------------------------------------------------------- /Code/Resources/Icons/Tango/22x22/zoom-fit-best.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sidch/Thea/b0b24a8b0000fe9e43f61d482a4295f6f1db7474/Code/Resources/Icons/Tango/22x22/zoom-fit-best.png -------------------------------------------------------------------------------- /Code/Resources/Icons/Tango/32x32/zoom-fit-best.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sidch/Thea/b0b24a8b0000fe9e43f61d482a4295f6f1db7474/Code/Resources/Icons/Tango/32x32/zoom-fit-best.png -------------------------------------------------------------------------------- /Code/Resources/Icons/Tango/48x48/zoom-fit-best.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sidch/Thea/b0b24a8b0000fe9e43f61d482a4295f6f1db7474/Code/Resources/Icons/Tango/48x48/zoom-fit-best.png -------------------------------------------------------------------------------- /Code/Resources/Images/background.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sidch/Thea/b0b24a8b0000fe9e43f61d482a4295f6f1db7474/Code/Resources/Images/background.jpg -------------------------------------------------------------------------------- /Code/Resources/Materials/FlatTextureFrag.glsl: -------------------------------------------------------------------------------- 1 | uniform sampler2D texture; 2 | 3 | void main() 4 | { 5 | gl_FragColor = texture2D(texture, gl_TexCoord[0].xy); 6 | } 7 | -------------------------------------------------------------------------------- /Code/Resources/Materials/FlatTextureVert.glsl: -------------------------------------------------------------------------------- 1 | void main() 2 | { 3 | gl_Position = ftransform(); 4 | gl_TexCoord[0] = gl_MultiTexCoord0; 5 | } 6 | -------------------------------------------------------------------------------- /Code/Resources/Materials/MatcapFrag.glsl: -------------------------------------------------------------------------------- 1 | uniform sampler2D matcap_tex; 2 | uniform float two_sided; 3 | uniform float flat_shaded; 4 | 5 | varying vec3 position; // position in camera space 6 | varying vec3 normal; // normal in camera space 7 | 8 | float lightness(vec3 color) 9 | { 10 | return 0.5 * (max(max(color.r, color.g), color.b) + min(min(color.r, color.g), color.b)); 11 | } 12 | 13 | void main() 14 | { 15 | vec3 N = normalize(flat_shaded > 0.5 ? cross(dFdx(position), dFdy(position)) : normal); 16 | vec2 matcap_uv = (two_sided < 0.5 && N.z < 0.0 ? normalize(N.xy) : N.xy); 17 | vec4 matcap_color = texture2D(matcap_tex, 0.495 * matcap_uv + 0.5); 18 | 19 | float lite = lightness(matcap_color.rgb); 20 | float highlight_blend = lite * lite * lite * lite; 21 | gl_FragColor = vec4(mix(gl_Color.rgb, vec3(1.0, 1.0, 1.0), highlight_blend) * matcap_color.rgb, gl_Color.a); 22 | } 23 | -------------------------------------------------------------------------------- /Code/Resources/Materials/PhongFrag.glsl: -------------------------------------------------------------------------------- 1 | uniform vec4 material; // [ka, kl, , ] 2 | uniform vec3 ambient_color; 3 | uniform vec3 light_dir; // must be specified in camera space, pointing towards object 4 | uniform vec3 light_color; 5 | uniform float two_sided; 6 | uniform float flat_shaded; 7 | 8 | varying vec3 position; // position in camera space 9 | varying vec3 normal; // normal in camera space 10 | 11 | void main() 12 | { 13 | vec3 N = normalize(flat_shaded > 0.5 ? cross(dFdx(position), dFdy(position)) : normal); 14 | vec3 L = normalize(light_dir); 15 | 16 | vec3 ambt_color = material[0] * gl_Color.rgb * ambient_color; 17 | 18 | float NdL = -dot(N, L); 19 | vec3 lamb_color = (NdL >= -two_sided) ? material[1] * abs(NdL) * gl_Color.rgb * light_color : vec3(0.0, 0.0, 0.0); 20 | 21 | gl_FragColor = vec4(ambt_color + lamb_color, 1.0); 22 | } 23 | -------------------------------------------------------------------------------- /Code/Resources/Materials/PhongVert.glsl: -------------------------------------------------------------------------------- 1 | varying vec3 position; // position in camera space 2 | varying vec3 normal; // normal in camera space 3 | 4 | void main() 5 | { 6 | gl_Position = ftransform(); 7 | 8 | position = vec3(gl_ModelViewMatrix * gl_Vertex); // assume rigid transform, so we can drop w 9 | normal = gl_NormalMatrix * gl_Normal; 10 | 11 | gl_FrontColor = gl_Color; 12 | gl_BackColor = gl_Color; 13 | } 14 | -------------------------------------------------------------------------------- /Code/Source/Algorithms/ApproximateConvexDecomposition.cpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2009 12 | // 13 | //============================================================================ 14 | 15 | #include "ApproximateConvexDecomposition.hpp" 16 | 17 | namespace Thea { 18 | namespace Algorithms { 19 | 20 | void 21 | ApproximateConvexPointDecomposition::decompose(double convexity_threshold, Array< Array > & results) 22 | { 23 | results.clear(); 24 | } 25 | 26 | } // namespace Algorithms 27 | } // namespace Thea 28 | -------------------------------------------------------------------------------- /Code/Source/Algorithms/ApproximateConvexDecomposition.hpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2009 12 | // 13 | //============================================================================ 14 | 15 | #ifndef __Thea_Algorithms_ApproximateConvexDecomposition_hpp__ 16 | #define __Thea_Algorithms_ApproximateConvexDecomposition_hpp__ 17 | 18 | #include "../Common.hpp" 19 | #include "../Array.hpp" 20 | #include "../MatVec.hpp" 21 | 22 | namespace Thea { 23 | namespace Algorithms { 24 | 25 | /** Approximate convex decomposition of point clouds. */ 26 | class THEA_API ApproximateConvexPointDecomposition 27 | { 28 | public: 29 | THEA_DECL_SMART_POINTERS(ApproximateConvexPointDecomposition) 30 | 31 | /** Add a point to the cloud to be decomposed. */ 32 | void addPoint(Vector3 const & p) { points.push_back(p); } 33 | 34 | /** Add a set of points to the cloud to be decomposed. */ 35 | template void addPoint(PointInputIterator begin, PointInputIterator end) 36 | { points.insert(points.end(), begin, end); } 37 | 38 | /** Compute the approximate convex decomposition. */ 39 | void decompose(double convexity_threshold, Array< Array > & results); 40 | 41 | private: 42 | Array points; 43 | 44 | }; // class ApproximateConvexPointDecomposition 45 | 46 | } // namespace Algorithms 47 | } // namespace Thea 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /Code/Source/Algorithms/BestFitBox3.hpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2009 12 | // 13 | //============================================================================ 14 | 15 | #ifndef __Thea_Algorithms_BestFitBox3_hpp__ 16 | #define __Thea_Algorithms_BestFitBox3_hpp__ 17 | 18 | #include "../Common.hpp" 19 | #include "../Array.hpp" 20 | #include "../Box3.hpp" 21 | 22 | namespace Thea { 23 | namespace Algorithms { 24 | 25 | /** Approximate best-fit oriented bounding box. */ 26 | class THEA_API BestFitBox3 27 | { 28 | public: 29 | THEA_DECL_SMART_POINTERS(BestFitBox3) 30 | 31 | /** Constructor. */ 32 | BestFitBox3(); 33 | 34 | /** Add a point to the set. */ 35 | void addPoint(Vector3 const & point); 36 | 37 | /** Remove all data and (lazily) set the box to null. */ 38 | void clear(); 39 | 40 | /** Set the up vector. The computed box will only consider orientations with the given up vector. */ 41 | void setUpVector(Vector3 const & up_) { up = up_.normalized(); has_up = true; } 42 | 43 | /** Check if the up vector has been set. */ 44 | bool hasUpVector() const { return has_up; } 45 | 46 | /** 47 | * Get the up vector, if it has been set. 48 | * 49 | * @see hasUpVector(); 50 | */ 51 | Vector3 const & getUpVector() const { return up; } 52 | 53 | /** Clear the up vector. Subsequent alignments will be unconstrained. */ 54 | void clearUpVector() { has_up = false; } 55 | 56 | /** Remove all cached data to free memory, but do not mark the box for recomputation. */ 57 | void releaseMemoryWithoutUpdate(); 58 | 59 | /** Get the box object. Will only force a recomputation if new data have been added since the last call to this function. */ 60 | Box3 const & getBox() const; 61 | 62 | private: 63 | /** Recompute the best-fit oriented bounding box. */ 64 | void update() const; 65 | 66 | Array points; 67 | bool has_up; 68 | Vector3 up; 69 | 70 | mutable Box3 box; 71 | mutable bool updated; 72 | 73 | }; // class BestFitBox3 74 | 75 | } // namespace Algorithms 76 | } // namespace Thea 77 | 78 | #endif 79 | -------------------------------------------------------------------------------- /Code/Source/Algorithms/BestFitEllipsoid3.hpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2009 12 | // 13 | //============================================================================ 14 | 15 | #ifndef __Thea_Algorithms_BestFitEllipsoid3_hpp__ 16 | #define __Thea_Algorithms_BestFitEllipsoid3_hpp__ 17 | 18 | #include "../Common.hpp" 19 | #include "../Array.hpp" 20 | #include "../Box3.hpp" 21 | 22 | namespace Thea { 23 | namespace Algorithms { 24 | 25 | /** Approximate best-fit ellipsoid. */ 26 | class THEA_API BestFitEllipsoid3 27 | { 28 | public: 29 | THEA_DECL_SMART_POINTERS(BestFitEllipsoid3) 30 | 31 | /** 32 | * Constructor. The optional argument (which may be ignored by the implementation) controls the approximation ratio 33 | * (1 + eps_) of the computed ellipsoid. A smaller value gives a better fit but may take longer to compute. 34 | */ 35 | BestFitEllipsoid3(Real eps_ = 0.05); 36 | 37 | /** Add a point to the set. */ 38 | void addPoint(Vector3 const & point); 39 | 40 | /** Remove all data and (lazily) set the ellipsoid to null. */ 41 | void clear(); 42 | 43 | /** Remove all cached data to free memory, but do not mark the ellipsoid for recomputation. */ 44 | void releaseMemoryWithoutUpdate(); 45 | 46 | /** 47 | * Get the axes of the ellipsoid. The lengths of the axes represent the shape of the ellipsoid. The axes will always be 48 | * returned in decreasing order of length, i.e. |axis0| >= |axis1| >= |axis2|. Also, 49 | * (axis0.cross(axis1)).normalized() == axis2.normalized(). 50 | */ 51 | void getAxes(Vector3 & axis0, Vector3 & axis1, Vector3 & axis2) const; 52 | 53 | /** Get the center of the ellipsoid. */ 54 | Vector3 const & getCenter() const; 55 | 56 | /** 57 | * Get a tight bounding box for the input data (not for the ellipsoid) oriented along the principal axes of the 58 | * ellipsoid. 59 | */ 60 | Box3 const & getOrientedBoundingBox() const; 61 | 62 | private: 63 | /** Recompute the best-fit ellipsoid. */ 64 | void update() const; 65 | 66 | Array points; 67 | Real eps; 68 | mutable Vector3 center, axis[3]; 69 | mutable Box3 obb; 70 | mutable bool updated; 71 | 72 | }; // class BestFitEllipsoid3 73 | 74 | } // namespace Algorithms 75 | } // namespace Thea 76 | 77 | #endif 78 | -------------------------------------------------------------------------------- /Code/Source/Algorithms/BestFitSphere3.hpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2013 12 | // 13 | //============================================================================ 14 | 15 | #ifndef __Thea_Algorithms_BestFitSphere3_hpp__ 16 | #define __Thea_Algorithms_BestFitSphere3_hpp__ 17 | 18 | #include "BestFitSphereN.hpp" 19 | 20 | namespace Thea { 21 | namespace Algorithms { 22 | 23 | /** Best-fit sphere in 3 dimensions. */ 24 | typedef BestFitSphereN<3, Real> BestFitSphere3; 25 | 26 | } // namespace Algorithms 27 | } // namespace Thea 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /Code/Source/Algorithms/BiasedNormalizedCuts.hpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2011 12 | // 13 | //============================================================================ 14 | 15 | #ifndef __Thea_Algorithms_BiasedNormalizedCuts_hpp__ 16 | #define __Thea_Algorithms_BiasedNormalizedCuts_hpp__ 17 | 18 | #include "../Common.hpp" 19 | #include "../CompressedSparseMatrix.hpp" 20 | #include "IEigenSolver.hpp" 21 | #include 22 | 23 | namespace Thea { 24 | namespace Algorithms { 25 | 26 | /** 27 | */ 28 | class THEA_API BiasedNormalizedCuts 29 | { 30 | public: 31 | template 32 | static void compute(MatrixT const & adjacency_matrix, Array const & vertices_of_interest, double correlation, 33 | Array & vertex_indicators) 34 | { 35 | } 36 | 37 | }; // class BiasedNormalizedCuts 38 | 39 | } // namespace Algorithms 40 | } // namespace Thea 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /Code/Source/Algorithms/BoundedTraitsN_Transform.hpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2009 12 | // 13 | //============================================================================ 14 | 15 | #ifndef __Thea_Algorithms_BoundedTraitsN_Transform_hpp__ 16 | #define __Thea_Algorithms_BoundedTraitsN_Transform_hpp__ 17 | 18 | #include "TransformedObject.hpp" 19 | 20 | namespace Thea { 21 | namespace Algorithms { 22 | 23 | template 24 | class IsBoundedN< TransformedObject, N > 25 | { 26 | public: 27 | static bool const value = IsBoundedN::value; 28 | }; 29 | 30 | template 31 | class /* THEA_API */ BoundedTraitsN< TransformedObject, N, ScalarT > 32 | { 33 | public: 34 | typedef TransformedObject TO; 35 | 36 | template static void getBounds(TO const & t, RangeT & bounds) 37 | { 38 | BoundedTraitsN::getBounds(t.getObject(), bounds); 39 | bounds = bounds.transformAndBound(t.getTransform()); 40 | } 41 | 42 | static Vector getCenter(TO const & t) 43 | { 44 | AxisAlignedBoxN bounds; 45 | getBounds(t, bounds); 46 | return bounds.getCenter(); 47 | } 48 | 49 | static ScalarT getHigh(TO const & t, intx coord) 50 | { 51 | AxisAlignedBoxN bounds; 52 | getBounds(t, bounds); 53 | return bounds.getHigh()[coord]; 54 | } 55 | 56 | static ScalarT getLow(TO const & t, intx coord) 57 | { 58 | AxisAlignedBoxN bounds; 59 | getBounds(t, bounds); 60 | return bounds.getLow()[coord]; 61 | } 62 | 63 | }; // class BoundedTraitsN 64 | 65 | } // namespace Algorithms 66 | } // namespace Thea 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /Code/Source/Algorithms/Filter.hpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2009 12 | // 13 | //============================================================================ 14 | 15 | #ifndef __Thea_Algorithms_Filter_hpp__ 16 | #define __Thea_Algorithms_Filter_hpp__ 17 | 18 | #include "../Common.hpp" 19 | 20 | namespace Thea { 21 | namespace Algorithms { 22 | 23 | /** 24 | * Interface for all single-object filters. A filter has an allows() function that takes an object argument and returns a 25 | * boolean value indicating whether the filter allows the object to pass through or not. 26 | */ 27 | template 28 | class Filter 29 | { 30 | public: 31 | THEA_DECL_SMART_POINTERS(Filter) 32 | 33 | /** Destructor. */ 34 | virtual ~Filter() {} 35 | 36 | /** 37 | * Check if the filter allows an object to pass through or not. 38 | * 39 | * @return True if the object \a t is allowed through, false if it is blocked. 40 | */ 41 | virtual bool allows(T const & t) const = 0; 42 | 43 | }; // class Filter 44 | 45 | /** A filter that allows everything to pass through. */ 46 | template 47 | class AlwaysPassFilter : public Filter 48 | { 49 | public: 50 | bool allows(T const & t) const { return true; } 51 | 52 | }; // class AlwaysPassFilter 53 | 54 | /** A filter that allows nothing to pass through. */ 55 | template 56 | class AlwaysBlockFilter : public Filter 57 | { 58 | public: 59 | bool allows(T const & t) const { return false; } 60 | 61 | }; // class AlwaysPassFilter 62 | 63 | /** 64 | * A compatibility functor that always returns true for any two objects. A compatibility functor has a 65 | * bool operator()(u, v) const function that returns true if the two objects u and v are compatible 66 | * with each other. 67 | */ 68 | class UniversalCompatibility 69 | { 70 | public: 71 | template bool operator()(U const & u, V const & v) const { return true; } 72 | 73 | }; // class UniversalCompatibility 74 | 75 | } // namespace Algorithms 76 | } // namespace Thea 77 | 78 | #endif 79 | -------------------------------------------------------------------------------- /Code/Source/Algorithms/FurthestPointSampling.hpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2018 12 | // 13 | //============================================================================ 14 | 15 | #ifndef __Thea_Algorithms_FurthestPointSampling_hpp__ 16 | #define __Thea_Algorithms_FurthestPointSampling_hpp__ 17 | 18 | #include "../Common.hpp" 19 | #include "../MatVec.hpp" 20 | 21 | namespace Thea { 22 | namespace Algorithms { 23 | 24 | /** 25 | * Subsample a set of 3D points to pick a subset of points distributed evenly, that is, neighboring points are (roughly) equally 26 | * spaced. The algorithm repeatedly picks the left-over point that is furthest from any of the previously selected ones. The 27 | * returned list of points has the property that any prefix of the list is also an evenly spaced set, making further subsampling 28 | * trivial. 29 | */ 30 | class FurthestPointSampling 31 | { 32 | public: 33 | /** 34 | * Samples approximately uniformly separated points from a larger set. The algorithm repeatedly picks the left-over point 35 | * that is furthest from any of the previously selected ones. The function returns an array of points ordered so that for 36 | * any K, the first K points form an approximately uniformly separated subsampling. 37 | * 38 | * @param num_orig_points The number of input points. 39 | * @param orig_points The set of input points. 40 | * @param num_desired_points The number of points to be subsampled. 41 | * @param selected_indices The indices of the subsampled points. This array must be preallocated to (at least) 42 | * \a num_desired_points elements. 43 | * @param dist_type The distance metric to be used. Currently only DistanceType::GEODESIC is supported. 44 | * @param verbose If true, prints progress messages. 45 | * 46 | * @return The number of subsampled points. A negative value, or a value less than \a num_desired_points in general, 47 | * indicates an error occurred. 48 | */ 49 | static intx subsample(intx num_orig_points, Vector3 const * orig_points, intx num_desired_points, intx * selected_indices, 50 | DistanceType dist_type = DistanceType::GEODESIC, bool verbose = false); 51 | 52 | }; // class FurthestPointSampling 53 | 54 | } // namespace Algorithms 55 | } // namespace Thea 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /Code/Source/Algorithms/GeodesicSphere3.hpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2017 12 | // 13 | //============================================================================ 14 | 15 | #ifndef __Thea_Algorithms_GeodesicSphere3_hpp__ 16 | #define __Thea_Algorithms_GeodesicSphere3_hpp__ 17 | 18 | #include "../Common.hpp" 19 | #include "../MatVec.hpp" 20 | 21 | namespace Thea { 22 | namespace Algorithms { 23 | 24 | /** 25 | * Generates a unit geodesic sphere, obtained by recursive subdivision of the faces of an icosahedron. This is useful for 26 | * getting a (nearly) uniformly separated distribution of points over the sphere. 27 | */ 28 | class THEA_API GeodesicSphere3 29 | { 30 | public: 31 | /** 32 | * Recursively subdivides the faces of the unit icosahedron, and projects each vertex to the surface of the unit sphere. 33 | * 34 | * @param num_subdivs The number of recursive subdivisions. 0 returns the icosahedron. 35 | * @param vertices Used to return the vertices of the geodesic sphere. 36 | * @param triangles If not null, used to return the faces of the sphere, as triplets of vertex indices. 37 | * 38 | * @return True on success, false on error. 39 | */ 40 | static bool compute(intx num_subdivs, Array & vertices, Array * triangles = nullptr); 41 | 42 | /** 43 | * Recursively subdivides a given set of triangles formed from vertices on the unit sphere, projecting each new vertex to 44 | * the surface of the sphere. This function is useful for generating only a part of the full geodesic sphere. 45 | * 46 | * @param num_subdivs The number of recursive subdivisions. 0 is a no-op. 47 | * @param vertices Used to pass the initial set of vertices, and to return the new vertices, pushed onto the end of the 48 | * list. 49 | * @param old_triangles The existing set of triangles to subdivide, as triplets of vertex indices. 50 | * @param new_triangles If not null, used to return the new faces, as triplets of vertex indices. 51 | * 52 | * @return True on success, false on error. 53 | */ 54 | static bool compute(intx num_subdivs, Array & vertices, Array const & old_triangles, 55 | Array * new_triangles = nullptr); 56 | 57 | }; // class GeodesicSphere3 58 | 59 | } // namespace Algorithms 60 | } // namespace Thea 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /Code/Source/Algorithms/IAnalyticD1ScalarFunction.hpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2011 12 | // 13 | //============================================================================ 14 | 15 | #ifndef __Thea_Algorithms_IAnalyticD1ScalarFunction_hpp__ 16 | #define __Thea_Algorithms_IAnalyticD1ScalarFunction_hpp__ 17 | 18 | #include "IScalarFunction.hpp" 19 | 20 | namespace Thea { 21 | namespace Algorithms { 22 | 23 | /** Interface for a function that maps each point in R^n to a real number and has an analytic first derivative (gradient). */ 24 | class THEA_API IAnalyticD1ScalarFunction : public virtual IScalarFunction 25 | { 26 | public: 27 | THEA_DECL_SMART_POINTERS(IAnalyticD1ScalarFunction) 28 | 29 | /** Compute the gradient of the function at a given point. Returns true on success, false on error. */ 30 | virtual bool THEA_ICALL gradientAt(float32 const * p, float32 * result) const = 0; 31 | 32 | /** Compute the gradient of the function at a given point. Returns true on success, false on error. */ 33 | virtual bool THEA_ICALL gradientAt(float64 const * p, float64 * result) const = 0; 34 | 35 | /** 36 | * If the function has an analytic second derivative, cast this object to the corresponding type. Returns null on failure. 37 | */ 38 | virtual IAnalyticD2ScalarFunction const * THEA_ICALL asAnalyticD2() const = 0; 39 | 40 | }; // class IAnalyticD1ScalarFunction 41 | 42 | } // namespace Algorithms 43 | } // namespace Thea 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /Code/Source/Algorithms/IAnalyticD2ScalarFunction.hpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2011 12 | // 13 | //============================================================================ 14 | 15 | #ifndef __Thea_Algorithms_IAnalyticD2ScalarFunction_hpp__ 16 | #define __Thea_Algorithms_IAnalyticD2ScalarFunction_hpp__ 17 | 18 | #include "../AddressableMatrix.hpp" 19 | #include "../IMatrix.hpp" 20 | #include "IAnalyticD1ScalarFunction.hpp" 21 | 22 | namespace Thea { 23 | namespace Algorithms { 24 | 25 | /** 26 | * Interface for a function that maps each point in R^n to a real number and has analytic first (gradient) and second (Hessian) 27 | * derivatives. 28 | */ 29 | class THEA_API IAnalyticD2ScalarFunction : public virtual IAnalyticD1ScalarFunction 30 | { 31 | public: 32 | THEA_DECL_SMART_POINTERS(IAnalyticD2ScalarFunction) 33 | 34 | /** Does the function have a sparse Hessian matrix? */ 35 | virtual bool THEA_ICALL hasSparseHessian() const = 0; 36 | 37 | /** Compute the Hessian of the function at a given point. Returns true on success, false on error. */ 38 | virtual void THEA_ICALL hessianAt(float32 const * p, IMatrix * result) const = 0; 39 | 40 | /** Compute the Hessian of the function at a given point. Returns true on success, false on error. */ 41 | virtual void THEA_ICALL hessianAt(float64 const * p, IMatrix * result) const = 0; 42 | 43 | }; // class IAnalyticD2ScalarFunction 44 | 45 | } // namespace Algorithms 46 | } // namespace Thea 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /Code/Source/Algorithms/IEigenSolver.cpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2009 12 | // 13 | //============================================================================ 14 | 15 | #include "IEigenSolver.hpp" 16 | 17 | namespace Thea { 18 | namespace Algorithms { 19 | 20 | IEigenSolverFactory * 21 | EigenSolverManager::getFactory(std::string const & type) 22 | { 23 | FactoryMap::const_iterator installed = installed_factories.find(toLower(type)); 24 | if (installed == installed_factories.end()) 25 | throw Error("No factory for eigensolvers of type '" + type + "' is installed"); 26 | 27 | return installed->second; 28 | } 29 | 30 | bool 31 | EigenSolverManager::installFactory(std::string const & type, IEigenSolverFactory * factory) 32 | { 33 | theaAssertM(factory, "EigenSolverManager: Null factory cannot be installed"); 34 | 35 | std::string type_lc = toLower(type); 36 | FactoryMap::const_iterator installed = installed_factories.find(type_lc); 37 | if (installed == installed_factories.end()) 38 | { 39 | installed_factories[type_lc] = factory; 40 | return true; 41 | } 42 | else 43 | return false; 44 | } 45 | 46 | void 47 | EigenSolverManager::uninstallFactory(std::string const & type) 48 | { 49 | installed_factories.erase(type); 50 | } 51 | 52 | } // namespace Algorithms 53 | } // namespace Thea 54 | -------------------------------------------------------------------------------- /Code/Source/Algorithms/ILinearSolver.cpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2009 12 | // 13 | //============================================================================ 14 | 15 | #include "ILinearSolver.hpp" 16 | 17 | namespace Thea { 18 | namespace Algorithms { 19 | 20 | ILinearSolverFactory * 21 | LinearSolverManager::getFactory(std::string const & type) 22 | { 23 | FactoryMap::const_iterator installed = installed_factories.find(toLower(type)); 24 | if (installed == installed_factories.end()) 25 | throw Error("No factory for linear solvers of type '" + type + "' is installed"); 26 | 27 | return installed->second; 28 | } 29 | 30 | bool 31 | LinearSolverManager::installFactory(std::string const & type, ILinearSolverFactory * factory) 32 | { 33 | theaAssertM(factory, "LinearSolverManager: Null factory cannot be installed"); 34 | 35 | std::string type_lc = toLower(type); 36 | FactoryMap::const_iterator installed = installed_factories.find(type_lc); 37 | if (installed == installed_factories.end()) 38 | { 39 | installed_factories[type_lc] = factory; 40 | return true; 41 | } 42 | else 43 | return false; 44 | } 45 | 46 | void 47 | LinearSolverManager::uninstallFactory(std::string const & type) 48 | { 49 | installed_factories.erase(type); 50 | } 51 | 52 | } // namespace Algorithms 53 | } // namespace Thea 54 | -------------------------------------------------------------------------------- /Code/Source/Algorithms/INumericalOptimizer.cpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2011 12 | // 13 | //============================================================================ 14 | 15 | #include "INumericalOptimizer.hpp" 16 | 17 | namespace Thea { 18 | namespace Algorithms { 19 | 20 | INumericalOptimizerFactory * 21 | NumericalOptimizerManager::getFactory(std::string const & type) 22 | { 23 | FactoryMap::const_iterator installed = installed_factories.find(toLower(type)); 24 | if (installed == installed_factories.end()) 25 | throw Error("No factory for numerical optimizers of type '" + type + "' is installed"); 26 | 27 | return installed->second; 28 | } 29 | 30 | bool 31 | NumericalOptimizerManager::installFactory(std::string const & type, INumericalOptimizerFactory * factory) 32 | { 33 | theaAssertM(factory, "NumericalOptimizerManager: Null factory cannot be installed"); 34 | 35 | std::string type_lc = toLower(type); 36 | FactoryMap::const_iterator installed = installed_factories.find(type_lc); 37 | if (installed == installed_factories.end()) 38 | { 39 | installed_factories[type_lc] = factory; 40 | return true; 41 | } 42 | else 43 | return false; 44 | } 45 | 46 | void 47 | NumericalOptimizerManager::uninstallFactory(std::string const & type) 48 | { 49 | installed_factories.erase(type); 50 | } 51 | 52 | } // namespace Algorithms 53 | } // namespace Thea 54 | -------------------------------------------------------------------------------- /Code/Source/Algorithms/IScalarConstraint.hpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2011 12 | // 13 | //============================================================================ 14 | 15 | #ifndef __Thea_Algorithms_IScalarConstraint_hpp__ 16 | #define __Thea_Algorithms_IScalarConstraint_hpp__ 17 | 18 | #include "../Common.hpp" 19 | #include "IScalarFunction.hpp" 20 | 21 | namespace Thea { 22 | namespace Algorithms { 23 | 24 | /** 25 | * Interface for an optimization constraint of the form f(x) op y, where x is a vector, y 26 | * is a scalar, f is a function, and op is a comparison operator. 27 | */ 28 | class IScalarConstraint 29 | { 30 | public: 31 | THEA_DECL_SMART_POINTERS(IScalarConstraint) 32 | 33 | /** Destructor. */ 34 | virtual ~IScalarConstraint() = 0; 35 | 36 | /** Get the function. */ 37 | virtual IScalarFunction const * THEA_ICALL getFunction() const = 0; 38 | 39 | /** Get the comparison operator, corresponding to a value of the CompareOp enum class. */ 40 | virtual int32 THEA_ICALL getCompareOp() const = 0; 41 | 42 | /** Get the right-hand side. */ 43 | virtual float64 THEA_ICALL getRhs() const = 0; 44 | 45 | }; // class IScalarConstraint 46 | 47 | inline IScalarConstraint::~IScalarConstraint() {} 48 | 49 | } // namespace Algorithms 50 | } // namespace Thea 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /Code/Source/Algorithms/IScalarFunction.hpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2011 12 | // 13 | //============================================================================ 14 | 15 | #ifndef __Thea_Algorithms_IScalarFunction_hpp__ 16 | #define __Thea_Algorithms_IScalarFunction_hpp__ 17 | 18 | #include "../Common.hpp" 19 | 20 | namespace Thea { 21 | namespace Algorithms { 22 | 23 | // Forward declarations 24 | class IAnalyticD1ScalarFunction; 25 | 26 | /** Interface for a function that maps each point in R^n to a real number. */ 27 | class THEA_API IScalarFunction 28 | { 29 | public: 30 | THEA_DECL_SMART_POINTERS(IScalarFunction) 31 | 32 | /** Destructor. */ 33 | virtual ~IScalarFunction() = 0; 34 | 35 | /** Get the number of dimensions of the function domain. */ 36 | virtual int64 THEA_ICALL dims() const; 37 | 38 | /** Compute the value of the function at a given point. */ 39 | virtual float64 THEA_ICALL valueAt(float32 const * p) const = 0; 40 | 41 | /** Compute the value of the function at a given point. */ 42 | virtual float64 THEA_ICALL valueAt(float64 const * p) const = 0; 43 | 44 | /** If the function has an analytic first derivative, cast this object to the corresponding type. */ 45 | virtual IAnalyticD1ScalarFunction const * THEA_ICALL asAnalyticD1() const = 0; 46 | 47 | }; // class IScalarFunction 48 | 49 | inline IScalarFunction::~IScalarFunction() {} 50 | 51 | } // namespace Algorithms 52 | } // namespace Thea 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /Code/Source/Algorithms/Metrics.hpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2009 12 | // 13 | //============================================================================ 14 | 15 | #ifndef __Thea_Algorithms_Metrics_hpp__ 16 | #define __Thea_Algorithms_Metrics_hpp__ 17 | 18 | #include "MetricL2.hpp" 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /Code/Source/Algorithms/PointPairs.hpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2009 12 | // 13 | //============================================================================ 14 | 15 | #ifndef __Thea_Algorithms_PointPairs_hpp__ 16 | #define __Thea_Algorithms_PointPairs_hpp__ 17 | 18 | #include "../Common.hpp" 19 | #include "../MatVec.hpp" 20 | #include 21 | 22 | namespace Thea { 23 | namespace Algorithms { 24 | 25 | /** A pair of points in 1-space (single-precision) */ 26 | typedef std::pair FloatPair; 27 | 28 | /** A pair of points in 1-space (double-precision) */ 29 | typedef std::pair DoublePair; 30 | 31 | /** A pair of points in 1-space (default precision) */ 32 | typedef std::pair RealPair; 33 | 34 | /** A pair of points in 2-space. */ 35 | typedef std::pair PointPair2; 36 | 37 | /** A pair of points in 3-space. */ 38 | typedef std::pair PointPair3; 39 | 40 | /** A pair of points in 4-space. */ 41 | typedef std::pair PointPair4; 42 | 43 | /** A pair of points in n-dimensional space. */ 44 | template 45 | class /* THEA_API */ PointPairN : public std::pair< Vector, Vector > 46 | { 47 | private: 48 | typedef std::pair< Vector, Vector > BaseType; 49 | 50 | public: 51 | /** Default constructor. */ 52 | PointPairN() : BaseType() {} 53 | 54 | /** Initializing constructor. */ 55 | PointPairN(Vector const & a, Vector const & b) : BaseType(a, b) {} 56 | 57 | }; // class PointPairN 58 | 59 | } // namespace Algorithms 60 | } // namespace Thea 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /Code/Source/Algorithms/SurfaceFeatures/Global/DistanceHistogram.cpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2015 12 | // 13 | //============================================================================ 14 | 15 | #include "DistanceHistogram.hpp" 16 | #include "../../../Math.hpp" 17 | #include "../../../Random.hpp" 18 | 19 | namespace Thea { 20 | namespace Algorithms { 21 | namespace SurfaceFeatures { 22 | namespace Global { 23 | 24 | DistanceHistogram::DistanceHistogram(PointSet3 const * surf_) 25 | : ldh(surf_) 26 | {} 27 | 28 | void 29 | DistanceHistogram::compute(Histogram & histogram, DistanceType dist_type, Real max_distance, Real pair_reduction_ratio) const 30 | { 31 | intx num_samples = getSurface()->numSamples(); 32 | intx num_distinct_unordered = (num_samples - 1) * num_samples; 33 | 34 | if (pair_reduction_ratio < 0) 35 | pair_reduction_ratio = (Real)std::min(0.5, 1000000.0 / num_distinct_unordered); // don't count (x, x) 36 | 37 | histogram.setZero(); // don't bother setting the range 38 | 39 | Real local_reduction_ratio = std::sqrt(pair_reduction_ratio); 40 | intx num_queries = Math::clamp((intx)std::ceil(local_reduction_ratio * num_samples), 0, num_samples - 1); 41 | if (num_queries <= 0) 42 | return; 43 | 44 | Array query_indices((size_t)num_queries); 45 | Random::common().sortedIntegers(0, (int32)num_samples - 1, (int32)num_queries, &query_indices[0]); 46 | 47 | Histogram local_histogram(histogram.numBins()); 48 | auto const & samples = getSurface()->getSamples(); 49 | for (size_t i = 0; i < query_indices.size(); ++i) 50 | { 51 | Vector3 const & p = samples[(size_t)query_indices[i]].getPosition(); 52 | ldh.compute(p, local_histogram, dist_type, max_distance, local_reduction_ratio); 53 | 54 | // Remove the zero distance from the query point to itself 55 | local_histogram.remove(0.0); 56 | 57 | if (i == 0) 58 | histogram.setRange(local_histogram.minValue(), local_histogram.maxValue()); 59 | 60 | histogram.insert(local_histogram); 61 | } 62 | } 63 | 64 | } // namespace Global 65 | } // namespace SurfaceFeatures 66 | } // namespace Algorithms 67 | } // namespace Thea 68 | -------------------------------------------------------------------------------- /Code/Source/Algorithms/SurfaceFeatures/Local/AverageDistance.hpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2016 12 | // 13 | //============================================================================ 14 | 15 | #ifndef __Thea_Algorithms_SurfaceFeatures_Local_AverageDistance_hpp__ 16 | #define __Thea_Algorithms_SurfaceFeatures_Local_AverageDistance_hpp__ 17 | 18 | #include "../../PointSet3.hpp" 19 | 20 | namespace Thea { 21 | namespace Algorithms { 22 | namespace SurfaceFeatures { 23 | namespace Local { 24 | 25 | /** Compute the average distance from a query point to other points on a shape. */ 26 | class AverageDistance 27 | { 28 | public: 29 | /** 30 | * Constructs the object to compute the histogram of distances to sample points on a given surface. The sampled surface must 31 | * persist as long as this object does. 32 | */ 33 | AverageDistance(PointSet3 const * surf_); 34 | 35 | /** Get the underlying point-sampled surface. */ 36 | PointSet3 const * getSurface() const { return surf; } 37 | 38 | /** 39 | * Compute the average distance from a query point to sample points on the shape. The returned distance is normalized by 40 | * dividing by the normalization scale, which is \a max_distance (if non-negative), else the shape's native scale. 41 | * 42 | * @param position The position of the query point. 43 | * @param dist_type The type of distance metric. 44 | * @param max_distance The distance to the furthest point to consider. A negative value indicates the 45 | * entire shape is to be considered (in which case \a max_distance is set to the shape scale specified in the 46 | * constructor). 47 | */ 48 | double compute(Vector3 const & position, DistanceType dist_type = DistanceType::EUCLIDEAN, Real max_distance = -1) const; 49 | 50 | private: 51 | PointSet3 const * surf; ///< The point-sampled surface. 52 | 53 | }; // class AverageDistance 54 | 55 | } // namespace Local 56 | } // namespace SurfaceFeatures 57 | } // namespace Algorithms 58 | } // namespace Thea 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /Code/Source/Algorithms/SurfaceFeatures/Local/LocalPca.cpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2014 12 | // 13 | //============================================================================ 14 | 15 | #include "LocalPca.hpp" 16 | #include "../../IntersectionTester.hpp" 17 | #include "../../PcaN.hpp" 18 | #include 19 | 20 | namespace Thea { 21 | namespace Algorithms { 22 | namespace SurfaceFeatures { 23 | namespace Local { 24 | 25 | LocalPca::LocalPca(PointSet3 const * surf_) 26 | : surf(surf_) 27 | { 28 | alwaysAssertM(surf_, "LocalPca: Cannot construct with a null surface"); 29 | } 30 | 31 | Vector3 32 | LocalPca::LocalPcaFunctor::getPcaFeatures(Vector3 * eigenvectors) const 33 | { 34 | Real eval[3]; 35 | Vector3 evec[3]; 36 | PcaN::compute(nbd_pts.begin(), nbd_pts.end(), eval, evec); // returns ordered by decreasing eigenvalue 37 | 38 | if (eigenvectors) 39 | { 40 | eigenvectors[0] = evec[0]; 41 | eigenvectors[1] = evec[1]; 42 | eigenvectors[2] = evec[2]; 43 | } 44 | 45 | return Vector3(eval[0], eval[1], eval[2]); 46 | } 47 | 48 | Vector3 49 | LocalPca::compute(Vector3 const & position, Vector3 * eigenvectors, Real nbd_radius) const 50 | { 51 | if (nbd_radius < 0) 52 | nbd_radius = 0.1f; 53 | 54 | nbd_radius *= surf->getScale(); 55 | 56 | Ball3 range(position, nbd_radius); 57 | func.reset(); 58 | surf->getBvh().processRange(range, std::ref(func)); 59 | 60 | return func.getPcaFeatures(eigenvectors); 61 | } 62 | 63 | } // namespace Local 64 | } // namespace SurfaceFeatures 65 | } // namespace Algorithms 66 | } // namespace Thea 67 | -------------------------------------------------------------------------------- /Code/Source/Algorithms/SurfaceFeatures/Local/RandomWalks.hpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2016 12 | // 13 | //============================================================================ 14 | 15 | #ifndef __Thea_Algorithms_SurfaceFeatures_Local_RandomWalks_hpp__ 16 | #define __Thea_Algorithms_SurfaceFeatures_Local_RandomWalks_hpp__ 17 | 18 | #include "../../PointSet3.hpp" 19 | 20 | namespace Thea { 21 | namespace Algorithms { 22 | namespace SurfaceFeatures { 23 | namespace Local { 24 | 25 | /** Compute the average offset, from the query position, after each step of an n-step random walk on a surface. */ 26 | class RandomWalks 27 | { 28 | public: 29 | /** 30 | * Constructs the object to compute random walk patterns on a given surface. The sampled surface must persist as long as 31 | * this object does. 32 | */ 33 | RandomWalks(PointSet3 const * surf_); 34 | 35 | /** Get the underlying point-sampled surface. */ 36 | PointSet3 const * getSurface() const { return surf; } 37 | 38 | /** 39 | * Compute the average offset, from the query position, after each step of an n-step random walk on the shape's sample 40 | * graph. 41 | * 42 | * @param position The position of the query point. 43 | * @param num_steps The number of random steps to take from the query point. 44 | * @param features Used to return the point features. Should be preallocated to \a num_steps * 3 entries. 45 | * @param num_walks The number of random walks over which to take averages. 46 | */ 47 | void compute(Vector3 const & position, intx num_steps, double * features, intx num_walks = -1) const; 48 | 49 | private: 50 | PointSet3 const * surf; ///< The point-sampled surface. 51 | 52 | }; // class RandomWalks 53 | 54 | } // namespace Local 55 | } // namespace SurfaceFeatures 56 | } // namespace Algorithms 57 | } // namespace Thea 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /Code/Source/Algorithms/TransformedObject.hpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2009 12 | // 13 | //============================================================================ 14 | 15 | #ifndef __Thea_Algorithms_TransformedObject_hpp__ 16 | #define __Thea_Algorithms_TransformedObject_hpp__ 17 | 18 | #include "../Common.hpp" 19 | 20 | namespace Thea { 21 | namespace Algorithms { 22 | 23 | /** 24 | * Wraps pointers to an object and an associated transformation. The pointer values will be dereferenced as necessary by the 25 | * get...() functions. The original data must persist until this class is destroyed. One should always check 26 | * the return value of the has...() function before calling the corresponding get...() functions. 27 | */ 28 | template 29 | class /* THEA_API */ TransformedObject 30 | { 31 | public: 32 | typedef ObjectT Object; ///< The type of wrapped object. 33 | typedef TransformT Transform; ///< The type of wrapped transformation. 34 | 35 | /** 36 | * Constructor. Both pointers are stored directly, so the original objects must persist as long as the TransformedObject is 37 | * being used. This is the preferred constructor for efficiency. 38 | */ 39 | explicit TransformedObject(Object const * obj_ = nullptr, Transform const * trans_ = nullptr) : obj(obj_), trans(trans_) {} 40 | 41 | /** Check if this class wraps an existing object or not. */ 42 | bool hasObject() const { return obj != nullptr; } 43 | 44 | /** Get the wrapped object. */ 45 | Object const & getObject() const { return *obj; } 46 | 47 | /** Check if this class wraps an existing transformation or not. */ 48 | bool hasTransform() const { return trans != nullptr; } 49 | 50 | /** Get the wrapped transformation. */ 51 | Transform const & getTransform() const { return *trans; } 52 | 53 | private: 54 | Object const * obj; 55 | Transform const * trans; 56 | 57 | }; // class TransformedObject 58 | 59 | /** Utility function to wrap an object-transformation pair. Allows the compiler to automatically infer template parameters. */ 60 | template 61 | TransformedObject 62 | makeTransformedObject(ObjectT const * obj, TransformT const * trans) 63 | { 64 | return TransformedObject(obj, trans); 65 | } 66 | 67 | } // namespace Algorithms 68 | } // namespace Thea 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /Code/Source/Algorithms/Zernike2.cpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2011 12 | // 13 | //============================================================================ 14 | 15 | #include "Zernike2.hpp" 16 | #include "../Math.hpp" 17 | 18 | namespace Thea { 19 | namespace Algorithms { 20 | 21 | Zernike2::Zernike2(Options const & opts_) 22 | : opts(opts_), lut_generated(false) 23 | { 24 | alwaysAssertM(opts.angular_steps > 0 && opts.radial_steps > 0 && opts.lut_radius > 0, 25 | "Zernike2: Lookup dimensions must be greater than zero"); 26 | } 27 | 28 | void 29 | Zernike2::generateBasisLUT() const 30 | { 31 | if (lut_generated) return; 32 | 33 | int lut_size = 2 * opts.lut_radius + 1; 34 | lut.resize(opts.angular_steps, opts.radial_steps, lut_size + 1, lut_size + 1); // one row/column of padding 35 | 36 | int max_radius = opts.lut_radius; 37 | double angle, temp, radius; 38 | 39 | for (int y = 0; y < lut_size; ++y) 40 | for (int x = 0; x < lut_size; ++x) 41 | { 42 | radius = std::sqrt((double)(Math::square(x - max_radius) + Math::square(y - max_radius))); 43 | 44 | if(radius < max_radius) 45 | { 46 | angle = std::atan2((double)(y - max_radius), (double)(x - max_radius)); 47 | 48 | for (int p = 0; p < opts.angular_steps; ++p) 49 | for (int r = 0; r < opts.radial_steps; ++r) 50 | { 51 | temp = std::cos(radius * Math::pi() * r / max_radius); 52 | lut(p, r, x, y) = temp * std::complex(std::cos(angle * p), std::sin(angle * p)); 53 | } 54 | } 55 | else 56 | { 57 | for (int p = 0; p < opts.angular_steps; ++p) 58 | for (int r = 0; r < opts.radial_steps; ++r) 59 | lut(p, r, x, y) = std::complex(0.0, 0.0); 60 | } 61 | } 62 | 63 | // Add some padding in case we index beyond the border 64 | for (int p = 0; p < opts.angular_steps; ++p) 65 | for (int r = 0; r < opts.radial_steps; ++r) 66 | for (int i = 0; i <= lut_size; ++i) 67 | lut(p, r, i, lut_size) = lut(p, r, lut_size, i) = std::complex(0.0, 0.0); 68 | 69 | lut_generated = true; 70 | } 71 | 72 | } // namespace Algorithms 73 | } // namespace Thea 74 | -------------------------------------------------------------------------------- /Code/Source/Array.hpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2011 12 | // 13 | //============================================================================ 14 | 15 | #ifndef __Thea_Array_hpp__ 16 | #define __Thea_Array_hpp__ 17 | 18 | #include "Platform.hpp" 19 | #include "AlignedAllocator.hpp" 20 | #include 21 | 22 | namespace Thea { 23 | 24 | /** Dynamically resizable array. */ 25 | template < typename T, typename Alloc = std::allocator > using Array = std::vector; 26 | 27 | /** Dynamically resizable array with aligned memory allocation. */ 28 | template < typename T, size_t N = 16 > using AlignedArray = std::vector< T, AlignedAllocator >; 29 | 30 | } // namespace Thea 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /Code/Source/AttributedObject.hpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2009 12 | // 13 | //============================================================================ 14 | 15 | #ifndef __Thea_AttributedObject_hpp__ 16 | #define __Thea_AttributedObject_hpp__ 17 | 18 | #include "Common.hpp" 19 | 20 | namespace Thea { 21 | 22 | /** An object with an attached attribute (which must be default-constructible). */ 23 | template 24 | class /* THEA_API */ AttributedObject 25 | { 26 | public: 27 | typedef AttributeType Attribute; 28 | 29 | /** Default constructor. */ 30 | AttributedObject() {} 31 | 32 | /** Constructor. */ 33 | AttributedObject(Attribute const & attrib_) : attrib(attrib_) {} 34 | 35 | /** Get the attribute of the object. */ 36 | Attribute const & attr() const { return attrib; } 37 | 38 | /** Get the attribute of the object. */ 39 | Attribute & attr() { return attrib; } 40 | 41 | /** Set the attribute of the object. */ 42 | void setAttr(Attribute const & attrib_) { attrib = attrib_; } 43 | 44 | private: 45 | Attribute attrib; 46 | 47 | }; // class AttributedObject 48 | 49 | /** A completely empty attribute. */ 50 | struct THEA_API NullAttribute {}; 51 | 52 | } // namespace Thea 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /Code/Source/Ball3.hpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2009 12 | // 13 | //============================================================================ 14 | 15 | #ifndef __Thea_Ball3_hpp__ 16 | #define __Thea_Ball3_hpp__ 17 | 18 | #include "Common.hpp" 19 | #include "BallN.hpp" 20 | 21 | namespace Thea { 22 | 23 | #ifdef THEA_EXPORT_INSTANTIATION 24 | template class THEA_API BallN<3, Real>; 25 | #endif 26 | 27 | /** The default ball class in real 3-space. */ 28 | typedef BallN<3, Real> Ball3; 29 | 30 | } // namespace Thea 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /Code/Source/Box3.hpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2009 12 | // 13 | //============================================================================ 14 | 15 | #ifndef __Thea_Box3_hpp__ 16 | #define __Thea_Box3_hpp__ 17 | 18 | #include "Common.hpp" 19 | #include "BoxN.hpp" 20 | 21 | namespace Thea { 22 | 23 | #ifdef THEA_EXPORT_INSTANTIATION 24 | template class THEA_API BoxN<3, Real>; 25 | #endif 26 | 27 | // The default oriented box class in 3-dimensional real space. 28 | typedef BoxN<3, Real> Box3; 29 | 30 | } // namespace Thea 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /Code/Source/Codec.cpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2020 12 | // 13 | //============================================================================ 14 | 15 | #include "Codec.hpp" 16 | #include "Iostream.hpp" 17 | 18 | namespace Thea { 19 | 20 | namespace CodecInternal { 21 | 22 | intx const RESERVED_LENGTH = 8; // additional space allocated but currently unused in a serialized BlockHeader 23 | 24 | } // namespace CodecInternal 25 | 26 | Codec::BlockHeader::BlockHeader(BinaryInputStream & in) 27 | : magic(zeroMagic()), data_size(0), header_pos(0) 28 | { 29 | read(in); 30 | } 31 | 32 | void 33 | Codec::BlockHeader::read(BinaryInputStream & in) 34 | { 35 | BinaryInputStream::EndiannessScope scope(in, Endianness::LITTLE); 36 | in.readBytes(MAGIC_LENGTH, magic.data()); 37 | data_size = in.readUInt64(); 38 | in.skip(CodecInternal::RESERVED_LENGTH); 39 | } 40 | 41 | void 42 | Codec::BlockHeader::write(BinaryOutputStream & out) const 43 | { 44 | BinaryOutputStream::EndiannessScope scope(out, Endianness::LITTLE); // headers are always little endian 45 | out.writeBytes(MAGIC_LENGTH, magic.data()); 46 | out.writeUInt64(data_size); 47 | 48 | static uint8 const RESERVED_ZEROES[CodecInternal::RESERVED_LENGTH] = {}; // zero initialization 49 | out.writeBytes(CodecInternal::RESERVED_LENGTH, RESERVED_ZEROES); 50 | } 51 | 52 | int64 53 | Codec::BlockHeader::markAndSkip(BinaryOutputStream & out) 54 | { 55 | header_pos = out.getPosition(); 56 | out.skip(SERIALIZED_LENGTH); 57 | return header_pos; 58 | } 59 | 60 | void 61 | Codec::BlockHeader::calcAndWrite(BinaryOutputStream & out) 62 | { 63 | int64 final_pos = out.getPosition(); 64 | data_size = (uint64)(final_pos - header_pos - SERIALIZED_LENGTH); 65 | out.setPosition(header_pos); 66 | write(out); 67 | out.setPosition(final_pos); 68 | } 69 | 70 | } // namespace Thea 71 | -------------------------------------------------------------------------------- /Code/Source/ColorL.cpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2013 12 | // 13 | //============================================================================ 14 | 15 | /* 16 | ORIGINAL HEADER 17 | 18 | @file ColorL.cpp 19 | 20 | Color class. 21 | 22 | @author Morgan McGuire, http://graphics.cs.williams.edu 23 | 24 | @created 2007-01-30 25 | @edited 2009-03-27 26 | */ 27 | 28 | #include "ColorL.hpp" 29 | #include "ColorL8.hpp" 30 | #include "ColorRgba.hpp" 31 | 32 | namespace Thea { 33 | 34 | ColorL::ColorL(ColorL8 const & other) 35 | : val(other.value() / 255.0f) 36 | {} 37 | 38 | ColorL::ColorL(ColorRgba const & other) 39 | : val(0.299f * other.r() + 0.587f * other.g() + 0.114f * other.b()) 40 | {} 41 | 42 | std::string 43 | ColorL::toString() const 44 | { 45 | return format("L(%g)", val); 46 | } 47 | 48 | } // namespace Thea 49 | -------------------------------------------------------------------------------- /Code/Source/ColorL8.cpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2013 12 | // 13 | //============================================================================ 14 | 15 | /* 16 | ORIGINAL HEADER 17 | 18 | @file ColorL8.cpp 19 | 20 | @author Morgan McGuire, http://graphics.cs.williams.edu 21 | 22 | @created 2007-01-30 23 | @edited 2007-01-30 24 | */ 25 | 26 | #include "ColorL8.hpp" 27 | #include "ColorL.hpp" 28 | #include "ColorRgba.hpp" 29 | #include "Math.hpp" 30 | 31 | namespace Thea { 32 | 33 | ColorL8::ColorL8(ColorL const & c) 34 | : val(Math::clamp((uint8)std::round(c.value() * 255), (uint8)0, (uint8)255)) 35 | {} 36 | 37 | ColorL::ColorL(ColorRgba const & other) 38 | { 39 | Real lum = 0.299f * other.r() + 0.587f * other.g() + 0.114f * other.b(); 40 | val = Math::clamp((uint8)std::round(lum * 255), (uint8)0, (uint8)255); 41 | } 42 | 43 | std::string 44 | ColorL8::toString() const 45 | { 46 | return format("L8(%d)", (int)val); 47 | } 48 | 49 | } // namespace Thea 50 | -------------------------------------------------------------------------------- /Code/Source/ColorRgb8.cpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2013 12 | // 13 | //============================================================================ 14 | 15 | /* 16 | ORIGINAL HEADER 17 | 18 | @file Color3uint8.cpp 19 | 20 | @author Morgan McGuire, http://graphics.cs.williams.edu 21 | 22 | @created 2003-04-07 23 | @edited 2006-01-07 24 | */ 25 | 26 | #include "ColorRgb8.hpp" 27 | #include "ColorRgb.hpp" 28 | #include "ColorRgba.hpp" 29 | #include "Math.hpp" 30 | 31 | namespace Thea { 32 | 33 | ColorRgb8::ColorRgb8(ColorRgb const & src) 34 | { 35 | c[0] = (uint8)Math::clamp((Real)std::round(src.r() * 255), (Real)0, (Real)255); 36 | c[1] = (uint8)Math::clamp((Real)std::round(src.g() * 255), (Real)0, (Real)255); 37 | c[2] = (uint8)Math::clamp((Real)std::round(src.b() * 255), (Real)0, (Real)255); 38 | } 39 | 40 | ColorRgb8::ColorRgb8(ColorRgba const & src) 41 | { 42 | *this = ColorRgb8(src.rgb()); 43 | } 44 | 45 | ColorRgb8 46 | ColorRgb8::fromARGB(uint32 argb) 47 | { 48 | return ColorRgb8((uint8)((argb >> 16) & 0xFF), 49 | (uint8)((argb >> 8) & 0xFF), 50 | (uint8)( argb & 0xFF)); 51 | } 52 | 53 | std::string 54 | ColorRgb8::toString() const 55 | { 56 | return format("RGB(%d, %d, %d)", (int)c[0], (int)c[1], (int)c[2]); 57 | } 58 | 59 | } // namespace Thea 60 | -------------------------------------------------------------------------------- /Code/Source/ColorRgba8.cpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2013 12 | // 13 | //============================================================================ 14 | 15 | /* 16 | ORIGINAL HEADER 17 | 18 | @file ColorRgba8.cpp 19 | 20 | @author Morgan McGuire, http://graphics.cs.williams.edu 21 | 22 | @created 2003-04-07 23 | @edited 2006-01-07 24 | */ 25 | 26 | #include "ColorRgba8.hpp" 27 | #include "ColorRgba.hpp" 28 | #include "Math.hpp" 29 | 30 | namespace Thea { 31 | 32 | ColorRgba8::ColorRgba8(ColorRgba const & src) 33 | { 34 | c[0] = (uint8)Math::clamp((Real)std::round(src.r() * 255), (Real)0, (Real)255); 35 | c[1] = (uint8)Math::clamp((Real)std::round(src.g() * 255), (Real)0, (Real)255); 36 | c[2] = (uint8)Math::clamp((Real)std::round(src.b() * 255), (Real)0, (Real)255); 37 | c[3] = (uint8)Math::clamp((Real)std::round(src.a() * 255), (Real)0, (Real)255); 38 | } 39 | 40 | ColorRgba8 41 | ColorRgba8::fromARGB(uint32 argb) 42 | { 43 | return ColorRgba8((uint8)((argb >> 16) & 0xFF), 44 | (uint8)((argb >> 8) & 0xFF), 45 | (uint8)( argb & 0xFF), 46 | (uint8)((argb >> 24) & 0xFF)); 47 | } 48 | 49 | std::string 50 | ColorRgba8::toString() const 51 | { 52 | return format("RGBA(%d, %d, %d, %d)", (int)c[0], (int)c[1], (int)c[2], (int)c[3]); 53 | } 54 | 55 | } // namespace Thea 56 | -------------------------------------------------------------------------------- /Code/Source/Colors.hpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2013 12 | // 13 | //============================================================================ 14 | 15 | #ifndef __Thea_Colors_hpp__ 16 | #define __Thea_Colors_hpp__ 17 | 18 | #include "ColorL.hpp" 19 | #include "ColorL8.hpp" 20 | #include "ColorRgb.hpp" 21 | #include "ColorRgb8.hpp" 22 | #include "ColorRgba.hpp" 23 | #include "ColorRgba8.hpp" 24 | 25 | namespace Thea { 26 | 27 | /** 28 | * 16-bit luminance value. 29 | * 30 | * @todo Replace this with a proper class. 31 | */ 32 | typedef uint16 ColorL16; 33 | 34 | } // namespace Thea 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /Code/Source/Cone3.hpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2021 12 | // 13 | //============================================================================ 14 | 15 | #ifndef __Thea_Cone3_hpp__ 16 | #define __Thea_Cone3_hpp__ 17 | 18 | #include "Common.hpp" 19 | #include "ConeN.hpp" 20 | 21 | namespace Thea { 22 | 23 | #ifdef THEA_EXPORT_INSTANTIATION 24 | template class THEA_API ConeN<3, Real>; 25 | #endif 26 | 27 | /** The default cone class in real 3-space. */ 28 | typedef ConeN<3, Real> Cone3; 29 | 30 | } // namespace Thea 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /Code/Source/CoordinateFrame2.hpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2009 12 | // 13 | //============================================================================ 14 | 15 | #ifndef __Thea_CoordinateFrame2_hpp__ 16 | #define __Thea_CoordinateFrame2_hpp__ 17 | 18 | #include "Common.hpp" 19 | #include "CoordinateFrameN.hpp" 20 | 21 | namespace Thea { 22 | 23 | /** A coordinate frame in 2-space, defined by two orthonormal vectors. */ 24 | template 25 | class /* THEA_API */ CoordinateFrameN<2, T> : public Internal::CoordinateFrameNBase<2, T> 26 | { 27 | private: 28 | typedef Internal::CoordinateFrameNBase<2, T> BaseT; 29 | 30 | public: 31 | typedef typename BaseT::RigidTransformT RigidTransformT; 32 | typedef typename BaseT::VectorT VectorT; 33 | typedef typename BaseT::MatrixT MatrixT; 34 | 35 | /** Default constructor. Constructs the identity frame. */ 36 | CoordinateFrameN() {} 37 | 38 | /** Construct from a rigid transform. */ 39 | CoordinateFrameN(RigidTransformT const & src) : BaseT(src) {} 40 | 41 | /** Construct from a viewing position (\a eye) and a look-at position (\a center). */ 42 | CoordinateFrameN(VectorT const & eye, VectorT const & center) 43 | { 44 | set(eye, center); 45 | } 46 | 47 | /** Initialize from a viewing position (\a eye) and a look-at position (\a center). */ 48 | void set(VectorT const & eye, VectorT const & center) 49 | { 50 | VectorT f = (center - eye).normalized(); 51 | this->_setRotation((MatrixT() << f[0], -f[1], f[1], f[0]).finished()); 52 | this->setTranslation(eye); 53 | } 54 | 55 | private: 56 | // Hide these functions from the default interface 57 | static RigidTransformT rotation(Real radians) { return RigidTransformT(); } 58 | 59 | }; // class CoordinateFrameN<2, T> 60 | 61 | #ifdef THEA_EXPORT_INSTANTIATION 62 | template class THEA_API CoordinateFrameN<2, Real>; 63 | #endif 64 | 65 | /** The default coordinate frame class in real 2-space. */ 66 | typedef CoordinateFrameN<2, Real> CoordinateFrame2; 67 | 68 | } // namespace Thea 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /Code/Source/Crypto.hpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2013 12 | // 13 | //============================================================================ 14 | 15 | #ifndef __Thea_Crypto_hpp__ 16 | #define __Thea_Crypto_hpp__ 17 | 18 | #include "Common.hpp" 19 | 20 | namespace Thea { 21 | 22 | /** Cryptographic functions. */ 23 | class THEA_API Crypto 24 | { 25 | public: 26 | /** Get the CRC32 hash of a sequence of bytes. */ 27 | static uint32 crc32(void const * byte, size_t num_bytes); 28 | 29 | }; // class Crypto 30 | 31 | } // namespace Thea 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /Code/Source/Cylinder3.hpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2021 12 | // 13 | //============================================================================ 14 | 15 | #ifndef __Thea_Cylinder3_hpp__ 16 | #define __Thea_Cylinder3_hpp__ 17 | 18 | #include "Common.hpp" 19 | #include "CylinderN.hpp" 20 | 21 | namespace Thea { 22 | 23 | #ifdef THEA_EXPORT_INSTANTIATION 24 | template class THEA_API CylinderN<3, Real>; 25 | #endif 26 | 27 | /** The default cylinder class in real 3-space. */ 28 | typedef CylinderN<3, Real> Cylinder3; 29 | 30 | } // namespace Thea 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /Code/Source/Deque.hpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2011 12 | // 13 | //============================================================================ 14 | 15 | #ifndef __Thea_Deque_hpp__ 16 | #define __Thea_Deque_hpp__ 17 | 18 | #include "Platform.hpp" 19 | #include 20 | 21 | /** Double-ended queue. */ 22 | template < typename T, typename Alloc = std::allocator > using Deque = std::deque; 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /Code/Source/Error.hpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2009 12 | // 13 | //============================================================================ 14 | 15 | #ifndef __Thea_Error_hpp__ 16 | #define __Thea_Error_hpp__ 17 | 18 | #include "Platform.hpp" 19 | #include "BasicStringAlg.hpp" 20 | #include "Log.hpp" 21 | #include 22 | #include 23 | 24 | namespace Thea { 25 | 26 | /** An error class. */ 27 | typedef std::runtime_error Error; 28 | 29 | /** A fatal error class. Doesn't derive from std::exception so that it is not caught by one of the usual handlers. */ 30 | class THEA_API FatalError 31 | { 32 | public: 33 | /** Constructor. */ 34 | FatalError(std::string const & message_) : message(message_) {} 35 | 36 | /** Destructor. */ 37 | ~FatalError() {} 38 | 39 | /** Assignment operator. */ 40 | FatalError & operator=(FatalError const & src) { message = src.message; return *this; } 41 | 42 | /** The error message. */ 43 | char const * what() const { return message.c_str(); } 44 | 45 | private: 46 | std::string message; 47 | 48 | }; // class FatalError 49 | 50 | /** 51 | * Generate a standard series of catch blocks that print a message on the specified stream and then perform an action. A fatal 52 | * error always generates a standard message on the error stream and the exception is rethrown, regardless of the specified 53 | * stream, message and action. 54 | * 55 | * Example: 56 | *
57 |  *   THEA_CATCH(continue;, WARNING, "A non-fatal error occurred in iteration %d", i)
58 |  * 
59 | */ 60 | #define THEA_CATCH(action__, stream__, message__, ...) \ 61 | catch (FatalError const & e__) \ 62 | { \ 63 | THEA_ERROR << format( "A fatal error occurred (%s)", e__.what() ); \ 64 | throw; \ 65 | } \ 66 | catch (std::exception const & e__) \ 67 | { \ 68 | THEA_ ## stream__ << format( (message__ + std::string(" (%s)")).c_str(), __VA_ARGS__, e__.what() ); \ 69 | action__ \ 70 | } \ 71 | catch (std::string const & e__) \ 72 | { \ 73 | THEA_ ## stream__ << format( (message__ + std::string(" (%s)")).c_str(), __VA_ARGS__, e__.c_str() ); \ 74 | action__ \ 75 | } \ 76 | catch (char const * e__) \ 77 | { \ 78 | THEA_ ## stream__ << format( (message__ + std::string(" (%s)")).c_str(), __VA_ARGS__, e__ ); \ 79 | action__ \ 80 | } \ 81 | catch (...) \ 82 | { \ 83 | THEA_ ## stream__ << format( (message__ + std::string(" (Unknown error)")).c_str(), __VA_ARGS__ ); \ 84 | action__ \ 85 | } 86 | 87 | } // namespace Thea 88 | 89 | #endif 90 | -------------------------------------------------------------------------------- /Code/Source/Graphics/DefaultMeshCodecs.hpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2009 12 | // 13 | //============================================================================ 14 | 15 | #ifndef __Thea_Graphics_DefaultMeshCodecs_hpp__ 16 | #define __Thea_Graphics_DefaultMeshCodecs_hpp__ 17 | 18 | #include "MeshCodec3ds.hpp" 19 | #include "MeshCodecObj.hpp" 20 | #include "MeshCodecOff.hpp" 21 | #include "MeshCodecPly.hpp" 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /Code/Source/Graphics/EdgeWelder.hpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2009 12 | // 13 | //============================================================================ 14 | 15 | #ifndef __Thea_Graphics_EdgeWelder_hpp__ 16 | #define __Thea_Graphics_EdgeWelder_hpp__ 17 | 18 | #include "../Common.hpp" 19 | #include "../MatVec.hpp" 20 | #include "../Noncopyable.hpp" 21 | 22 | namespace Thea { 23 | namespace Graphics { 24 | 25 | // Forward declaration 26 | class EdgeWelderImpl; 27 | 28 | /** 29 | * Maintains a set of edges, with associated positions, without duplication. Two edges are considered identical if both pairs of 30 | * corresponding endpoints are approximately co-located. 31 | */ 32 | class THEA_API EdgeWelder : private Noncopyable 33 | { 34 | public: 35 | /** 36 | * Constructor. Two edges are considered identical if both pairs of corresponding endpoints are separated by at most the 37 | * welding radius. 38 | */ 39 | EdgeWelder(Real weld_radius); 40 | 41 | /** Destructor. */ 42 | ~EdgeWelder(); 43 | 44 | /** Add an edge to the set, unless a coincident edge already exists. */ 45 | void addEdge(void * edge, Vector3 const & e0, Vector3 const & e1); 46 | 47 | /** If a directed edge with the specified endpoints exists, return it, else return null. */ 48 | void * getDirectedEdge(Vector3 const & e0, Vector3 const & e1) const; 49 | 50 | /** If an undirected edge with the specified endpoints exists, return it, else return null. */ 51 | void * getUndirectedEdge(Vector3 const & e0, Vector3 const & e1) const; 52 | 53 | private: 54 | EdgeWelderImpl * impl; 55 | 56 | }; // class EdgeWelder 57 | 58 | } // namespace Graphics 59 | } // namespace Thea 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /Code/Source/Graphics/IBufferPool.hpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2009 12 | // 13 | //============================================================================ 14 | 15 | #ifndef __Thea_Graphics_IBufferPool_hpp__ 16 | #define __Thea_Graphics_IBufferPool_hpp__ 17 | 18 | #include "../Common.hpp" 19 | #include "../NamedObject.hpp" 20 | 21 | namespace Thea { 22 | namespace Graphics { 23 | 24 | // Forward declarations 25 | class IBuffer; 26 | 27 | /** 28 | * Interface for a storage area in CPU or GPU memory that can store one or more graphics buffers. 29 | * 30 | * @see IBuffer 31 | */ 32 | class THEA_API IBufferPool : public virtual INamedObject 33 | { 34 | public: 35 | /** How the storage will be used (enum class). */ 36 | struct THEA_API Usage 37 | { 38 | /** Supported values. */ 39 | enum Value 40 | { 41 | WRITE_EVERY_FRAME, ///< The pool will be written to frequently. 42 | WRITE_OCCASIONALLY, ///< The pool will be written to occasionally. 43 | WRITE_ONCE ///< The pool will be written to at most once. 44 | }; 45 | 46 | THEA_ENUM_CLASS_BODY(Usage) 47 | }; 48 | 49 | /** Destructor. Automatically destroys all associated buffers. */ 50 | virtual ~IBufferPool() = 0; 51 | 52 | /** 53 | * Destroy all buffers allocated in this pool. Don't try to dereference pointers to previously allocated buffers after 54 | * calling this function! 55 | * 56 | * @return True on success, false on error. 57 | */ 58 | virtual int8 THEA_ICALL reset() = 0; 59 | 60 | /** Get the total capacity of the area in bytes. */ 61 | virtual int64 THEA_ICALL getCapacity() const = 0; 62 | 63 | /** Get the number of bytes already allocated. */ 64 | virtual int64 THEA_ICALL getAllocatedSize() const = 0; 65 | 66 | /** Get the number of available bytes. */ 67 | virtual int64 THEA_ICALL getAvailableSize() const = 0; 68 | 69 | /** Check if the area is stored in GPU memory or not. */ 70 | virtual int8 THEA_ICALL inGpuMemory() const = 0; 71 | 72 | /** 73 | * Create a buffer with a specified capacity in bytes. The buffer must be destroyed with destroyBuffer(). It will be 74 | * automatically destroyed when the IBufferPool is destroyed or reset(). 75 | */ 76 | virtual IBuffer * THEA_ICALL createBuffer(int64 num_bytes) = 0; 77 | 78 | /** 79 | * Destroy a buffer. The buffer must have been created with createBuffer(). 80 | * 81 | * @return True on success, false on error. 82 | */ 83 | virtual int8 THEA_ICALL destroyBuffer(IBuffer * buf) = 0; 84 | 85 | }; // class IBufferPool 86 | 87 | inline IBufferPool::~IBufferPool() {} 88 | 89 | } // namespace Graphics 90 | } // namespace Thea 91 | 92 | #endif 93 | -------------------------------------------------------------------------------- /Code/Source/Graphics/IDrawable.hpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2009 12 | // 13 | //============================================================================ 14 | 15 | #ifndef __Thea_Graphics_IDrawable_hpp__ 16 | #define __Thea_Graphics_IDrawable_hpp__ 17 | 18 | #include "../Common.hpp" 19 | #include "RenderOptions.hpp" 20 | #include "IRenderSystem.hpp" 21 | 22 | namespace Thea { 23 | 24 | /** %Graphics functionality. */ 25 | namespace Graphics { 26 | 27 | /** Interface for objects that can be displayed onscreen. */ 28 | class THEA_API IDrawable 29 | { 30 | public: 31 | THEA_DECL_SMART_POINTERS(IDrawable) 32 | 33 | /** Destructor. */ 34 | virtual ~IDrawable() = 0; 35 | 36 | /** Draw the object using the specified options via the specified rendering system. */ 37 | virtual int8 THEA_ICALL draw(IRenderSystem * render_system, IRenderOptions const * options = nullptr) const = 0; 38 | 39 | }; // class IDrawable 40 | 41 | // Pure virtual destructor should have a body 42 | // http://www.linuxtopia.org/online_books/programming_books/thinking_in_c++/Chapter15_024.html 43 | inline IDrawable::~IDrawable() {} 44 | 45 | } // namespace Graphics 46 | } // namespace Thea 47 | 48 | THEA_DECL_EXTERN_SMART_POINTERS(Thea::Graphics::IDrawable) 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /Code/Source/Graphics/IMesh.hpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2019 12 | // 13 | //============================================================================ 14 | 15 | #ifndef __Thea_Graphics_IMesh_hpp__ 16 | #define __Thea_Graphics_IMesh_hpp__ 17 | 18 | #include "../Common.hpp" 19 | #include "../IDenseMatrix.hpp" 20 | #include "../NamedObject.hpp" 21 | #include "IDrawable.hpp" 22 | 23 | namespace Thea { 24 | namespace Graphics { 25 | 26 | /** A minimalistic abstract base class for passing polygon mesh data across shared library boundaries. */ 27 | class IMesh : public virtual INamedObject, public virtual IDrawable 28 | { 29 | public: 30 | THEA_DECL_SMART_POINTERS(IMesh) 31 | 32 | /** 33 | * Get the vertices of the mesh, as a dense 3xN column-major matrix. Each column of the matrix is the (x, y, z) coordinate 34 | * triplet of a vertex. The function is guaranteed to return a non-null matrix, even if it has 0 columns. 35 | * 36 | * @note This function is safe to call across a shared library boundary only if the Real type has a consistent size on both 37 | * sides of the boundary. 38 | */ 39 | virtual IDenseMatrix const * THEA_ICALL getVertexMatrix() const = 0; 40 | 41 | /** 42 | * Get the triangles of the mesh, as a dense 3xN column-major matrix. Each column of the matrix is the set of indices of a 43 | * triangle's vertices. The function is guaranteed to return a non-null matrix, even if it has 0 columns. 44 | */ 45 | virtual IDenseMatrix const * THEA_ICALL getTriangleMatrix() const = 0; 46 | 47 | /** 48 | * Get the quads of the mesh, as a dense 4xN column-major matrix. Each column of the matrix is the set of indices of a 49 | * quad's vertices. The function is guaranteed to return a non-null matrix, even if it has 0 columns. 50 | */ 51 | virtual IDenseMatrix const * THEA_ICALL getQuadMatrix() const = 0; 52 | 53 | }; // class IMesh 54 | 55 | } // namespace Graphics 56 | } // namespace Thea 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /Code/Source/Graphics/IRenderSystem.cpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2009 12 | // 13 | //============================================================================ 14 | 15 | #include "IRenderSystem.hpp" 16 | 17 | namespace Thea { 18 | namespace Graphics { 19 | 20 | IRenderSystemFactory * 21 | RenderSystemManager::getFactory(std::string const & type) 22 | { 23 | FactoryMap::const_iterator installed = installed_factories.find(toLower(type)); 24 | if (installed == installed_factories.end()) 25 | throw Error("No factory for rendersystems of type '" + type + "' is installed"); 26 | 27 | return installed->second; 28 | } 29 | 30 | bool 31 | RenderSystemManager::installFactory(std::string const & type, IRenderSystemFactory * factory) 32 | { 33 | theaAssertM(factory, "RenderSystemManager: Null factory cannot be installed"); 34 | 35 | std::string type_lc = toLower(type); 36 | FactoryMap::const_iterator installed = installed_factories.find(type_lc); 37 | if (installed == installed_factories.end()) 38 | { 39 | installed_factories[type_lc] = factory; 40 | return true; 41 | } 42 | else 43 | return false; 44 | } 45 | 46 | void 47 | RenderSystemManager::uninstallFactory(std::string const & type) 48 | { 49 | installed_factories.erase(type); 50 | } 51 | 52 | } // namespace Graphics 53 | } // namespace Thea 54 | -------------------------------------------------------------------------------- /Code/Source/Graphics/MeshType.hpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2009 12 | // 13 | //============================================================================ 14 | 15 | #ifndef __Thea_Graphics_MeshType_hpp__ 16 | #define __Thea_Graphics_MeshType_hpp__ 17 | 18 | #include "../Common.hpp" 19 | #include "../Concept.hpp" 20 | 21 | namespace Thea { 22 | namespace Graphics { 23 | 24 | /** Concept of a general-purpose mesh. */ 25 | THEA_HAS_TYPE(IsGeneralMesh, GENERAL_MESH_TAG) 26 | 27 | /** Concept of a DCEL mesh. */ 28 | THEA_HAS_TYPE(IsDcelMesh, DCEL_MESH_TAG) 29 | 30 | /** Concept of a display mesh. */ 31 | THEA_HAS_TYPE(IsDisplayMesh, DISPLAY_MESH_TAG) 32 | 33 | } // namespace Graphics 34 | } // namespace Thea 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /Code/Source/Graphics/VertexWelder.hpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2009 12 | // 13 | //============================================================================ 14 | 15 | #ifndef __Thea_Graphics_VertexWelder_hpp__ 16 | #define __Thea_Graphics_VertexWelder_hpp__ 17 | 18 | #include "../Common.hpp" 19 | #include "../Noncopyable.hpp" 20 | #include "../MatVec.hpp" 21 | 22 | namespace Thea { 23 | namespace Graphics { 24 | 25 | // Forward declaration 26 | class VertexWelderImpl; 27 | 28 | /** 29 | * Maintains a set of vertices, with associated positions, without duplication. Two vertices are considered identical if their 30 | * positions are approximately the same. 31 | */ 32 | class THEA_API VertexWelder : private Noncopyable 33 | { 34 | public: 35 | /** Constructor. Two vertices are considered identical if their positions are separated by at most the welding radius. */ 36 | VertexWelder(Real weld_radius); 37 | 38 | /** Destructor. */ 39 | ~VertexWelder(); 40 | 41 | /** Add a vertex to the set, unless a coincident vertex already exists. */ 42 | void addVertex(void * vertex, Vector3 const & position); 43 | 44 | /** If a vertex exists at the specified position, return it, else return null. */ 45 | void * getVertex(Vector3 const & position) const; 46 | 47 | private: 48 | VertexWelderImpl * impl; 49 | 50 | }; // class VertexWelder 51 | 52 | } // namespace Graphics 53 | } // namespace Thea 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /Code/Source/Hash.hpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2019 12 | // 13 | //============================================================================ 14 | 15 | #ifndef __Thea_Hash_hpp__ 16 | #define __Thea_Hash_hpp__ 17 | 18 | #include "Platform.hpp" 19 | #include 20 | #include 21 | 22 | namespace Thea { 23 | 24 | /** Custom hasher that extends `std::hash`. The default specialization just duplicates `std::hash`. */ 25 | template 26 | struct Hasher : public std::hash {}; 27 | 28 | /** Convenience function that returns the hash of any object supported by Hasher. */ 29 | template 30 | std::size_t 31 | hashValue(T const & v) 32 | { 33 | return Hasher()(v); 34 | } 35 | 36 | /** Hash a value \a v and combine it with a preexisting hash \a seed. The combination is order-dependent. */ 37 | template 38 | void 39 | hashCombine(std::size_t & seed, T const & v) 40 | { 41 | // Copied from boost::hash_combine 42 | seed ^= hashValue(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2); // magic random number ensures spreading of hashes 43 | } 44 | 45 | /** Hash a range of values, optionally starting with a pre-existing hash \a seed. */ 46 | template 47 | std::size_t 48 | hashRange(Iterator first, Iterator last, std::size_t seed = 0) 49 | { 50 | // Copied from boost::hash_range 51 | std::size_t h = seed; 52 | for(; first != last; ++first) 53 | hashCombine(seed, *first); 54 | 55 | return h; 56 | } 57 | 58 | /** Specialization of Hasher for `std::pair` types. For some inexplicable reason this is not present in the standard library. */ 59 | template 60 | struct Hasher< std::pair > 61 | { 62 | std::size_t operator()(std::pair const & p) const 63 | { 64 | std::size_t h = hashValue(p.first); 65 | hashCombine(h, p.second); 66 | return h; 67 | } 68 | }; 69 | 70 | } // namespace Thea 71 | 72 | #endif 73 | -------------------------------------------------------------------------------- /Code/Source/Hyperplane3.hpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2011 12 | // 13 | //============================================================================ 14 | 15 | #ifndef __Thea_Hyperplane3_hpp__ 16 | #define __Thea_Hyperplane3_hpp__ 17 | 18 | #include "Common.hpp" 19 | #include "HyperplaneN.hpp" 20 | #include "Math.hpp" 21 | 22 | namespace Thea { 23 | 24 | /** A plane (2-flat) in 3-dimensional space. */ 25 | template 26 | class /* THEA_API */ HyperplaneN<3, T> : public Internal::HyperplaneNBase<3, T> 27 | { 28 | private: 29 | typedef Internal::HyperplaneNBase<3, T> BaseT; 30 | 31 | public: 32 | typedef typename BaseT::VectorT VectorT; 33 | 34 | static HyperplaneN fromThreePoints(VectorT const & point1, VectorT const & point2, VectorT const & point3) 35 | { 36 | HyperplaneN hyperplane; 37 | 38 | hyperplane.normal = (point2 - point1).cross(point3 - point1).normalized(); 39 | hyperplane.dist = hyperplane.normal.dot(point1); 40 | return hyperplane; 41 | } 42 | 43 | /** Construct a hyperplane given coefficients a, b, c, d of the plane equation a * x + b * y + c * z + d = 0. */ 44 | static HyperplaneN fromEquation(T const & a, T const & b, T const & c, T const & d) 45 | { 46 | HyperplaneN hyperplane; 47 | 48 | hyperplane.normal = VectorT(a, b, c); 49 | T sqlen = hyperplane.normal.squaredNorm(); 50 | if (Math::fuzzyEq(sqlen, static_cast(0))) 51 | { 52 | hyperplane.normal = VectorT::Zero(); 53 | hyperplane.dist = 0; 54 | } 55 | else 56 | { 57 | T len = std::sqrt(sqlen); 58 | hyperplane.normal /= len; 59 | hyperplane.dist = -d / len; 60 | } 61 | 62 | return hyperplane; 63 | } 64 | 65 | using BaseT::getEquation; 66 | 67 | /** Get the coefficients a, b, c, d of the plane equation a * x + b * y + c * z + d = 0. */ 68 | void getEquation(T & a, T & b, T & c, T & d) const 69 | { 70 | a = this->normal.x(); 71 | b = this->normal.y(); 72 | c = this->normal.z(); 73 | d = -this->dist; 74 | } 75 | 76 | }; // class HyperplaneN<3, T> 77 | 78 | #ifdef THEA_EXPORT_INSTANTIATION 79 | template class THEA_API HyperplaneN<3, Real>; 80 | #endif 81 | 82 | /** The default plane class in 3-dimensional real space. */ 83 | typedef HyperplaneN<3, Real> Plane3; 84 | 85 | } // namespace Thea 86 | 87 | #endif 88 | -------------------------------------------------------------------------------- /Code/Source/IRowOrColumnMajorMatrix.hpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2020 12 | // 13 | //============================================================================ 14 | 15 | #ifndef __Thea_IRowOrColumnMajorMatrix_hpp__ 16 | #define __Thea_IRowOrColumnMajorMatrix_hpp__ 17 | 18 | #include "IMatrix.hpp" 19 | 20 | namespace Thea { 21 | 22 | /** Interface for a matrix that has either a row-major or a column-major layout. */ 23 | template 24 | class /* THEA_API */ IRowOrColumnMajorMatrix : public virtual IMatrix 25 | { 26 | public: 27 | THEA_DECL_SMART_POINTERS(IRowOrColumnMajorMatrix) 28 | 29 | /** Is the matrix stored in row-major format? */ 30 | virtual int8 THEA_ICALL isRowMajor() const = 0; 31 | 32 | /** Is the matrix stored in column-major format? */ 33 | virtual int8 THEA_ICALL isColumnMajor() const = 0; 34 | 35 | }; // class IRowOrColumnMajorMatrix 36 | 37 | } // namespace Thea 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /Code/Source/ISparseMatrix.hpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2019 12 | // 13 | //============================================================================ 14 | 15 | #ifndef __Thea_ISparseMatrix_hpp__ 16 | #define __Thea_ISparseMatrix_hpp__ 17 | 18 | #include "IMatrix.hpp" 19 | 20 | namespace Thea { 21 | 22 | // Forward declarations 23 | template class ICompressedSparseMatrix; 24 | 25 | /** Interface for a 2D sparse matrix. Useful for passing matrices across shared library boundaries. */ 26 | template 27 | class /* THEA_API */ ISparseMatrix : public virtual IMatrix 28 | { 29 | public: 30 | THEA_DECL_SMART_POINTERS(ISparseMatrix) 31 | 32 | /** 33 | * Get the number of entries actually stored in the matrix. These are often called "non-zeros", though they may actually 34 | * have the numeric value 0. 35 | */ 36 | virtual int64 THEA_ICALL numStoredElements() const = 0; 37 | 38 | /** 39 | * If the matrix is stored in compressed column or row format, get a pointer to a derived interface supporting access 40 | * specific to that format. Else, return null. 41 | * 42 | * @note dynamic_cast does not work reliably across shared library boundaries, and relying on users to avoid it 43 | * and only use static_cast is dangerous. 44 | */ 45 | virtual ICompressedSparseMatrix const * THEA_ICALL asCompressed() const = 0; 46 | 47 | /** 48 | * If the matrix is stored in compressed column or row format, get a pointer to a derived interface supporting access 49 | * specific to that format. Else, return null. 50 | * 51 | * @note dynamic_cast does not work reliably across shared library boundaries, and relying on users to avoid it 52 | * and only use static_cast is dangerous. 53 | */ 54 | virtual ICompressedSparseMatrix * THEA_ICALL asCompressed() = 0; 55 | 56 | }; // class ISparseMatrix 57 | 58 | } // namespace Thea 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /Code/Source/Iostream.hpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2009 12 | // 13 | //============================================================================ 14 | 15 | #ifndef __Thea_Iostream_hpp__ 16 | #define __Thea_Iostream_hpp__ 17 | 18 | #include "BinaryInputStream.hpp" 19 | #include "BinaryOutputStream.hpp" 20 | #include "TextInputStream.hpp" 21 | #include "TextOutputStream.hpp" 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /Code/Source/Line2.hpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2011 12 | // 13 | //============================================================================ 14 | 15 | #ifndef __Thea_Line2_hpp__ 16 | #define __Thea_Line2_hpp__ 17 | 18 | #include "Common.hpp" 19 | #include "LineN.hpp" 20 | 21 | namespace Thea { 22 | 23 | #ifdef THEA_EXPORT_INSTANTIATION 24 | template class THEA_API LineN<2, Real>; 25 | #endif 26 | 27 | /** The default straight line class in 2-dimensional real space. */ 28 | typedef LineN<2, Real> Line2; 29 | 30 | } // namespace Thea 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /Code/Source/Line3.hpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2011 12 | // 13 | //============================================================================ 14 | 15 | #ifndef __Thea_Line3_hpp__ 16 | #define __Thea_Line3_hpp__ 17 | 18 | #include "Common.hpp" 19 | #include "LineN.hpp" 20 | 21 | namespace Thea { 22 | 23 | #ifdef THEA_EXPORT_INSTANTIATION 24 | template class THEA_API LineN<3, Real>; 25 | #endif 26 | 27 | /** The default straight line class in 3-dimensional real space. */ 28 | typedef LineN<3, Real> Line3; 29 | 30 | } // namespace Thea 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /Code/Source/LineSegment2.hpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2011 12 | // 13 | //============================================================================ 14 | 15 | #ifndef __Thea_LineSegment2_hpp__ 16 | #define __Thea_LineSegment2_hpp__ 17 | 18 | #include "Common.hpp" 19 | #include "LineSegmentN.hpp" 20 | 21 | namespace Thea { 22 | 23 | #ifdef THEA_EXPORT_INSTANTIATION 24 | template class THEA_API LineSegmentN<2, Real>; 25 | #endif 26 | 27 | /** The default line segment class in 2-dimensional real space. */ 28 | typedef LineSegmentN<2, Real> LineSegment2; 29 | 30 | } // namespace Thea 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /Code/Source/LineSegment3.hpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2011 12 | // 13 | //============================================================================ 14 | 15 | #ifndef __Thea_LineSegment3_hpp__ 16 | #define __Thea_LineSegment3_hpp__ 17 | 18 | #include "Common.hpp" 19 | #include "LineSegmentN.hpp" 20 | 21 | namespace Thea { 22 | 23 | #ifdef THEA_EXPORT_INSTANTIATION 24 | template class THEA_API LineSegmentN<3, Real>; 25 | #endif 26 | 27 | /** The default line segment class in 3-dimensional real space. */ 28 | typedef LineSegmentN<3, Real> LineSegment3; 29 | 30 | } // namespace Thea 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /Code/Source/List.hpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2011 12 | // 13 | //============================================================================ 14 | 15 | #ifndef __Thea_List_hpp__ 16 | #define __Thea_List_hpp__ 17 | 18 | #include "Platform.hpp" 19 | #include 20 | 21 | namespace Thea { 22 | 23 | /** Linked list. */ 24 | template < typename T, typename Alloc = std::allocator > using List = std::list; 25 | 26 | } // namespace Thea 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /Code/Source/Log.cpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2009 12 | // 13 | //============================================================================ 14 | 15 | #include "Log.hpp" 16 | #include "Common.hpp" 17 | #include 18 | #include 19 | #include 20 | 21 | namespace Thea { 22 | namespace LogInternal { 23 | 24 | Spinlock lock; 25 | 26 | std::string 27 | stripPathFromFilename(std::string const & full_path) 28 | { 29 | size_t last_slash; 30 | last_slash = full_path.find_last_of("/\\"); 31 | return (last_slash >= full_path.length()) ? full_path : full_path.substr(last_slash + 1); 32 | } 33 | 34 | std::string 35 | currentDateTimeToString() 36 | { 37 | std::time_t raw_time; 38 | std::tm const * time_info; 39 | 40 | std::time(&raw_time); // get raw system time 41 | time_info = std::localtime(&raw_time); // break it down into components w.r.t. the current locale 42 | std::ostringstream os; 43 | os << 1900 + time_info->tm_year << '-' 44 | << std::setw(2) << std::right << std::setfill('0') << 1 + time_info->tm_mon << '-' 45 | << std::setw(2) << std::right << std::setfill('0') << time_info->tm_mday << ' ' 46 | << std::setw(2) << std::right << std::setfill('0') << time_info->tm_hour << ':' 47 | << std::setw(2) << std::right << std::setfill('0') << time_info->tm_min << ':' 48 | << std::setw(2) << std::right << std::setfill('0') << time_info->tm_sec; 49 | return os.str(); 50 | } 51 | 52 | } // namespace LogInternal 53 | } // namespace Thea 54 | -------------------------------------------------------------------------------- /Code/Source/Map.hpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2011 12 | // 13 | //============================================================================ 14 | 15 | #ifndef __Thea_Map_hpp__ 16 | #define __Thea_Map_hpp__ 17 | 18 | #include "Platform.hpp" 19 | #include 20 | 21 | namespace Thea { 22 | 23 | /** Maps keys to values. Requires an ordering on the keys. */ 24 | template < typename Key, 25 | typename T, 26 | typename Compare = std::less, 27 | typename Alloc = std::allocator< std::pair > 28 | > using Map = std::map; 29 | 30 | /** Maps (possibly duplicate) keys to values. Requires an ordering on the keys. */ 31 | template < typename Key, 32 | typename T, 33 | typename Compare = std::less, 34 | typename Alloc = std::allocator< std::pair > 35 | > using MultiMap = std::multimap; 36 | 37 | } // namespace Thea 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /Code/Source/MatrixFormat.hpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2011 12 | // 13 | //============================================================================ 14 | 15 | #ifndef __Thea_MatrixFormat_hpp__ 16 | #define __Thea_MatrixFormat_hpp__ 17 | 18 | #include "Common.hpp" 19 | 20 | // Resolve a conflict between X.h (which #defines Success) and Eigen (which has an enum called Success). Fortunately both 21 | // headers currently assign the same value to Success (0) so the #undef should be all that's needed. 22 | // https://stackoverflow.com/questions/22400905/eigen-and-cimg-compatibility-issues 23 | #ifdef Success 24 | # undef Success 25 | #endif 26 | #include 27 | 28 | namespace Thea { 29 | 30 | /** %Matrix layouts (enum class). */ 31 | struct THEA_API MatrixLayout 32 | { 33 | /** Supported values. */ 34 | enum Value 35 | { 36 | ROW_MAJOR = (int)Eigen::RowMajor, ///< Row-major layout. 37 | COLUMN_MAJOR = (int)Eigen::ColMajor, ///< Column-major layout. 38 | }; 39 | 40 | THEA_ENUM_CLASS_BODY(MatrixLayout) 41 | }; 42 | 43 | } // namespace Thea 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /Code/Source/Noncopyable.hpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2009 12 | // 13 | //============================================================================ 14 | 15 | #ifndef __Thea_Noncopyable_hpp__ 16 | #define __Thea_Noncopyable_hpp__ 17 | 18 | #include "Platform.hpp" 19 | 20 | namespace Thea { 21 | 22 | /** 23 | * A base class for objects that should never be copied. This is achieved by declaring the copy constructor and assignment 24 | * operator as private members. Never ever try to refer to an object of a derived class using a Noncopyable pointer or 25 | * reference (in any case this seems semantically weird) -- to ensure this class has zero runtime overhead, the destructor is 26 | * not virtual. 27 | */ 28 | class THEA_API Noncopyable 29 | { 30 | protected: 31 | /** Constructor. */ 32 | Noncopyable() {} 33 | 34 | /** Destructor. */ 35 | ~Noncopyable() {} 36 | 37 | private: 38 | /** 39 | * Hidden copy constructor. No body provided since this should never be accessible -- if a linker error occurs then 40 | * something is seriously wrong. 41 | */ 42 | THEA_DLL_LOCAL Noncopyable(const Noncopyable &); 43 | 44 | /** 45 | * Hidden assignment operator. No body provided since this should never be accessible -- if a linker error occurs then 46 | * something is seriously wrong. 47 | */ 48 | THEA_DLL_LOCAL Noncopyable const & operator=(Noncopyable const &); 49 | 50 | }; // class Noncopyable 51 | 52 | } // namespace Thea 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /Code/Source/ParametricCurve3.hpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2018 12 | // 13 | //============================================================================ 14 | 15 | #ifndef __Thea_ParametricCurve3_hpp__ 16 | #define __Thea_ParametricCurve3_hpp__ 17 | 18 | #include "Common.hpp" 19 | #include "ParametricCurveN.hpp" 20 | 21 | namespace Thea { 22 | 23 | /** A parametric curve segment in 3-dimensional space. */ 24 | template 25 | class /* THEA_API */ ParametricCurveN<3, T> : public Internal::ParametricCurveNBase<3, T> 26 | { 27 | private: 28 | typedef Internal::ParametricCurveNBase<3, T> BaseT; 29 | 30 | public: 31 | typedef typename BaseT::VectorT VectorT; 32 | 33 | /** Constructor, sets parameter limits. */ 34 | ParametricCurveN(T const & min_param_ = 0, T const & max_param_ = 1) : BaseT(min_param_, max_param_) {} 35 | 36 | /** Destructor. */ 37 | virtual ~ParametricCurveN() = 0; 38 | 39 | /** 40 | * Get the unit binormal vector (third Frenet vector) to the curve at parameter value \a t. This requires the second 41 | * derivative (dimensions > 3 require the third derivative), and the return value is zero if hasDeriv(2) returns false (or 42 | * N < 3, in which case the binormal is undefined). 43 | */ 44 | VectorT getBinormal(T const & t) const 45 | { 46 | if (!this->hasDeriv(2)) return VectorT::Zero(); 47 | 48 | VectorT d1 = this->eval(t, 1); 49 | T d1_sqlen = d1.squaredNorm(); 50 | if (Math::fuzzyEq(d1_sqlen, static_cast(0), Math::square(Math::eps()))) 51 | return VectorT::Zero(); 52 | 53 | VectorT d2 = this->eval(t, 2); 54 | d2 -= (d2.dot(d1) / d1_sqlen) * d1; // sqrt in normalizing d1 avoided because of repeated d1 55 | 56 | return d1.cross(d2).normalized(); 57 | } 58 | 59 | }; // class ParametricCurveN 60 | 61 | template ParametricCurveN<3, T>::~ParametricCurveN() {} // pure virtual destructor should have body 62 | 63 | } // namespace Thea 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /Code/Source/Plane3.hpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2011 12 | // 13 | //============================================================================ 14 | 15 | #ifndef __Thea_Plane3_hpp__ 16 | #define __Thea_Plane3_hpp__ 17 | 18 | #include "Hyperplane3.hpp" 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /Code/Source/Plugins/ARPACK/ArpackCommon.hpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2009 12 | // 13 | //============================================================================ 14 | 15 | #ifndef __Thea_ArpackCommon_hpp__ 16 | #define __Thea_ArpackCommon_hpp__ 17 | 18 | #include "../../Common.hpp" 19 | #include "ArpackSymbolVisibility.hpp" 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /Code/Source/Plugins/ARPACK/ArpackEigenSolverDense.cpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2009 12 | // 13 | //============================================================================ 14 | 15 | #include "ArpackEigenSolver.hpp" 16 | #include "../../ThirdParty/arpackpp/ardsnsym.h" 17 | 18 | namespace Thea { 19 | namespace Algorithms { 20 | 21 | int64 22 | ArpackEigenSolver::solveDense(IDenseMatrix const & m, int32 nev, int8 shift_invert, float64 sigma, char * which, 23 | int32 ncv, float64 tol, int32 maxit, float64 * resid, int8 auto_shift) 24 | { 25 | try 26 | { 27 | // Create the matrix 28 | ARdsNonSymMatrix arm(m.rows(), const_cast(m.data())); 29 | 30 | // Setup the problem 31 | std::shared_ptr< ARdsNonSymStdEig > eig = 32 | shift_invert ? std::shared_ptr< ARdsNonSymStdEig >(new ARdsNonSymStdEig( 33 | nev, arm, sigma, which, ncv, 34 | tol, maxit, resid, auto_shift)) 35 | : std::shared_ptr< ARdsNonSymStdEig >(new ARdsNonSymStdEig( 36 | nev, arm, which, ncv, tol, 37 | maxit, resid, auto_shift)); 38 | eig->Trace(); 39 | 40 | // Find eigenpairs 41 | size_t nconv = (size_t)eig->FindEigenvectors(); 42 | 43 | eigenvalues [0].resize(nconv); eigenvalues [1].resize(nconv); 44 | eigenvectors[0].resize(nconv); eigenvectors[1].resize(nconv); 45 | 46 | for (size_t i = 0; i < nconv; ++i) 47 | { 48 | eigenvalues[0][i] = eig->EigenvalueReal((int)i); 49 | eigenvalues[1][i] = eig->EigenvalueImag((int)i); 50 | 51 | eigenvectors[0][i].resize(ndims); eigenvectors[1][i].resize(ndims); 52 | for (intx j = 0; j < ndims; ++j) 53 | { 54 | eigenvectors[0][i][j] = eig->EigenvectorReal((int)i, (int)j); 55 | eigenvectors[1][i][j] = eig->EigenvectorImag((int)i, (int)j); 56 | } 57 | } 58 | 59 | return (int64)nconv; 60 | } 61 | THEA_CATCH(return -1;, ERROR, "%s: Error solving dense eigensystem", getName()) 62 | } 63 | 64 | } // namespace Algorithms 65 | } // namespace Thea 66 | -------------------------------------------------------------------------------- /Code/Source/Plugins/ARPACK/ArpackPlugin.cpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2009 12 | // 13 | //============================================================================ 14 | 15 | #include "ArpackPlugin.hpp" 16 | #include "ArpackEigenSolver.hpp" 17 | 18 | namespace Thea { 19 | 20 | static Algorithms::ArpackPlugin * plugin = nullptr; 21 | 22 | /** DLL start routine. Installs plugin. */ 23 | extern "C" THEA_ARPACK_API IPlugin * 24 | dllStartPlugin(IFactoryRegistry * registry_) 25 | { 26 | plugin = new Algorithms::ArpackPlugin(registry_); 27 | return plugin; 28 | } 29 | 30 | /** DLL stop routine. Uninstalls plugin. */ 31 | extern "C" THEA_ARPACK_API void 32 | dllStopPlugin() 33 | { 34 | delete plugin; 35 | } 36 | 37 | namespace Algorithms { 38 | 39 | static char const * ARPACK_PLUGIN_NAME = "ARPACK EigenSolver"; 40 | static char const * ARPACK_EIGENSOLVER_NAME = "ARPACK"; 41 | 42 | ArpackPlugin::ArpackPlugin(IFactoryRegistry * registry_) 43 | : registry(registry_), factory(nullptr), started(false) 44 | { 45 | alwaysAssertM(registry, std::string(ARPACK_PLUGIN_NAME) + ": Factory registry must be non-null"); 46 | } 47 | 48 | ArpackPlugin::~ArpackPlugin() 49 | { 50 | uninstall(); 51 | } 52 | 53 | char const * 54 | ArpackPlugin::getName() const 55 | { 56 | return ARPACK_PLUGIN_NAME; 57 | } 58 | 59 | void 60 | ArpackPlugin::install() 61 | {} 62 | 63 | void 64 | ArpackPlugin::startup() 65 | { 66 | if (!started) 67 | { 68 | if (!factory) 69 | factory = new ArpackEigenSolverFactory; 70 | 71 | registry->addEigenSolverFactory(ARPACK_EIGENSOLVER_NAME, factory); 72 | started = true; 73 | } 74 | } 75 | 76 | void 77 | ArpackPlugin::shutdown() 78 | { 79 | if (started) 80 | { 81 | factory->destroyAllEigenSolvers(); 82 | 83 | registry->removeEigenSolverFactory(ARPACK_EIGENSOLVER_NAME); 84 | started = false; 85 | } 86 | } 87 | 88 | void 89 | ArpackPlugin::uninstall() 90 | { 91 | shutdown(); // not currently dependent on presence of other plugins 92 | 93 | if (factory) 94 | { 95 | delete factory; 96 | factory = nullptr; 97 | } 98 | } 99 | 100 | } // namespace Algorithms 101 | 102 | } // namespace Thea 103 | -------------------------------------------------------------------------------- /Code/Source/Plugins/ARPACK/ArpackPlugin.hpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2009 12 | // 13 | //============================================================================ 14 | 15 | #ifndef __Thea_Algorithms_ArpackPlugin_hpp__ 16 | #define __Thea_Algorithms_ArpackPlugin_hpp__ 17 | 18 | #include "../../IPlugin.hpp" 19 | #include "ArpackCommon.hpp" 20 | 21 | namespace Thea { 22 | namespace Algorithms { 23 | 24 | // Forward declaration 25 | class ArpackEigenSolverFactory; 26 | 27 | /** An ARPACK-based eigensolver plugin. */ 28 | class THEA_ARPACK_DLL_LOCAL ArpackPlugin : public virtual IPlugin 29 | { 30 | public: 31 | /** Constructor. */ 32 | ArpackPlugin(IFactoryRegistry * registry_); 33 | 34 | /** Destructor. */ 35 | ~ArpackPlugin(); 36 | 37 | char const * getName() const; 38 | void install(); 39 | void startup(); 40 | void shutdown(); 41 | void uninstall(); 42 | 43 | private: 44 | IFactoryRegistry * registry; 45 | ArpackEigenSolverFactory * factory; 46 | bool started; 47 | 48 | }; // class ArpackPlugin 49 | 50 | } // namespace Algorithms 51 | } // namespace Thea 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /Code/Source/Plugins/CSPARSE/CsparseCommon.hpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2009 12 | // 13 | //============================================================================ 14 | 15 | #ifndef __Thea_CsparseCommon_hpp__ 16 | #define __Thea_CsparseCommon_hpp__ 17 | 18 | #include "../../Common.hpp" 19 | #include "CsparseSymbolVisibility.hpp" 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /Code/Source/Plugins/CSPARSE/CsparsePlugin.cpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2009 12 | // 13 | //============================================================================ 14 | 15 | #include "CsparsePlugin.hpp" 16 | #include "CsparseLinearSolver.hpp" 17 | 18 | namespace Thea { 19 | 20 | static Algorithms::CsparsePlugin * plugin = nullptr; 21 | 22 | /** DLL start routine. Installs plugin. */ 23 | extern "C" THEA_CSPARSE_API IPlugin * 24 | dllStartPlugin(IFactoryRegistry * registry_) 25 | { 26 | plugin = new Algorithms::CsparsePlugin(registry_); 27 | return plugin; 28 | } 29 | 30 | /** DLL stop routine. Uninstalls plugin. */ 31 | extern "C" THEA_CSPARSE_API void 32 | dllStopPlugin() 33 | { 34 | delete plugin; 35 | } 36 | 37 | namespace Algorithms { 38 | 39 | static char const * CSPARSE_PLUGIN_NAME = "CSPARSE LinearSolver"; 40 | static char const * CSPARSE_LINEARSOLVER_NAME = "CSPARSE"; 41 | 42 | CsparsePlugin::CsparsePlugin(IFactoryRegistry * registry_) 43 | : registry(registry_), factory(nullptr), started(false) 44 | { 45 | alwaysAssertM(registry, std::string(CSPARSE_PLUGIN_NAME) + ": Factory registry must be non-null"); 46 | } 47 | 48 | CsparsePlugin::~CsparsePlugin() 49 | { 50 | uninstall(); 51 | } 52 | 53 | char const * 54 | CsparsePlugin::getName() const 55 | { 56 | return CSPARSE_PLUGIN_NAME; 57 | } 58 | 59 | void 60 | CsparsePlugin::install() 61 | {} 62 | 63 | void 64 | CsparsePlugin::startup() 65 | { 66 | if (!started) 67 | { 68 | if (!factory) 69 | factory = new CsparseLinearSolverFactory; 70 | 71 | registry->addLinearSolverFactory(CSPARSE_LINEARSOLVER_NAME, factory); 72 | started = true; 73 | } 74 | } 75 | 76 | void 77 | CsparsePlugin::shutdown() 78 | { 79 | if (started) 80 | { 81 | factory->destroyAllLinearSolvers(); 82 | 83 | registry->removeLinearSolverFactory(CSPARSE_LINEARSOLVER_NAME); 84 | started = false; 85 | } 86 | } 87 | 88 | void 89 | CsparsePlugin::uninstall() 90 | { 91 | shutdown(); // not currently dependent on presence of other plugins 92 | 93 | if (factory) 94 | { 95 | delete factory; 96 | factory = nullptr; 97 | } 98 | } 99 | 100 | } // namespace Algorithms 101 | 102 | } // namespace Thea 103 | -------------------------------------------------------------------------------- /Code/Source/Plugins/CSPARSE/CsparsePlugin.hpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2009 12 | // 13 | //============================================================================ 14 | 15 | #ifndef __Thea_Algorithms_CsparsePlugin_hpp__ 16 | #define __Thea_Algorithms_CsparsePlugin_hpp__ 17 | 18 | #include "../../IPlugin.hpp" 19 | #include "CsparseCommon.hpp" 20 | 21 | namespace Thea { 22 | namespace Algorithms { 23 | 24 | // Forward declaration 25 | class CsparseLinearSolverFactory; 26 | 27 | /** A CSPARSE-based plugin for solving sparse systems of linear equations. */ 28 | class THEA_CSPARSE_DLL_LOCAL CsparsePlugin : public virtual IPlugin 29 | { 30 | public: 31 | /** Default constructor. */ 32 | CsparsePlugin(IFactoryRegistry * registry_); 33 | 34 | /** Destructor. */ 35 | ~CsparsePlugin(); 36 | 37 | char const * getName() const; 38 | void install(); 39 | void startup(); 40 | void shutdown(); 41 | void uninstall(); 42 | 43 | private: 44 | IFactoryRegistry * registry; 45 | CsparseLinearSolverFactory * factory; 46 | bool started; 47 | 48 | }; // class CsparsePlugin 49 | 50 | } // namespace Algorithms 51 | } // namespace Thea 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /Code/Source/Plugins/GL/GlCommon.hpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2009 12 | // 13 | //============================================================================ 14 | 15 | #ifndef __Thea_Graphics_Gl_GlCommon_hpp__ 16 | #define __Thea_Graphics_Gl_GlCommon_hpp__ 17 | 18 | #include "../../Common.hpp" 19 | #include "GlSymbolVisibility.hpp" 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /Code/Source/Plugins/GL/GlFramebuffer.hpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2009 12 | // 13 | //============================================================================ 14 | 15 | #ifndef __Thea_Graphics_Gl_GlFramebuffer_hpp__ 16 | #define __Thea_Graphics_Gl_GlFramebuffer_hpp__ 17 | 18 | #include "../../Graphics/IFramebuffer.hpp" 19 | #include "../../Array.hpp" 20 | #include "GlCommon.hpp" 21 | #include "GlHeaders.hpp" 22 | #include "GlTexture.hpp" 23 | 24 | namespace Thea { 25 | namespace Graphics { 26 | namespace Gl { 27 | 28 | // Forward declarations 29 | class GlRenderSystem; 30 | 31 | /** An OpenGL framebuffer. */ 32 | class THEA_GL_DLL_LOCAL GlFramebuffer : public virtual IFramebuffer 33 | { 34 | public: 35 | /** Constructor. */ 36 | GlFramebuffer(GlRenderSystem * render_system_, char const * name_); 37 | 38 | /** Destructor. */ 39 | ~GlFramebuffer(); 40 | 41 | /** Get the parent rendersystem. */ 42 | GlRenderSystem * getRenderSystem() const { return render_system; } 43 | 44 | char const * THEA_ICALL getName() const { return name.c_str(); } 45 | int8 THEA_ICALL setName(char const * s) { return false; /* name is read-only */ } 46 | 47 | int8 THEA_ICALL attach(int32 ap, ITexture * texture, int32 face = ITexture::Face::POS_X, int64 z_offset = 0); 48 | int8 THEA_ICALL detach(int32 ap); 49 | int8 THEA_ICALL detachAll(); 50 | int64 THEA_ICALL getWidth() const { return width; } 51 | int64 THEA_ICALL getHeight() const { return height; } 52 | 53 | /** Get the OpenGL ID of the framebuffer object. */ 54 | GLuint getGlId() const { return gl_fbid; } 55 | 56 | /** Use the framebuffer for rendering. */ 57 | int8 use(); 58 | 59 | private: 60 | GlRenderSystem * render_system; 61 | std::string name; 62 | GLuint gl_fbid; 63 | GlTexture * attachment_table[AttachmentPoint::NUM]; 64 | int32 num_attachments; 65 | Array gl_draw_buffers; 66 | int64 width; 67 | int64 height; 68 | 69 | }; // class GlFramebuffer 70 | 71 | } // namespace Gl 72 | } // namespace Graphics 73 | } // namespace Thea 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /Code/Source/Plugins/GL/GlPlugin.cpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2009 12 | // 13 | //============================================================================ 14 | 15 | #include "GlPlugin.hpp" 16 | #include "GlRenderSystem.hpp" 17 | 18 | namespace Thea { 19 | 20 | static Graphics::Gl::GlPlugin * plugin = nullptr; 21 | 22 | /** DLL start routine. Installs plugin. */ 23 | extern "C" THEA_GL_API IPlugin * 24 | dllStartPlugin(IFactoryRegistry * registry_) 25 | { 26 | plugin = new Graphics::Gl::GlPlugin(registry_); 27 | return plugin; 28 | } 29 | 30 | /** DLL stop routine. Uninstalls plugin. */ 31 | extern "C" THEA_GL_API void 32 | dllStopPlugin() 33 | { 34 | delete plugin; 35 | } 36 | 37 | namespace Graphics { 38 | namespace Gl { 39 | 40 | static char const * GL_PLUGIN_NAME = "OpenGL RenderSystem"; 41 | static char const * GL_RENDERSYSTEM_NAME = "OpenGL"; 42 | 43 | GlPlugin::GlPlugin(IFactoryRegistry * registry_) 44 | : registry(registry_), factory(nullptr), started(false) 45 | { 46 | alwaysAssertM(registry, std::string(GL_PLUGIN_NAME) + ": Factory registry must be non-null"); 47 | } 48 | 49 | GlPlugin::~GlPlugin() 50 | { 51 | uninstall(); 52 | delete factory; 53 | } 54 | 55 | char const * 56 | GlPlugin::getName() const 57 | { 58 | return GL_PLUGIN_NAME; 59 | } 60 | 61 | void 62 | GlPlugin::install() 63 | {} 64 | 65 | void 66 | GlPlugin::startup() 67 | { 68 | if (!started) 69 | { 70 | if (!factory) 71 | factory = new GlRenderSystemFactory; 72 | 73 | registry->addRenderSystemFactory(GL_RENDERSYSTEM_NAME, factory); 74 | started = true; 75 | } 76 | } 77 | 78 | void 79 | GlPlugin::shutdown() 80 | { 81 | if (started) 82 | { 83 | factory->destroyAllRenderSystems(); 84 | 85 | registry->removeRenderSystemFactory(GL_RENDERSYSTEM_NAME); 86 | started = false; 87 | } 88 | } 89 | 90 | void 91 | GlPlugin::uninstall() 92 | { 93 | shutdown(); // not currently dependent on presence of other plugins 94 | 95 | // Don't delete the factory, we don't want anyone to be able to create a second GL rendersystem by installing the plugin 96 | // object again (though this shouldn't normally happen). Delete it only when the plugin is properly destroyed. 97 | // 98 | // ^^^ This is expected to change when we figure out how to properly cleanup GL state after a rendersystem is destroyed. 99 | } 100 | 101 | } // namespace Gl 102 | } // namespace Graphics 103 | 104 | } // namespace Thea 105 | -------------------------------------------------------------------------------- /Code/Source/Plugins/GL/GlPlugin.hpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2009 12 | // 13 | //============================================================================ 14 | 15 | #ifndef __Thea_Graphics_Gl_GlPlugin_hpp__ 16 | #define __Thea_Graphics_Gl_GlPlugin_hpp__ 17 | 18 | #include "../../IPlugin.hpp" 19 | #include "GlCommon.hpp" 20 | 21 | namespace Thea { 22 | namespace Graphics { 23 | namespace Gl { 24 | 25 | // Forward declaration 26 | class GlRenderSystemFactory; 27 | 28 | /** An OpenGL rendering plugin. */ 29 | class THEA_GL_DLL_LOCAL GlPlugin : public virtual IPlugin 30 | { 31 | public: 32 | /** Constructor. */ 33 | GlPlugin(IFactoryRegistry * registry_); 34 | 35 | /** Destructor. */ 36 | ~GlPlugin(); 37 | 38 | char const * THEA_ICALL getName() const; 39 | int8 THEA_ICALL setName(char const * s) { return false; /* name is read-only */ } 40 | 41 | void THEA_ICALL install(); 42 | void THEA_ICALL startup(); 43 | void THEA_ICALL shutdown(); 44 | void THEA_ICALL uninstall(); 45 | 46 | private: 47 | IFactoryRegistry * registry; 48 | GlRenderSystemFactory * factory; 49 | bool started; 50 | 51 | }; // class GlPlugin 52 | 53 | } // namespace Gl 54 | } // namespace Graphics 55 | } // namespace Thea 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /Code/Source/Queue.hpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2011 12 | // 13 | //============================================================================ 14 | 15 | #ifndef __Thea_Queue_hpp__ 16 | #define __Thea_Queue_hpp__ 17 | 18 | #include "Platform.hpp" 19 | #include 20 | #include 21 | 22 | /** First-in-first-out queue of objects. */ 23 | template < typename T, typename Container = std::deque > using Queue = std::queue; 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /Code/Source/Ray3.hpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2009 12 | // 13 | //============================================================================ 14 | 15 | #ifndef __Thea_Ray3_hpp__ 16 | #define __Thea_Ray3_hpp__ 17 | 18 | #include "Common.hpp" 19 | #include "RayN.hpp" 20 | 21 | namespace Thea { 22 | 23 | #ifdef THEA_EXPORT_INSTANTIATION 24 | template class THEA_API RayN<3, Real>; 25 | #endif 26 | 27 | // The default ray class in 3-dimensional real space. 28 | typedef RayN<3, Real> Ray3; 29 | 30 | } // namespace Thea 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /Code/Source/RayIntersectable3.hpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2009 12 | // 13 | //============================================================================ 14 | 15 | #ifndef __Thea_RayIntersectable3_hpp__ 16 | #define __Thea_RayIntersectable3_hpp__ 17 | 18 | #include "Common.hpp" 19 | #include "RayIntersectableN.hpp" 20 | 21 | namespace Thea { 22 | 23 | #ifdef THEA_EXPORT_INSTANTIATION 24 | template class THEA_API RayIntersectionN<3, Real>; 25 | template class THEA_API RayIntersectableN<3, Real>; 26 | #endif 27 | 28 | // The default ray intersection class in real 3-space. 29 | typedef RayIntersectionN<3, Real> RayIntersection3; 30 | 31 | // The default ray intersectable interface in real 3-space. 32 | typedef RayIntersectableN<3, Real> RayIntersectable3; 33 | 34 | } // namespace Thea 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /Code/Source/RigidTransform2.hpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2009 12 | // 13 | //============================================================================ 14 | 15 | #ifndef __Thea_RigidTransform2_hpp__ 16 | #define __Thea_RigidTransform2_hpp__ 17 | 18 | #include "Common.hpp" 19 | #include "AffineTransform2.hpp" 20 | #include "RigidTransformN.hpp" 21 | 22 | namespace Thea { 23 | 24 | /** 25 | * A rigid transformation in 2-space, consisting of a rotation followed by a translation. 26 | * 27 | * @note While this is technically an affine transform, it restricts enough functionality to make a separate implementation 28 | * preferable. It can be trivially converted to an AffineTransform2 using the implicit conversion operator or toAffine(). 29 | */ 30 | template 31 | class /* THEA_API */ RigidTransformN<2, T> : public Internal::RigidTransformNBase<2, T> 32 | { 33 | private: 34 | typedef Internal::RigidTransformNBase<2, T> BaseT; 35 | 36 | public: 37 | typedef typename BaseT::AffineTransformT AffineTransformT; 38 | typedef typename BaseT::VectorT VectorT; 39 | typedef typename BaseT::MatrixT MatrixT; 40 | 41 | /** Default constructor. Constructs the identity transform. */ 42 | RigidTransformN() {} 43 | 44 | using BaseT::translation; 45 | 46 | /** Construct a translation. */ 47 | static RigidTransformN translation(T const & tx, T const & ty) 48 | { 49 | return BaseT::translation(VectorT(tx, ty)); 50 | } 51 | 52 | /** Construct a rotation specified by an angle (in radians) around the origin. */ 53 | static RigidTransformN rotation(Real radians) 54 | { 55 | return BaseT::_fromAffine(AffineTransformT::rotation(radians)); 56 | } 57 | 58 | }; // class RigidTransformN<2, T> 59 | 60 | #ifdef THEA_EXPORT_INSTANTIATION 61 | template class THEA_API RigidTransformN<2, Real>; 62 | #endif 63 | 64 | /** The default rigid transform class in real 2-space. */ 65 | typedef RigidTransformN<2, Real> RigidTransform2; 66 | 67 | } // namespace Thea 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /Code/Source/ScopedLock.hpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2013 12 | // 13 | //============================================================================ 14 | 15 | #ifndef __Thea_ScopedLock_hpp__ 16 | #define __Thea_ScopedLock_hpp__ 17 | 18 | namespace Thea { 19 | 20 | /** A wrapper for a shared lock object that acquires the lock upon construction and releases it upon destruction. */ 21 | template 22 | class ScopedLock 23 | { 24 | public: 25 | typedef LockT Lock; ///< The wrapped lock class. 26 | 27 | /** Constructor, which acquires the lock. The wrapped lock object must persist as long as this wrapper does. */ 28 | ScopedLock(LockT * lock_) : lock(lock_) 29 | { 30 | if (lock) 31 | lock->lock(); 32 | } 33 | 34 | /** Destructor, which releases the lock. */ 35 | ~ScopedLock() 36 | { 37 | if (lock) 38 | lock->unlock(); 39 | } 40 | 41 | private: 42 | Lock * lock; 43 | 44 | }; // class ScopedLock 45 | 46 | } // namespace Thea 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /Code/Source/Serializable.cpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2009 12 | // 13 | //============================================================================ 14 | 15 | #include "Serializable.hpp" 16 | 17 | #if THEA_EXTERN_TEMPLATES 18 | 19 | THEA_INSTANTIATE_SMART_POINTERS(Thea::Serializable) 20 | THEA_INSTANTIATE_SMART_POINTERS(Thea::SerializableFactory) 21 | 22 | #endif // THEA_EXTERN_TEMPLATES 23 | 24 | namespace Thea { 25 | 26 | TextInputStream::Settings 27 | Serializable::initConfigReadSettings() 28 | { 29 | TextInputStream::Settings settings; 30 | settings.caseSensitive = false; 31 | settings.cppBlockComments = true; 32 | settings.cppLineComments = true; 33 | settings.escapeSequencesInStrings = true; 34 | settings.falseSymbols.insert("false"); 35 | settings.falseSymbols.insert("off"); 36 | settings.falseSymbols.insert("0"); 37 | settings.generateCommentTokens = false; 38 | settings.generateNewlineTokens = false; 39 | settings.otherCommentCharacter = '#'; 40 | settings.otherCommentCharacter2 = '\''; 41 | settings.otherLineComments = true; 42 | settings.proofSymbols = false; 43 | settings.signedNumbers = true; 44 | settings.simpleFloatSpecials = true; 45 | settings.singleQuotedStrings = true; 46 | settings.falseSymbols.insert("true"); 47 | settings.falseSymbols.insert("on"); 48 | settings.falseSymbols.insert("1"); 49 | 50 | return settings; 51 | } 52 | 53 | TextOutputStream::Settings 54 | Serializable::initConfigWriteSettings() 55 | { 56 | TextOutputStream::Settings settings; 57 | settings.allowWordWrapInsideDoubleQuotes = true; 58 | settings.convertNewlines = true; 59 | settings.falseSymbol = "false"; 60 | 61 | #ifdef THEA_WINDOWS 62 | settings.newlineStyle = TextOutputStream::NewlineStyle::WINDOWS; 63 | #else 64 | settings.newlineStyle = TextOutputStream::NewlineStyle::UNIX; 65 | #endif 66 | 67 | settings.numColumns = 8; 68 | settings.spacesPerIndent = 4; 69 | settings.trueSymbol = "true"; 70 | settings.wordWrap = TextOutputStream::WordWrap::NONE; 71 | 72 | return settings; 73 | } 74 | 75 | } // namespace Thea 76 | -------------------------------------------------------------------------------- /Code/Source/Set.hpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2011 12 | // 13 | //============================================================================ 14 | 15 | #ifndef __Thea_Set_hpp__ 16 | #define __Thea_Set_hpp__ 17 | 18 | #include "Platform.hpp" 19 | #include 20 | 21 | namespace Thea { 22 | 23 | /** Set of objects. Requires an ordering on the objects. */ 24 | template < typename T, 25 | typename Compare = std::less, 26 | typename Alloc = std::allocator 27 | > using Set = std::set; 28 | 29 | /** Set of objects, with possible duplication. Requires an ordering on the objects. */ 30 | template < typename T, 31 | typename Compare = std::less, 32 | typename Alloc = std::allocator 33 | > using MultiSet = std::multiset; 34 | 35 | } // namespace Thea 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /Code/Source/SparseMatVec.hpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2019 12 | // 13 | //============================================================================ 14 | 15 | #ifndef __Thea_SparseMatVec_hpp__ 16 | #define __Thea_SparseMatVec_hpp__ 17 | 18 | #include "Common.hpp" 19 | #include "MatrixFormat.hpp" 20 | 21 | #pragma clang diagnostic push 22 | #pragma clang diagnostic ignored "-Wunused-but-set-variable" 23 | # include 24 | #pragma clang diagnostic pop 25 | 26 | namespace Thea { 27 | 28 | #ifdef THEA_SPARSE_ROW_MAJOR 29 | int const DEFAULT_SPARSE_MATRIX_LAYOUT = MatrixLayout::ROW_MAJOR; 30 | #else // nothing provided or THEA_SPARSE_COLUMN_MAJOR defined 31 | int const DEFAULT_SPARSE_MATRIX_LAYOUT = MatrixLayout::COLUMN_MAJOR; 32 | #endif 33 | 34 | /** 35 | * General 2D sparse matrix template, alias for Eigen::SparseMatrix with a custom default layout (row or column 36 | * major). 37 | */ 38 | template 41 | using SparseMatrix = Eigen::SparseMatrix; 42 | 43 | /** 2D sparse column matrix template, alias for Eigen::SparseMatrix with Eigen::ColMajor. */ 44 | template 46 | using SparseColumnMatrix = Eigen::SparseMatrix; 47 | 48 | /** 2D sparse row matrix template, alias for Eigen::SparseMatrix with Eigen::RowMajor. */ 49 | template 51 | using SparseRowMatrix = Eigen::SparseMatrix; 52 | 53 | /** 54 | * General 1D sparse vector template, alias for Eigen::SparseVector with a custom default layout (row or column 55 | * major). 56 | */ 57 | template 60 | using SparseVector = Eigen::SparseVector; 61 | 62 | /** 1D sparse column vector template, alias for Eigen::SparseVector with Eigen::ColMajor. */ 63 | template 65 | using SparseColumnVector = Eigen::SparseVector; 66 | 67 | /** 1D sparse row vector template, alias for Eigen::SparseVector with Eigen::RowMajor. */ 68 | template 70 | using SparseRowVector = Eigen::SparseVector; 71 | 72 | } // namespace Thea 73 | 74 | #include "MatrixUtil.hpp" 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /Code/Source/Spinlock.hpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2013 12 | // 13 | //============================================================================ 14 | 15 | #ifndef __Thea_Spinlock_hpp__ 16 | #define __Thea_Spinlock_hpp__ 17 | 18 | #include 19 | 20 | namespace Thea { 21 | 22 | /** 23 | * A simple lock that can be shared by multiple threads for synchronization. Busy-waits for a lock, and unlocks immediately. 24 | * Implemented with a single atomic flag. 25 | */ 26 | class THEA_API Spinlock 27 | { 28 | public: 29 | /** Constructor. The object is initially unlocked. */ 30 | Spinlock() 31 | { 32 | flag.clear(); 33 | } 34 | 35 | /** 36 | * Acquire the lock by atomically setting the value of an integer to non-zero, busy-waiting until the lock is obtained. 37 | * 38 | * @see unlock() 39 | */ 40 | void lock() 41 | { 42 | while (flag.test_and_set(std::memory_order_acquire)) {} 43 | } 44 | 45 | /** 46 | * Release the lock by atomically setting the value of an integer to zero. This operation is immediate and does not wait. 47 | * 48 | * @see unlock() 49 | */ 50 | void unlock() 51 | { 52 | flag.clear(std::memory_order_release); 53 | } 54 | 55 | private: 56 | std::atomic_flag flag; 57 | 58 | }; // class Spinlock 59 | 60 | } // namespace Thea 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /Code/Source/Stack.hpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2011 12 | // 13 | //============================================================================ 14 | 15 | #ifndef __Thea_Stack_hpp__ 16 | #define __Thea_Stack_hpp__ 17 | 18 | #include "Platform.hpp" 19 | #include 20 | #include 21 | 22 | /** Last-in-first-out stack of objects. */ 23 | template < typename T, typename Container = std::deque > using Stack = std::stack; 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /Code/Source/Stopwatch.hpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2013 12 | // 13 | //============================================================================ 14 | 15 | /* 16 | ORIGINAL HEADER ([SC] Note: As of Feb 2023, this class has been completely 17 | rewritten to use C++17 standard library functions and remove unused 18 | functionality. Apart from some function signatures, it has no further 19 | connection with G3D.) 20 | 21 | @file Stopwatch.h 22 | 23 | @maintainer Morgan McGuire, http://graphics.cs.williams.edu 24 | 25 | @created 2005-10-05 26 | @edited 2009-05-10 27 | 28 | Copyright 2000-2009, Morgan McGuire. 29 | All rights reserved. 30 | */ 31 | 32 | #ifndef __Thea_Stopwatch_hpp__ 33 | #define __Thea_Stopwatch_hpp__ 34 | 35 | #include "Common.hpp" 36 | #include 37 | 38 | namespace Thea { 39 | 40 | /** Measure duration between calls to tick() and tock(). */ 41 | class THEA_API Stopwatch 42 | { 43 | private: 44 | using Clock = std::chrono::steady_clock; 45 | 46 | Clock::time_point time_start; 47 | double last_duration; 48 | bool in_between; 49 | 50 | public: 51 | /** Constructor. */ 52 | Stopwatch() : last_duration(0), in_between(false) {} 53 | 54 | /** Begin a timing operation. */ 55 | void tick() 56 | { 57 | if (in_between) { throw Error("Stopwatch: tick() called twice in a row"); } 58 | 59 | in_between = true; 60 | time_start = Clock::now(); 61 | } 62 | 63 | /** End a timing operation. */ 64 | void tock() 65 | { 66 | std::chrono::duration secs = Clock::now() - time_start; 67 | last_duration = secs.count(); 68 | 69 | if (!in_between) { throw Error("Stopwatch: tock() called without matching tick()"); } 70 | in_between = false; 71 | } 72 | 73 | /** Duration in seconds between the last tick() and tock() calls. Returns 0 if tick() has never been called. */ 74 | double elapsedTime() const { return last_duration; } 75 | 76 | }; // class Stopwatch 77 | 78 | } // namespace Thea 79 | 80 | #endif 81 | -------------------------------------------------------------------------------- /Code/Source/System.cpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2013 12 | // 13 | //============================================================================ 14 | 15 | #include "System.hpp" 16 | #include 17 | 18 | #ifdef THEA_WINDOWS 19 | # include 20 | #else 21 | # include 22 | #endif 23 | 24 | namespace Thea { 25 | 26 | System::System() 27 | {} 28 | 29 | intx 30 | System::concurrency() 31 | { 32 | intx cc = (intx)std::thread::hardware_concurrency(); 33 | if (cc <= 0) 34 | return 1; // operate in single-threaded mode as fallback 35 | else 36 | return cc; 37 | } 38 | 39 | void 40 | System::sleep(intx ms) 41 | { 42 | #ifdef THEA_WINDOWS 43 | Sleep(static_cast(ms)); 44 | #else 45 | usleep(static_cast(ms * 1000)); 46 | #endif 47 | } 48 | 49 | } // namespace Thea 50 | -------------------------------------------------------------------------------- /Code/Source/System.hpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2013 12 | // 13 | //============================================================================ 14 | 15 | #ifndef __Thea_System_hpp__ 16 | #define __Thea_System_hpp__ 17 | 18 | #include "Common.hpp" 19 | #include 20 | 21 | namespace Thea { 22 | 23 | /** Low-level system information and profiling functions. */ 24 | class THEA_API System 25 | { 26 | public: 27 | /** Get the hardware concurrency (approximate number of thread contexts). */ 28 | static intx concurrency(); 29 | 30 | /** Get the machine endianness. */ 31 | static Endianness endianness() { return Endianness::machine(); } 32 | 33 | /** Pause the current thread for a given number of milliseconds. */ 34 | static void sleep(intx ms); 35 | 36 | /** The time in seconds since Jan 1 1970 midnight. Adjusted for local timezone and daylight savings time. */ 37 | static double time() 38 | { 39 | typedef std::chrono::duration DSecs; 40 | 41 | return std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count(); 42 | } 43 | 44 | private: 45 | /** Constructor. */ 46 | System(); 47 | 48 | /** Singleton instance. */ 49 | static System & instance() { static System s; return s; } 50 | 51 | }; // class System 52 | 53 | } // namespace Thea 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /Code/Source/Test/TestBagOfWords.cpp: -------------------------------------------------------------------------------- 1 | #include "../Algorithms/BagOfWords.hpp" 2 | #include "../MatrixWrapper.hpp" 3 | #include "../MatVec.hpp" 4 | #include "../Random.hpp" 5 | #include "../EnumClass.hpp" 6 | 7 | using namespace std; 8 | using namespace Thea; 9 | using namespace Algorithms; 10 | 11 | bool testBagOfWords(); 12 | 13 | int 14 | main(int argc, char * argv[]) 15 | { 16 | if (!testBagOfWords()) return -1; 17 | 18 | return 0; 19 | } 20 | 21 | bool 22 | testBagOfWords() 23 | { 24 | static intx const NUM_POINT_FEATURES = 100; 25 | static intx const NUM_WORDS = 5; 26 | static intx const NUM_TRAINING_POINTS = 100; 27 | static intx const NUM_TEST_POINTS = 5000; 28 | 29 | Random rng(0x01234567); 30 | 31 | MatrixXd training_points(NUM_TRAINING_POINTS, NUM_POINT_FEATURES); 32 | for (intx i = 0; i < NUM_TRAINING_POINTS; ++i) 33 | for (intx j = 0; j < NUM_POINT_FEATURES; ++j) 34 | training_points(i, j) = rng.uniform01(); 35 | 36 | BagOfWords bow; 37 | bow.train(NUM_WORDS, MatrixWrapper(&training_points)); 38 | 39 | MatrixXd test_points(NUM_TEST_POINTS, NUM_POINT_FEATURES); 40 | for (intx i = 0; i < NUM_TEST_POINTS; ++i) 41 | for (intx j = 0; j < NUM_POINT_FEATURES; ++j) 42 | test_points(i, j) = rng.uniform01(); 43 | 44 | double histogram[NUM_WORDS]; 45 | bow.computeWordFrequencies(MatrixWrapper(&test_points), &histogram[0]); 46 | 47 | THEA_CONSOLE << "Word frequencies = ["; 48 | 49 | for (intx i = 0; i < NUM_WORDS; ++i) 50 | THEA_CONSOLE << " " << histogram[i]; 51 | 52 | THEA_CONSOLE << " ]"; 53 | 54 | return true; 55 | } 56 | -------------------------------------------------------------------------------- /Code/Source/Test/TestBezier.cpp: -------------------------------------------------------------------------------- 1 | #include "../BezierN.hpp" 2 | 3 | using namespace std; 4 | using namespace Thea; 5 | 6 | int 7 | main(int argc, char * argv[]) 8 | { 9 | BezierN<3, Real> b(3); 10 | 11 | b.setControl(0, Vector3(0, 0, 0)); 12 | b.setControl(1, Vector3(1, 0, 0)); 13 | b.setControl(2, Vector3(1, 1, 0)); 14 | b.setControl(3, Vector3(2, 1, 0)); 15 | 16 | THEA_CONSOLE << "b(0.0) = " << toString(b.getPoint(0.0)); 17 | THEA_CONSOLE << "b(0.5) = " << toString(b.getPoint(0.5)); 18 | THEA_CONSOLE << "b(1.0) = " << toString(b.getPoint(1.0)); 19 | 20 | Array even_p(10); 21 | Array even_u(10); 22 | b.getEvenlySpacedPoints(10, &even_p[0], &even_u[0]); 23 | THEA_CONSOLE << "even = ["; 24 | for (size_t i = 0; i < even_p.size(); ++i) 25 | THEA_CONSOLE << " " << toString(even_p[i]) << ", " << even_u[i] << (i < even_p.size() - 1 ? "," : ""); 26 | THEA_CONSOLE << "];"; 27 | 28 | THEA_CONSOLE << "tangents = ["; 29 | for (size_t i = 0; i < even_u.size(); ++i) 30 | { 31 | Vector3 t = b.getTangent(even_u[i]); 32 | THEA_CONSOLE << " " << toString(t) << (i < even_p.size() - 1 ? "," : ""); 33 | } 34 | THEA_CONSOLE << "];"; 35 | 36 | THEA_CONSOLE << "normals = ["; 37 | for (size_t i = 0; i < even_u.size(); ++i) 38 | { 39 | Vector3 n = b.getNormal(even_u[i]); 40 | THEA_CONSOLE << " " << toString(n) << (i < even_p.size() - 1 ? "," : ""); 41 | } 42 | THEA_CONSOLE << "];"; 43 | 44 | THEA_CONSOLE << "binormals = ["; 45 | for (size_t i = 0; i < even_u.size(); ++i) 46 | { 47 | Vector3 bn = b.getBinormal(even_u[i]); 48 | THEA_CONSOLE << " " << toString(bn) << (i < even_p.size() - 1 ? "," : ""); 49 | } 50 | THEA_CONSOLE << "];"; 51 | 52 | static Vector3 const d[] = { 53 | Vector3(0.0, 0.0, 0.0), 54 | Vector3(0.0, 0.5, 0.0), 55 | Vector3(1.1, 1.4, 0.0), 56 | Vector3(2.1, 1.6, 0.0), 57 | Vector3(3.2, 1.1, 0.0), 58 | Vector3(4.0, 0.2, 0.0), 59 | Vector3(4.0, 0.0, 0.0), 60 | }; 61 | static size_t const dsize = sizeof(d) / sizeof(Vector3); 62 | 63 | Array u(dsize); 64 | 65 | for (int reparam_iters = 0; reparam_iters <= 10; ++reparam_iters) 66 | { 67 | if (reparam_iters == 10) 68 | reparam_iters = 100; 69 | 70 | double sqerr = b.fitToPoints(&d[0], &d[0] + dsize, nullptr, &u[0], true, reparam_iters); 71 | THEA_CONSOLE << "sqerr" << reparam_iters << " = " << sqerr << ';'; 72 | 73 | THEA_CONSOLE << "points" << reparam_iters << " = ["; 74 | for (long i = 0; i < b.numControls(); ++i) 75 | { 76 | Vector3 c = b.getControl(i); 77 | THEA_CONSOLE << " " << toString(c) << (i < b.numControls() - 1 ? "," : ""); 78 | } 79 | THEA_CONSOLE << "];"; 80 | } 81 | 82 | b.getEvenlySpacedPoints(10, &even_p[0], &even_u[0]); 83 | THEA_CONSOLE << "even = ["; 84 | for (size_t i = 0; i < even_p.size(); ++i) 85 | THEA_CONSOLE << " " << toString(even_p[i]) << ", " << even_u[i] << (i < even_p.size() - 1 ? "," : ""); 86 | THEA_CONSOLE << "];"; 87 | 88 | return 0; 89 | } 90 | -------------------------------------------------------------------------------- /Code/Source/Test/TestIterators.cpp: -------------------------------------------------------------------------------- 1 | #include "../Algorithms/Iterators.hpp" 2 | #include 3 | 4 | using namespace std; 5 | using namespace Thea; 6 | using namespace Algorithms; 7 | 8 | int 9 | main(int argc, char * argv[]) 10 | { 11 | int a = 1, b = 2, c = 3; 12 | vector ivec; ivec.push_back(a); 13 | vector ipvec; ipvec.push_back(&b); 14 | vector ipcvec; ipcvec.push_back(&c); 15 | 16 | auto i1 = makeRefIterator(ivec.begin()); 17 | auto i2 = makeRefIterator(ipvec.begin()); 18 | auto i3 = makeRefIterator(ipcvec.begin()); 19 | 20 | auto i4 = makePtrIterator(ivec.begin()); 21 | auto i5 = makePtrIterator(ipvec.begin()); 22 | auto i6 = makePtrIterator(ipcvec.begin()); 23 | 24 | auto i7 = makeRefIterator(&ivec[0]); 25 | auto i8 = makeRefIterator(&ipvec[0]); 26 | auto i9 = makeRefIterator((int const * const *)&ipcvec[0]); 27 | 28 | auto i10 = makePtrIterator(&ivec[0]); 29 | auto i11 = makePtrIterator(&ipvec[0]); 30 | auto i12 = makePtrIterator((int const * const *)&ipcvec[0]); 31 | 32 | // All should print "1 2 3" 33 | THEA_CONSOLE << *i1 << " " << *i2 << " " << *i3; 34 | THEA_CONSOLE << **i4 << " " << **i5 << " " << **i6; 35 | THEA_CONSOLE << *i7 << " " << *i8 << " " << *i9; 36 | THEA_CONSOLE << **i10 << " " << **i11 << " " << **i12; 37 | 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /Code/Source/Test/TestPCA.cpp: -------------------------------------------------------------------------------- 1 | #include "../Algorithms/PcaN.hpp" 2 | #include "../Algorithms/SparsePcaN.hpp" 3 | #include "../Algorithms/PointTraitsN.hpp" 4 | #include "../Common.hpp" 5 | #include "../Math.hpp" 6 | #include "../MatVec.hpp" 7 | #include 8 | 9 | using namespace std; 10 | using namespace Thea; 11 | using namespace Algorithms; 12 | 13 | bool testPCA(); 14 | 15 | int 16 | main(int argc, char * argv[]) 17 | { 18 | if (!testPCA()) return -1; 19 | 20 | return 0; 21 | } 22 | 23 | bool 24 | testPCA() 25 | { 26 | static intx const DATA_SIZE = 10; 27 | Vector3 data[DATA_SIZE]; 28 | cout << "Data vectors:" << endl; 29 | for (intx i = 0; i < DATA_SIZE; ++i) 30 | { 31 | data[i] = Vector3(rand() / (Real)RAND_MAX, 32 | rand() / (Real)RAND_MAX, 33 | rand() / (Real)RAND_MAX); 34 | 35 | cout << " " << data[i] << endl; 36 | } 37 | 38 | //========================================================================================================================== 39 | // PCA 40 | //========================================================================================================================== 41 | 42 | Vector3 axes[3], centroid; 43 | Real vars[3]; 44 | PcaN::compute(&data[0], &data[DATA_SIZE], vars, axes, ¢roid); 45 | 46 | cout << "\nPrincipal axes = " << endl; 47 | for (intx i = 0; i < 3; ++i) 48 | cout << " " << axes[i] << " (variance = " << vars[i] << ')' << endl; 49 | cout << "Centroid = " << centroid << endl; 50 | 51 | for (intx i = 0; i < 3; ++i) 52 | { 53 | intx j = (i + 1) % 3; 54 | cout << i << " x " << j << " = " << toString(axes[i].cross(axes[j])) << endl; 55 | } 56 | 57 | //========================================================================================================================== 58 | // Sparse PCA 59 | //========================================================================================================================== 60 | 61 | SparsePcaN::compute(&data[0], &data[DATA_SIZE], vars, axes, ¢roid); 62 | 63 | cout << "\nSparse principal axes = " << endl; 64 | for (intx i = 0; i < 3; ++i) 65 | cout << " " << axes[i] << " (variance = " << vars[i] << ')' << endl; 66 | cout << "Centroid = " << centroid << endl; 67 | 68 | for (intx i = 0; i < 3; ++i) 69 | { 70 | intx j = (i + 1) % 3; 71 | cout << i << " x " << j << " = " << toString(axes[i].cross(axes[j])) << endl; 72 | } 73 | 74 | return true; 75 | } 76 | -------------------------------------------------------------------------------- /Code/Source/Test/TestPyramidMatch.cpp: -------------------------------------------------------------------------------- 1 | #include "../Common.hpp" 2 | #include "../Algorithms/PyramidMatch.hpp" 3 | #include 4 | 5 | using namespace std; 6 | using namespace Thea; 7 | using namespace Algorithms; 8 | 9 | int 10 | main(int argc, char * argv[]) 11 | { 12 | try 13 | { 14 | PyramidMatch::test(); 15 | } 16 | THEA_CATCH(return -1;, ERROR, "%s", "An error occurred") 17 | 18 | // Hooray, all tests passed 19 | cout << "PyramidMatch: Test completed" << endl; 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /Code/Source/Test/TestZernike.cpp: -------------------------------------------------------------------------------- 1 | #include "../Common.hpp" 2 | #include "../Array.hpp" 3 | #include "../Image.hpp" 4 | #include "../ImageMatrix.hpp" 5 | #include "../Math.hpp" 6 | #include "../MatVec.hpp" 7 | #include "../Algorithms/Zernike2.hpp" 8 | #include 9 | #include 10 | 11 | using namespace std; 12 | using namespace Thea; 13 | using namespace Algorithms; 14 | 15 | template 16 | int 17 | zernike(ImageMatrix const & m) 18 | { 19 | Zernike2 zernike; 20 | Zernike2::MomentMatrix<3, Real> moments; 21 | zernike.compute(m, 0.5 * (m.cols() - 1), 0.5 * (m.rows() - 1), 22 | 0.5 * sqrt(Math::square(m.cols()) + Math::square(m.rows())), moments); 23 | 24 | for (intx i = 0; i < moments.cols(); ++i) 25 | THEA_CONSOLE<< "Moment magnitude [" << i << "] = " << moments.col(i).norm(); 26 | 27 | return 0; 28 | } 29 | 30 | int 31 | main(int argc, char * argv[]) 32 | { 33 | try 34 | { 35 | if (argc < 2) 36 | { 37 | cerr << "Usage: " << argv[0] << " " << endl; 38 | return 0; 39 | } 40 | 41 | Image image(argv[1]); 42 | switch (image.getType()) 43 | { 44 | case Image::Type::LUMINANCE_8U: 45 | return zernike(ImageMatrix(&image)); 46 | 47 | case Image::Type::RGB_8U: 48 | return zernike(ImageMatrix(&image)); 49 | 50 | case Image::Type::RGBA_8U: 51 | return zernike(ImageMatrix(&image)); 52 | 53 | default: 54 | cerr << "Unsupported image format" << endl; 55 | return -1; 56 | } 57 | } 58 | THEA_CATCH(return -1;, ERROR, "%s", "An error occurred") 59 | 60 | cout << "Zernike: Test completed" << endl; 61 | return 0; 62 | } 63 | -------------------------------------------------------------------------------- /Code/Source/ThirdParty/arpackpp/arch.h: -------------------------------------------------------------------------------- 1 | /* 2 | ARPACK++ v1.2 2/20/2000 3 | c++ interface to ARPACK code. 4 | 5 | MODULE arch.h 6 | Modified version of arch.h (from LAPACK++ 1.1). 7 | Machine dependent functions and variable types. 8 | 9 | ARPACK Authors 10 | Richard Lehoucq 11 | Danny Sorensen 12 | Chao Yang 13 | Dept. of Computational & Applied Mathematics 14 | Rice University 15 | Houston, Texas 16 | */ 17 | 18 | 19 | #ifndef ARCH_H 20 | #define ARCH_H 21 | 22 | // ARPACK++ arcomplex type definition. 23 | // If you are not using g++ (or CC) and also are not intending 24 | // use complex variables, comment out the following line. 25 | 26 | #include "arcomp.h" 27 | 28 | // STL vector class. 29 | // If the Standard Template Library is not available at your system 30 | // and you do not want to install it, comment out the following line. 31 | 32 | #include 33 | 34 | // If your STL vector class defines a variable other than 35 | // __SGI_STL_VECTOR_H, please change this variable name 36 | // in the ifdef command below. 37 | 38 | #ifdef __SGI_STL_VECTOR_H 39 | #define STL_VECTOR_H 40 | #endif 41 | 42 | // UMFPACK parameters. 43 | // These parameters are used by UMFPACK library functions. Normally 44 | // they are not modified by the user. To use the default value, set 45 | // the parameter to zero. For a complete description of all UMFPACK 46 | // parameters, see the library documentation. 47 | 48 | #define UICNTL7 0 // icntl(7). Block size for the blas (machine-dependent). 49 | #define UICNTL5 0 // icntl(5). Number of columns to examine during pivot search. 50 | #define UCNTL2 0 // cntl(2). Amalgamation parameter. 51 | #define UKEEP7 0 // keep(7). Absolute number of elements a column must have 52 | // to be considered "dense". 53 | #define UKEEP8 0 // keep(8). Relative number of elements a column must have 54 | // to be considered "dense". Dense columns have more 55 | // than max{0,UMFABDEN,UMFREDEN*sqrt(n)} elements. 56 | 57 | // Line length used when reading a dense matrix from a file. 58 | 59 | #define LINELEN 256 60 | 61 | // Linkage names between C, C++, and Fortran (platform dependent) 62 | 63 | #if defined(RIOS) && !defined(CLAPACK) 64 | #define F77NAME(x) x 65 | #else 66 | // #include 67 | // #define F77NAME(x) name2(x,_) 68 | #define F77NAME(x) x ## _ 69 | #endif 70 | 71 | #if defined(SGI) && !defined(SGI_DEC) 72 | #define SGI_DEC 73 | 74 | extern "C" { 75 | void mkidxname() {} 76 | void mkdatname() {} 77 | } 78 | #endif 79 | 80 | 81 | // Type conversion. 82 | 83 | typedef int ARint; 84 | typedef int ARlogical; 85 | 86 | #ifdef __SUNPRO_CC 87 | 88 | typedef int bool; 89 | int true = 1; 90 | int false = 0; 91 | 92 | #endif 93 | 94 | // SC: Squash "deprecated conversion from string constant to char*" warnings 95 | #include 96 | #define APP_C_STR( text ) (const_cast(std::string( text ).c_str())) 97 | 98 | #endif // ARCH_H 99 | -------------------------------------------------------------------------------- /Code/Source/ThirdParty/arpackpp/arcomp.h: -------------------------------------------------------------------------------- 1 | /* 2 | ARPACK++ v1.2 2/20/2000 3 | c++ interface to ARPACK code. 4 | 5 | MODULE arcomp.h 6 | arcomplex complex type definition. 7 | 8 | ARPACK Authors 9 | Richard Lehoucq 10 | Danny Sorensen 11 | Chao Yang 12 | Dept. of Computational & Applied Mathematics 13 | Rice University 14 | Houston, Texas 15 | */ 16 | 17 | #ifndef ARCOMP_H 18 | #define ARCOMP_H 19 | 20 | #include 21 | 22 | #ifdef __GNUG__ 23 | 24 | #define arcomplex std::complex 25 | 26 | #endif 27 | 28 | #if defined(__SUNPRO_CC) || defined(__sgi) 29 | 30 | template 31 | class arcomplex: public complex 32 | { 33 | public: 34 | 35 | arcomplex(ARFLOAT x, ARFLOAT y): complex(x,y) { } 36 | arcomplex(): complex() { } 37 | arcomplex(complex x): complex(x) { } 38 | 39 | }; 40 | 41 | #endif 42 | 43 | #endif // ARCOMP_H 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /Code/Source/ThirdParty/arpackpp/armat.h: -------------------------------------------------------------------------------- 1 | /* 2 | ARPACK++ v1.2 2/20/2000 3 | c++ interface to ARPACK code. 4 | 5 | MODULE ARMat.h 6 | Generic matrix template with a matrix-vector product. 7 | 8 | ARPACK Authors 9 | Richard Lehoucq 10 | Danny Sorensen 11 | Chao Yang 12 | Dept. of Computational & Applied Mathematics 13 | Rice University 14 | Houston, Texas 15 | */ 16 | 17 | #ifndef ARMAT_H 18 | #define ARMAT_H 19 | 20 | template 21 | class ARMatrix { 22 | 23 | protected: 24 | 25 | int m, n; // Number of rows and columns. 26 | bool defined; 27 | 28 | public: 29 | 30 | ARMatrix() { defined = false; } 31 | // Short constructor. 32 | 33 | ARMatrix(int nrows, int ncols = 0) 34 | // Long constructor. 35 | { 36 | m = nrows; 37 | n = (ncols?ncols:nrows); 38 | defined = false; 39 | } // Constructor. 40 | 41 | virtual ~ARMatrix() { } 42 | // Destructor. 43 | 44 | int nrows() { return m; } 45 | 46 | int ncols() { return n; } 47 | 48 | bool IsDefined() { return defined; } 49 | 50 | virtual void MultMv(ARTYPE* v, ARTYPE* w) = 0; 51 | // Matrix-vector product: w = A*v. 52 | 53 | }; // ARMatrix. 54 | 55 | #endif // ARMAT_H 56 | 57 | -------------------------------------------------------------------------------- /Code/Source/ThirdParty/arpackpp/arrgeig.h: -------------------------------------------------------------------------------- 1 | /* 2 | ARPACK++ v1.2 2/20/2000 3 | c++ interface to ARPACK code. 4 | 5 | MODULE ARRGEig.h. 6 | Arpack++ class ARrcGenEig definition. 7 | Derived from ARrcStdEig, this class implements the 8 | reverse communication interface for generalized problems. 9 | 10 | ARPACK Authors 11 | Richard Lehoucq 12 | Danny Sorensen 13 | Chao Yang 14 | Dept. of Computational & Applied Mathematics 15 | Rice University 16 | Houston, Texas 17 | */ 18 | 19 | #ifndef ARRGEIG_H 20 | #define ARRGEIG_H 21 | 22 | #include "arch.h" 23 | #include "arerror.h" 24 | #include "arrseig.h" 25 | 26 | // ARrcGenEig class definition. 27 | 28 | template 29 | class ARrcGenEig: virtual public ARrcStdEig { 30 | 31 | public: 32 | 33 | // a) Public functions: 34 | 35 | // a.1) Functions that allow changes in problem parameters. 36 | 37 | void NoShift(); 38 | // Turns the problem to regular mode. 39 | 40 | 41 | // a.2) Constructors and destructor. 42 | 43 | ARrcGenEig(); 44 | // Short constructor that does almost nothing. 45 | 46 | ARrcGenEig(const ARrcGenEig& other) { Copy(other); } 47 | // Copy constructor. 48 | 49 | virtual ~ARrcGenEig() { } 50 | // Destructor (presently meaningless). 51 | 52 | // b) Operators. 53 | 54 | ARrcGenEig& operator=(const ARrcGenEig& other); 55 | // Assignment operator. 56 | 57 | }; // class ARrcGenEig. 58 | 59 | 60 | // ------------------------------------------------------------------------ // 61 | // ARrcGenEig member functions definition. // 62 | // ------------------------------------------------------------------------ // 63 | 64 | 65 | template 66 | inline void ARrcGenEig::NoShift() 67 | { 68 | 69 | this->sigmaR = (ARTYPE)0; 70 | this->sigmaI = 0.0; 71 | this->mode = 2; 72 | this->iparam[7] = this->mode; 73 | this->Restart(); 74 | 75 | } // NoShift. 76 | 77 | 78 | template 79 | inline ARrcGenEig::ARrcGenEig() 80 | { 81 | 82 | this->bmat = 'G'; // This is a generalized problem. 83 | this->NoShift(); 84 | 85 | } // Short constructor. 86 | 87 | 88 | template 89 | ARrcGenEig& ARrcGenEig:: 90 | operator=(const ARrcGenEig& other) 91 | { 92 | 93 | if (this != &other) { // Stroustrup suggestion. 94 | this->ClearMem(); 95 | Copy(other); 96 | } 97 | return *this; 98 | 99 | } // operator=. 100 | 101 | 102 | #endif // ARRGEIG_H 103 | 104 | -------------------------------------------------------------------------------- /Code/Source/ThirdParty/dx/dx.h: -------------------------------------------------------------------------------- 1 | /***********************************************************************/ 2 | /* Open Visualization Data Explorer */ 3 | /* (C) Copyright IBM Corp. 1989,1999 */ 4 | /* ALL RIGHTS RESERVED */ 5 | /* This code licensed under the */ 6 | /* "IBM PUBLIC LICENSE - Open Visualization Data Explorer" */ 7 | /**************intelnt*********************************************************/ 8 | 9 | 10 | #ifndef _LIBDX_H 11 | #define _LIBDX_H 12 | 13 | #ifdef _MSC_VER 14 | # define libdx_intelnt 1 15 | #elif defined(__FreeBSD__) 16 | # define libdx_freebsd 1 17 | # define HAVE_SYS_BSD_TYPES_H 18 | #elif defined(__OpenBSD__) 19 | # define libdx_openbsd 1 20 | # define libdx_freebsd 1 21 | # define HAVE_SYS_BSD_TYPES_H 22 | #elif defined(__linux__) 23 | # define libdx_linux 1 24 | # define HAVE_SYS_TYPES_H 25 | #elif defined(__APPLE__) 26 | # define libdx_macos 1 27 | # define HAVE_SYS_TYPES_H 28 | #endif 29 | 30 | #include "error.h" 31 | #include "memory.h" 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /Code/Source/ThirdParty/dx/error.h: -------------------------------------------------------------------------------- 1 | /***********************************************************************/ 2 | /* Open Visualization Data Explorer */ 3 | /* (C) Copyright IBM Corp. 1989,1999 */ 4 | /* ALL RIGHTS RESERVED */ 5 | /* This code licensed under the */ 6 | /* "IBM PUBLIC LICENSE - Open Visualization Data Explorer" */ 7 | /***********************************************************************/ 8 | 9 | 10 | /* TeX starts here. Do not remove this comment. */ 11 | 12 | #ifndef _DXI_ERROR_H_ 13 | #define _DXI_ERROR_H_ 14 | 15 | #if defined(__cplusplus) || defined(c_plusplus) 16 | extern "C" { 17 | #endif 18 | 19 | /* 20 | \section{Error handling} 21 | \label{errorsec} 22 | 23 | In general, the routines in the Data Explorer library return either a 24 | pointer, such as an object reference, or an integer error indication. 25 | Success is indicated by returning a non-null pointer or by returning 26 | the non-zero integer constant {\tt OK}. Failure is indicated by 27 | returning {\tt NULL}, or by returning {\tt ERROR} (which is defined to 28 | be zero). 29 | 30 | In case of failure, the library routine may have set the error code by 31 | calling {\tt DXSetError()}, in which case the calling routine generally 32 | should just return {\tt NULL} or {\tt ERROR} to propagate the error 33 | up. On the other hand, the library routine may not have set the error 34 | code. In this case it is up to the calling routine to decide whether 35 | the null return indicates an error, in which case the calling routine 36 | should set the error code by calling {\tt DXSetError()}, and then return 37 | {\tt NULL} or {\tt ERROR}; or whether the null return was not an 38 | error, in which case the calling routine should proceed. This manual 39 | documents for each routine whether it sets the error code when it 40 | returns null. 41 | 42 | The error codes are defined as follows: \index{errorcodes} 43 | */ 44 | 45 | typedef enum errorcode { 46 | ERROR_NONE, 47 | ERROR_INTERNAL, 48 | ERROR_UNEXPECTED, 49 | ERROR_ASSERTION, 50 | ERROR_NOT_IMPLEMENTED, 51 | ERROR_NO_MEMORY, 52 | ERROR_BAD_CLASS, 53 | ERROR_BAD_TYPE, 54 | ERROR_NO_CAMERA, 55 | ERROR_MISSING_DATA, 56 | ERROR_DATA_INVALID, 57 | ERROR_BAD_PARAMETER, 58 | ERROR_NO_HARDWARE_RENDERING, 59 | ERROR_MAX 60 | } ErrorCode; 61 | 62 | typedef int Error; 63 | #ifndef ERROR 64 | #define ERROR 0 65 | #endif 66 | #ifndef OK 67 | #define OK 1 68 | #endif 69 | 70 | typedef void *Pointer; 71 | 72 | #ifndef NULL 73 | #define NULL 0 74 | #endif 75 | 76 | #if defined(__cplusplus) || defined(c_plusplus) 77 | } 78 | #endif 79 | 80 | #endif /* _DXI_ERROR_H_ */ 81 | -------------------------------------------------------------------------------- /Code/Source/ThirdParty/miniball/Seb_point.h: -------------------------------------------------------------------------------- 1 | // Synopsis: Simple point class 2 | // 3 | // Authors: Martin Kutz , 4 | // Kaspar Fischer 5 | 6 | #ifndef SEB_POINT_H 7 | #define SEB_POINT_H 8 | 9 | #include "Seb_configure.h" 10 | 11 | namespace SEB_NAMESPACE { 12 | 13 | template 14 | class Point 15 | // A simple class representing a d-dimensional point. 16 | { 17 | public: // types: 18 | typedef Float const * Const_iterator; 19 | typedef Float * Iterator; 20 | 21 | public: // construction and destruction: 22 | 23 | Point() 24 | // Constructs a d-dimensional point with undefined coordinates. 25 | { 26 | } 27 | 28 | template 29 | Point(InputIterator first) 30 | // Constructs a d-dimensional point with Cartesian center 31 | // coordinates [first,first+d). 32 | { 33 | for (unsigned int i = 0; i < D; ++i, ++first) 34 | c[i] = *first; 35 | } 36 | 37 | public: // access: 38 | 39 | const Float& operator[](unsigned int i) const 40 | // Returns a const-reference to the i-th coordinate. 41 | { 42 | SEB_ASSERT(0 <= i && i < D); 43 | return c[i]; 44 | } 45 | 46 | Float& operator[](unsigned int i) 47 | // Returns a reference to the i-th coordinate. 48 | { 49 | SEB_ASSERT(0 <= i && i < D); 50 | return c[i]; 51 | } 52 | 53 | Const_iterator begin() const 54 | // Returns a const-iterator to the first of the d Cartesian coordinates. 55 | { 56 | return c.begin(); 57 | } 58 | 59 | Const_iterator end() const 60 | // Returns the past-the-end iterator corresponding to begin(). 61 | { 62 | return c.end(); 63 | } 64 | 65 | unsigned int dims() const 66 | // Returns the number of dimensions of the point 67 | { 68 | return D; 69 | } 70 | 71 | private: // member fields: 72 | Float c[D]; // Cartesian center coordinates 73 | }; 74 | 75 | } // namespace SEB_NAMESPACE 76 | 77 | #endif // SEB_POINT_H 78 | -------------------------------------------------------------------------------- /Code/Source/Tools/Browse3D/Common.hpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2011 12 | // 13 | //============================================================================ 14 | 15 | #ifndef __Browse3D_Common_hpp__ 16 | #define __Browse3D_Common_hpp__ 17 | 18 | #include "../../Common.hpp" 19 | #include "../../Colors.hpp" 20 | #include 21 | 22 | // Forward declarations 23 | class wxPoint; 24 | class wxRealPoint; 25 | class wxKeyEvent; 26 | class wxMouseEvent; 27 | class wxSizeEvent; 28 | 29 | /** Namespace for 3D file browser project. */ 30 | namespace Browse3D { 31 | 32 | using namespace Thea; 33 | 34 | /** A dummy event that is a default argument for callbacks. */ 35 | extern wxCommandEvent DUMMY_EVENT; 36 | 37 | } // namespace Browse3D 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /Code/Source/Tools/Browse3D/MeshFwd.hpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2011 12 | // 13 | //============================================================================ 14 | 15 | #ifndef __Browse3D_MeshFwd_hpp__ 16 | #define __Browse3D_MeshFwd_hpp__ 17 | 18 | #include "Common.hpp" 19 | 20 | namespace Thea { 21 | namespace Graphics { 22 | 23 | // Forward declarations 24 | struct NullAttribute; 25 | 26 | template class Alloc> class GeneralMeshVertex; 27 | template class Alloc> class GeneralMeshFace; 28 | template class MeshGroup; 29 | 30 | } // namespace Graphics 31 | } // namespace Thea 32 | 33 | namespace Browse3D { 34 | 35 | // Forward declarations 36 | class VertexAttribute; 37 | class FaceAttribute; 38 | class Mesh; 39 | 40 | /**< Handle to a mesh vertex. */ 41 | typedef Graphics::GeneralMeshVertex MeshVertex; 42 | 43 | /**< Handle to a mesh face. */ 44 | typedef Graphics::GeneralMeshFace MeshFace; 45 | 46 | typedef Graphics::MeshGroup MeshGroup; ///< A hierarchical group of meshes. 47 | typedef std::shared_ptr MeshPtr; ///< A shared pointer to a mesh. 48 | typedef std::shared_ptr MeshConstPtr; ///< A shared pointer to an immutable mesh. 49 | typedef std::shared_ptr MeshGroupPtr; ///< A shared pointer to a group of meshes. 50 | typedef std::shared_ptr MeshGroupConstPtr; ///< A shared pointer to an immutable group of meshes. 51 | 52 | } // namespace Browse3D 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /Code/Source/Tools/Browse3D/Segment.hpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2015 12 | // 13 | //============================================================================ 14 | 15 | #ifndef __Browse3D_Segment_hpp__ 16 | #define __Browse3D_Segment_hpp__ 17 | 18 | #include "Common.hpp" 19 | #include "MeshFwd.hpp" 20 | #include "../../UnorderedSet.hpp" 21 | 22 | namespace Browse3D { 23 | 24 | /** A labeled segment. */ 25 | class Segment 26 | { 27 | public: 28 | typedef UnorderedSet MeshSet; ///< A set of meshes 29 | 30 | /** Default constructor. */ 31 | Segment() : label("AnonymousSegment") {} 32 | 33 | /** Create a segment with the given label. */ 34 | Segment(std::string const & label_) : label(label_) {} 35 | 36 | /** Get the segment label. */ 37 | std::string const & getLabel() const { return label; } 38 | 39 | /** Set the segment label. */ 40 | void setLabel(std::string const & label_) { label = label_; } 41 | 42 | /** Get the number of meshes in the segment. */ 43 | intx numMeshes() const { return (intx)meshes.size(); } 44 | 45 | /** Get the set of meshes. */ 46 | MeshSet const & getMeshes() const { return meshes; } 47 | 48 | /** Add a mesh to the segment. */ 49 | void addMesh(Mesh * mesh) { meshes.insert(mesh); } 50 | 51 | /** Remove a mesh from the segment. */ 52 | void removeMesh(Mesh const * mesh, intx depth_promotion = 0); 53 | 54 | /** Add a mesh group to the segment. */ 55 | void addMeshGroup(MeshGroup * mg); 56 | 57 | /** Remove a mesh group from the segment. */ 58 | void removeMeshGroup(MeshGroup const * mg); 59 | 60 | /** Check if the (possibly hierarchically expanded) segment contains a given mesh. */ 61 | bool hasMesh(Mesh const * mesh, intx depth_promotion = 0) const; 62 | 63 | /** Get the minimum depth (from the root) of a mesh in the segment. */ 64 | intx minDepth() const; 65 | 66 | /** Clear the segment. */ 67 | void clear() { meshes.clear(); } 68 | 69 | private: 70 | MeshSet meshes; 71 | std::string label; 72 | 73 | }; // class Segment 74 | 75 | } // namespace Browse3D 76 | 77 | #endif 78 | -------------------------------------------------------------------------------- /Code/Source/Tools/GeoSphere/GeoSphere.cpp: -------------------------------------------------------------------------------- 1 | #include "../../Common.hpp" 2 | #include "../../Algorithms/GeodesicSphere3.hpp" 3 | #include "../../Graphics/DisplayMesh.hpp" 4 | #include "../../Graphics/MeshGroup.hpp" 5 | #include 6 | 7 | using namespace std; 8 | using namespace Thea; 9 | using namespace Algorithms; 10 | using namespace Graphics; 11 | 12 | typedef DisplayMesh Mesh; 13 | typedef MeshGroup MG; 14 | 15 | int 16 | usage(int argc, char * argv[]) 17 | { 18 | THEA_CONSOLE << "Usage: " << argv[0] << " <#subdivs> "; 19 | return 0; 20 | } 21 | 22 | int 23 | main(int argc, char * argv[]) 24 | { 25 | if (argc < 3) 26 | return usage(argc, argv); 27 | 28 | long num_subdivs; 29 | if (sscanf(argv[1], " %ld", &num_subdivs) != 1) 30 | { 31 | THEA_ERROR << "Could not parse number of subdivisions"; 32 | return -1; 33 | } 34 | 35 | string out_path = argv[2]; 36 | 37 | Array vertices; 38 | Array triangles; 39 | if (!GeodesicSphere3::compute(num_subdivs, vertices, &triangles)) 40 | return -1; 41 | 42 | Mesh::Ptr mesh(new Mesh); 43 | for (size_t i = 0; i < vertices.size(); ++i) 44 | mesh->addVertex(vertices[i]); 45 | 46 | for (size_t i = 0; i < triangles.size(); i += 3) 47 | mesh->addTriangle(triangles[i], triangles[i + 1], triangles[i + 2]); 48 | 49 | MG mg; 50 | mg.addMesh(mesh); 51 | 52 | try 53 | { 54 | mg.save(out_path); 55 | } 56 | THEA_CATCH(return -1;, ERROR, "Could not save geodesic sphere to '%s'", out_path.c_str()) 57 | 58 | return 0; 59 | } 60 | -------------------------------------------------------------------------------- /Code/Source/Tools/RenderShape/ShapeRenderer.hpp: -------------------------------------------------------------------------------- 1 | #ifndef __Thea_RenderShape_ShapeRenderer__ 2 | #define __Thea_RenderShape_ShapeRenderer__ 3 | 4 | #include "../../Common.hpp" 5 | 6 | using namespace std; 7 | 8 | class ShapeRendererImpl; 9 | 10 | class ShapeRenderer 11 | { 12 | public: 13 | ShapeRenderer(int argc, char * argv[]); // just loads plugins and initializes variables 14 | ~ShapeRenderer(); 15 | 16 | int exec(string const & cmdline); 17 | int exec(int argc, char ** argv); 18 | 19 | private: 20 | ShapeRendererImpl * impl; 21 | 22 | }; // class ShapeRenderer 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /Code/Source/Tools/RenderShape/main.cpp: -------------------------------------------------------------------------------- 1 | #include "ShapeRenderer.hpp" 2 | 3 | int 4 | main(int argc, char * argv[]) 5 | { 6 | ShapeRenderer renderer(argc, argv); 7 | return renderer.exec(argc, argv); 8 | } 9 | -------------------------------------------------------------------------------- /Code/Source/Torus3.hpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2021 12 | // 13 | //============================================================================ 14 | 15 | #ifndef __Thea_Torus3_hpp__ 16 | #define __Thea_Torus3_hpp__ 17 | 18 | #include "Common.hpp" 19 | #include "TorusN.hpp" 20 | 21 | namespace Thea { 22 | 23 | #ifdef THEA_EXPORT_INSTANTIATION 24 | template class THEA_API TorusN<3, Real>; 25 | #endif 26 | 27 | /** The default torus class in real 3-space. */ 28 | typedef TorusN<3, Real> Torus3; 29 | 30 | } // namespace Thea 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /Code/Source/Transformable.hpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2009 12 | // 13 | //============================================================================ 14 | 15 | #ifndef __Thea_Transformable_hpp__ 16 | #define __Thea_Transformable_hpp__ 17 | 18 | #include "Common.hpp" 19 | 20 | namespace Thea { 21 | 22 | /** An object with an associated transformation, stored separately. */ 23 | template 24 | class /* THEA_API */ Transformable 25 | { 26 | public: 27 | THEA_DECL_SMART_POINTERS(Transformable) 28 | 29 | typedef TransformT Transform; ///< The type of transformation. 30 | 31 | /** Destructor. */ 32 | virtual ~Transformable() = 0; 33 | 34 | /** Default constructor. */ 35 | Transformable() : has_trans(false) {} 36 | 37 | /** Constructor. */ 38 | Transformable(Transform const & trans_) : has_trans(true), trans(trans_) {} 39 | 40 | /** Copy constructor. */ 41 | Transformable(Transformable const & src) : has_trans(src.has_trans), trans(src.trans) {} 42 | 43 | /** Check if a transform has been set. */ 44 | bool hasTransform() const { return has_trans; } 45 | 46 | /** Get the transformation, if one has been set. Else, the return value is undefined. */ 47 | Transform const & getTransform() const { return trans; } 48 | 49 | /** Get the transformation, if one has been set. Else, the return value is undefined. */ 50 | Transform & getTransform() { return trans; } 51 | 52 | /** Set the transformation. */ 53 | virtual void setTransform(Transform const & trans_) { has_trans = true; trans = trans_; } 54 | 55 | /** Clear any existing transform. */ 56 | virtual void clearTransform() { has_trans = false; } 57 | 58 | private: 59 | bool has_trans; 60 | TransformT trans; 61 | 62 | }; // Transformable 63 | 64 | template 65 | Transformable::~Transformable() 66 | { 67 | // Pure virtual destructor should have a body 68 | // http://www.linuxtopia.org/online_books/programming_books/thinking_in_c++/Chapter15_024.html 69 | } 70 | 71 | } // namespace Thea 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /Code/Source/UnorderedMap.hpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2011 12 | // 13 | //============================================================================ 14 | 15 | #ifndef __Thea_UnorderedMap_hpp__ 16 | #define __Thea_UnorderedMap_hpp__ 17 | 18 | #include "Platform.hpp" 19 | #include 20 | 21 | namespace Thea { 22 | 23 | /** Hash table-based mapping from keys to values. */ 24 | template < typename Key, 25 | typename T, 26 | typename Hash = std::hash, 27 | typename Pred = std::equal_to, 28 | typename Alloc = std::allocator< std::pair > 29 | > using UnorderedMap = std::unordered_map; 30 | 31 | /** Hash table-based mapping from (possibly duplicate) keys to values. */ 32 | template < typename Key, 33 | typename T, 34 | typename Hash = std::hash, 35 | typename Pred = std::equal_to, 36 | typename Alloc = std::allocator< std::pair > 37 | > using UnorderedMultiMap = std::unordered_multimap; 38 | 39 | } // namespace Thea 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /Code/Source/UnorderedSet.hpp: -------------------------------------------------------------------------------- 1 | //============================================================================ 2 | // 3 | // This file is part of the Thea toolkit. 4 | // 5 | // This software is distributed under the BSD license, as detailed in the 6 | // accompanying LICENSE.txt file. Portions are derived from other works: 7 | // their respective licenses and copyright information are reproduced in 8 | // LICENSE.txt and/or in the relevant source files. 9 | // 10 | // Author: Siddhartha Chaudhuri 11 | // First version: 2011 12 | // 13 | //============================================================================ 14 | 15 | #ifndef __Thea_UnorderedSet_hpp__ 16 | #define __Thea_UnorderedSet_hpp__ 17 | 18 | #include "Platform.hpp" 19 | #include 20 | 21 | namespace Thea { 22 | 23 | /** Hash table-based set of objects. */ 24 | template < typename T, 25 | typename Hash = std::hash, 26 | typename Pred = std::equal_to, 27 | typename Alloc = std::allocator 28 | > using UnorderedSet = std::unordered_set; 29 | 30 | /** Hash table-based set of objects, with possible duplication. */ 31 | template < typename T, 32 | typename Hash = std::hash, 33 | typename Pred = std::equal_to, 34 | typename Alloc = std::allocator 35 | > using UnorderedMultiSet = std::unordered_multiset; 36 | 37 | } // namespace Thea 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /Data/Models/cube.obj: -------------------------------------------------------------------------------- 1 | v 0.000000 0.000000 0.000000 2 | v 1.000000 1.000000 0.000000 3 | v 1.000000 0.000000 0.000000 4 | v 0.000000 1.000000 0.000000 5 | v 0.000000 1.000000 1.000000 6 | v 0.000000 0.000000 1.000000 7 | v 1.000000 1.000000 1.000000 8 | v 1.000000 0.000000 1.000000 9 | vn 0.000000 0.000000 -1.000000 10 | vn 0.000000 0.000000 -1.000000 11 | vn 0.000000 0.000000 -1.000000 12 | vn 0.000000 0.000000 -1.000000 13 | vn -1.000000 0.000000 0.000000 14 | vn -1.000000 0.000000 0.000000 15 | vn 0.000000 1.000000 0.000000 16 | vn 1.000000 0.000000 0.000000 17 | 18 | g cube 19 | f 1//1 2//2 3//3 20 | f 1//1 4//4 2//2 21 | f 1//1 5//5 4//4 22 | f 1//1 6//6 5//5 23 | f 4//4 7//7 2//2 24 | f 4//4 5//5 7//7 25 | f 3//3 2//2 7//7 26 | f 3//3 7//7 8//8 27 | f 1//1 3//3 8//8 28 | f 1//1 8//8 6//6 29 | f 6//6 8//8 7//7 30 | f 6//6 7//7 5//5 31 | --------------------------------------------------------------------------------