├── env.sh ├── vipss ├── src │ ├── surfacer │ │ ├── utils │ │ │ ├── Utils_Dots_i.H │ │ │ ├── PMeshLite_Ply.H │ │ │ ├── Ppm.H │ │ │ ├── Mesh_Random.H │ │ │ ├── Mesh_PolygonSpatial.H │ │ │ ├── Utils_Timer.H │ │ │ ├── tdgTimer.h │ │ │ ├── Utils_Toggle.H │ │ │ ├── Rn_Io1_i.H │ │ │ ├── Rn_Polynomial_i.H │ │ │ ├── Mesh_Pool.H │ │ │ ├── Utils_IcosahedralSampler.H │ │ │ ├── Utils_EditStamp.H │ │ │ ├── R2_Contour_i.H │ │ │ ├── Mesh_Bbox.H │ │ │ ├── Rn_Io2_i.H │ │ │ ├── Rn_Io3_i.H │ │ │ ├── Rn_Io4_i.H │ │ │ ├── Rn_Point1_i.H │ │ │ ├── Utils_Polygon_mapping.H │ │ │ ├── Rn_CoVector1_i.H │ │ │ ├── R2_Polygon_i.H │ │ │ ├── R3_Polygon_i.H │ │ │ ├── Mesh_Stat.H │ │ │ ├── R3_Sphere_i.H │ │ │ ├── R2_Boxed_polygon_i.H │ │ │ ├── Rn_Point4_i.H │ │ │ ├── Rn_Vector1_i.H │ │ │ ├── Rn_CoVector2_i.H │ │ │ ├── C2_ComplexNumbers.H │ │ │ ├── Rn_Point2_i.H │ │ │ ├── C2_PointTC.H │ │ │ ├── R3_Line_seg_i.H │ │ │ ├── C2_LFTTC.H │ │ │ ├── Rn_Point3_i.H │ │ │ ├── BaryPoly.h │ │ │ ├── Rn_CoVector4_i.H │ │ │ ├── Utils_EdgeFilter.H │ │ │ ├── R2_Ellipse_i.H │ │ │ ├── Utils_GaborFilter.H │ │ │ ├── R2_Sphere_i.H │ │ │ ├── Utils_Barys.H │ │ │ ├── R3_Line_i.H │ │ │ ├── Rn_Unary1_i.H │ │ │ ├── Rn_CoVector3_i.H │ │ │ ├── R3_Ellipse_i.H │ │ │ ├── Rn_Vector4_i.H │ │ │ ├── Rn_Vector2_i.H │ │ │ ├── Mesh_Stack.H │ │ │ ├── Rn_Projective.H │ │ │ ├── Rn_Unary2_i.H │ │ │ ├── Mesh_Set.H │ │ │ ├── Rn_Projective_i.H │ │ │ ├── Rn_Unary3_i.H │ │ │ ├── Mesh_Queue.H │ │ │ ├── Rn_Unary4_i.H │ │ │ ├── Utils_GeomArray.H │ │ │ ├── Rn_BBox.H │ │ │ ├── Rn_Polynomial.H │ │ │ ├── R2_Line_i.H │ │ │ ├── Mesh_Spatial.H │ │ │ ├── Mesh_HashStruct.H │ │ │ ├── Rn_Vector3_i.H │ │ │ ├── R2_Contour.H │ │ │ ├── Image_Raw1D.H │ │ │ ├── R3_Plane.H │ │ │ ├── Mesh_Intersect.H │ │ │ └── C2_PointTC_i.H │ │ ├── Polygonizer.h │ │ ├── ImplicitedSurfacing.h │ │ └── ImplicitedSurfacing.cpp │ ├── Solver.h │ └── readers.h ├── CMakeLists.txt ├── makefigure.sh └── main.cpp ├── data └── torus │ ├── multisample_n25 │ └── input.xyz │ └── multisample_n50 │ └── input.xyz ├── LICENSE.txt └── ReadMe.md /env.sh: -------------------------------------------------------------------------------- 1 | /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" 2 | 3 | brew install nlopt 4 | 5 | brew install armadillo 6 | -------------------------------------------------------------------------------- /vipss/src/surfacer/utils/Utils_Dots_i.H: -------------------------------------------------------------------------------- 1 | 2 | inline UTILSDot::UTILSDot( ) : m_vecCurOffset(0,0,0) 3 | { 4 | m_iName = m_siNames++; 5 | m_oiGroupId = -1; 6 | } 7 | -------------------------------------------------------------------------------- /vipss/src/surfacer/utils/PMeshLite_Ply.H: -------------------------------------------------------------------------------- 1 | #ifndef _PLY_PMESH_LITE_PLY_H__ 2 | #define _PLY_PMESH_LITE_PLY_H__ 3 | 4 | #include 5 | 6 | extern void PLYReadPlyToPMeshLite( const char * in_strFName, PMeshLite &out_mesh, const WINbool in_bReverse ); 7 | extern void PLYWritePMeshLiteToPly( const PMeshLite &in_mesh, const char * in_strFName ); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /vipss/src/surfacer/utils/Ppm.H: -------------------------------------------------------------------------------- 1 | //ppm.H 2 | // 3 | //This declares a few functions that will help save images 4 | //as PPM files. 5 | // 6 | //Created: Thu Aug 5 12:23:04 PDT 2004 7 | //Creator: Leon Barrett 8 | 9 | #ifndef PPM_BY_LEON_RIGHT_HERE_DECLARE_H 10 | #define PPM_BY_LEON_RIGHT_HERE_DECLARE_H 11 | 12 | #include 13 | 14 | //Data should be arranged in row-major format (i.e. all of a row is together) 15 | //with each pixel arranged as adjacent RGB. 16 | //i.e. it should look like RGBRGBRGB... 17 | void WritePPM( std::ostream & os, int width, int height, unsigned short * data ); 18 | void WritePPM( char * fileName, int width, int height, unsigned short * data ); 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /vipss/src/surfacer/utils/Mesh_Random.H: -------------------------------------------------------------------------------- 1 | // This may look like C code, but it is really -*- C++ -*- 2 | // Copyright (c) 1992 Hugues H. Hoppe; All rights reserved. 3 | 4 | #ifndef MeshRandom_h 5 | #define MeshRandom_h 6 | 7 | class MeshRandom { 8 | public: 9 | static MeshRandom G; 10 | MeshRandom(int seed=1); 11 | ~MeshRandom(); 12 | int getint(); 13 | double unif(); 14 | double dunif(); 15 | double gauss(); 16 | double dgauss(); 17 | void setseed(int seed); 18 | private: 19 | enum { SIZE=32, NGAUSS=10 }; 20 | int state[SIZE]; // int should be 32 bit 21 | double uniffactor; 22 | double gaussoffset,gaussfactor; 23 | void showstate() const; 24 | DISABLECOPY(MeshRandom); 25 | }; 26 | 27 | #endif 28 | 29 | -------------------------------------------------------------------------------- /vipss/src/surfacer/utils/Mesh_PolygonSpatial.H: -------------------------------------------------------------------------------- 1 | // This may look like C code, but it is really -*- C++ -*- 2 | // Copyright (c) 1992 Hugues H. Hoppe; All rights reserved. 3 | 4 | #ifndef PolygonSpatial_h 5 | #define PolygonSpatial_h 6 | 7 | #include 8 | #include 9 | 10 | class PolygonSpatial : public ObjectSpatial { 11 | public: 12 | PolygonSpatial(int pgn); 13 | ~PolygonSpatial(); 14 | // clear() inherited from ObjectSpatial, does not delete Polygons! 15 | // deleteclear() must be implemented by user 16 | void enter(const R3Polygon &poly); // poly is not copied! 17 | int firstAlongSegment(const R3Pt& p1, const R3Pt& p2, 18 | const R3Polygon*& poly, R3Pt& pint) const; 19 | }; 20 | 21 | #endif 22 | 23 | -------------------------------------------------------------------------------- /vipss/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(vipss) 2 | cmake_minimum_required(VERSION 2.8) 3 | 4 | SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O3 ") 5 | 6 | find_package(nlopt REQUIRED) 7 | set(NLOPT_LIB_DIR "") 8 | set(NLOPT_LIB ${NLOPT_LIBRARIES}) 9 | 10 | find_package(Armadillo REQUIRED) 11 | set(ARMADILLO_LIB_DIRS "") 12 | set(ARMADILLO_LIB ${ARMADILLO_LIBRARIES}) 13 | 14 | 15 | include_directories(${NLOPT_INCLUDE_DIRS} ${ARMADILLO_INCLUDE_DIRS} ./src/surfacer) 16 | aux_source_directory(. MAIN) 17 | aux_source_directory(./src SRC_LIST) 18 | aux_source_directory(./src/surfacer SURFACER_LIST) 19 | 20 | LINK_DIRECTORIES(${ARMADILLO_LIB_DIRS} ${NLOPT_LIB_DIR}) 21 | add_executable(${PROJECT_NAME} ${SRC_LIST} ${MAIN} ${SURFACER_LIST}) 22 | 23 | target_link_libraries(${PROJECT_NAME} ${ARMADILLO_LIB} ${NLOPT_LIB}) 24 | -------------------------------------------------------------------------------- /data/torus/multisample_n25/input.xyz: -------------------------------------------------------------------------------- 1 | 0.938617 0.0149752 -0.162901 2 | 0.859186 0.237939 0.20532 3 | -0.489118 -0.545309 0.249185 4 | -0.672254 0.0660315 0.238544 5 | -0.21725 -0.481131 -0.11561 6 | 0.104384 -0.786686 -0.245838 7 | 0.666696 -0.433201 0.24568 8 | -0.765971 0.614255 -0.0918751 9 | 0.408981 0.783479 -0.21069 10 | -0.478693 0.227465 -0.119695 11 | -0.61781 -0.250006 -0.235404 12 | 0.785091 0.498412 -0.172391 13 | -0.995059 -0.0775631 -0.0230112 14 | 0.533199 0.667687 0.226583 15 | 0.0977032 -0.820763 0.237574 16 | -0.23984 -0.969022 0.0109533 17 | 0.220929 -0.450461 0.0317333 18 | -0.426634 0.810656 0.186238 19 | -0.196954 0.89077 -0.189235 20 | 0.0295202 0.736767 0.249421 21 | 0.584909 -0.466678 -0.249936 22 | 0.232824 0.442441 0.00223249 23 | 0.508837 -0.858514 -0.0169062 24 | -0.856822 -0.51201 0.0132256 25 | 0.492594 0.0857877 -0.00922203 26 | -------------------------------------------------------------------------------- /vipss/src/surfacer/utils/Utils_Timer.H: -------------------------------------------------------------------------------- 1 | // timer.h 2 | 3 | #include 4 | #include 5 | 6 | #ifdef SGI 7 | #include 8 | #endif 9 | 10 | /**@name Count seconds and milliseconds 11 | \ingroup UtilitiesFunc 12 | 13 | May not work under unix system.
14 | Bracked area to be times with UTILSTickStart and UTILSTickEnd, 15 | then call UTILSSecondsFromTick to get time or print out result from UTILSTickEnd. 16 |
FILES:
17 | - include/utils/Utils_Timer.H 18 | - utils/utils/Timer.cpp 19 | */ 20 | //@{ 21 | 22 | /// 23 | typedef struct {long milliseconds; long seconds;} UTILSTick; 24 | /// 25 | UTILSTick UTILSTickStart(void); 26 | /// Call with tick returned from UTILSTickStart. 27 | UTILSTick UTILSTickEnd(UTILSTick tickStart); 28 | /// 29 | double UTILSSecondsFromTick(UTILSTick tick); 30 | 31 | //@} 32 | -------------------------------------------------------------------------------- /vipss/src/surfacer/Polygonizer.h: -------------------------------------------------------------------------------- 1 | /***** implicit.h */ 2 | 3 | /* header file for implicit surface polygonizer, implicit.c */ 4 | 5 | #ifndef IMPLICIT_HDR 6 | #define IMPLICIT_HDR 7 | 8 | #include 9 | 10 | typedef struct { /* surface vertex */ 11 | R3Pt position; 12 | R3Vec normal; /* position and surface normal */ 13 | } VERTEX; 14 | 15 | typedef struct { /* list of vertices in polygonization */ 16 | int count, max; /* # vertices, max # allowed */ 17 | VERTEX *ptr; /* dynamically allocated */ 18 | } VERTICES; 19 | 20 | 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | bool polygonize ( 27 | double (*function)(const R3Pt &in_pt), 28 | double size, 29 | int bounds, 30 | const R3Pt &in_ptStart, 31 | int (*triproc)(int i1, int i2, int i3, VERTICES vertices), 32 | void (*vertproc)(VERTICES vertices) 33 | ); 34 | 35 | /* see implicit.c for explanation of arguments */ 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | 41 | #endif 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Zhiyang Huang 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /vipss/src/surfacer/utils/tdgTimer.h: -------------------------------------------------------------------------------- 1 | #ifndef TDGTIMER_H 2 | #define TDGTIMER_H 3 | 4 | #include 5 | #include 6 | #ifdef WIN32 7 | #include 8 | #else 9 | #include 10 | #endif 11 | //#include 12 | #include 13 | 14 | class tdgTimer 15 | { 16 | private: 17 | //clock_t m_StartTime; 18 | //clock_t m_StopTime; 19 | //Array m_SplitTime; 20 | #ifdef WIN32 21 | LARGE_INTEGER m_freq; 22 | LARGE_INTEGER m_StartTime; 23 | LARGE_INTEGER m_StopTime; 24 | Array m_SplitTimes; 25 | #else 26 | timeval m_StartTime; 27 | timeval m_StopTime; 28 | Array m_SplitTimes; 29 | #endif 30 | int m_isRunning; 31 | 32 | public: 33 | tdgTimer(); 34 | ~tdgTimer(); 35 | //struct timeval t0; 36 | 37 | void Reset(); 38 | void Start(); 39 | void Stop(); 40 | void Split(); 41 | 42 | double GetStartTime(); 43 | double GetStopTime(); 44 | double GetElapsedTime(); 45 | 46 | double GetSplitTime(const int i); 47 | 48 | double GetTotalSplitTime(); 49 | double GetAvgSplitTime(); 50 | double GetMinSplitTime(); 51 | double GetMaxSplitTime(); 52 | }; 53 | #endif 54 | -------------------------------------------------------------------------------- /vipss/src/surfacer/utils/Utils_Toggle.H: -------------------------------------------------------------------------------- 1 | #ifndef _UTILS_TOGGLE_DEFS_H 2 | #define _UTILS_TOGGLE_DEFS_H 3 | 4 | #include 5 | 6 | /** Toggle between true and false. 7 | 8 | \ingroup UtilitiesFunc 9 | 10 | \brief Basically a boolean, but forces initialization so's you don't forget to :) 11 | 12 |
Files: 13 | - include/utils/Utils_Toggle.H 14 | 15 | */ 16 | class UTILSToggle { 17 | private: 18 | WINbool m_bBool; 19 | 20 | public: 21 | /// 22 | WINbool Toggle() 23 | { 24 | m_bBool = ( m_bBool == TRUE ? FALSE : TRUE ); 25 | return m_bBool; 26 | } 27 | 28 | /// 29 | WINbool operator=( WINbool in_b ) { m_bBool = in_b; return m_bBool; } 30 | /// 31 | WINbool operator==( WINbool in_b ) const 32 | { 33 | if ( in_b == m_bBool ) return TRUE; 34 | return FALSE; 35 | } 36 | 37 | /// For those functions which reallllly want an int 38 | int Int() const { return m_bBool; } 39 | 40 | /// 41 | WINbool operator()() const { return m_bBool; } 42 | 43 | /// 44 | UTILSToggle( WINbool in_bSet ) { m_bBool = in_bSet; } 45 | /// 46 | ~UTILSToggle() {} 47 | }; 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /vipss/src/surfacer/utils/Rn_Io1_i.H: -------------------------------------------------------------------------------- 1 | // ========================================================= 2 | // 3 | // IO operators on affine1 classes 4 | // 5 | // ========================================================= 6 | 7 | /** \ingroup SimpleGeometryIO */ 8 | //@{ 9 | /// 10 | template 11 | inline ostream& operator<<( ostream &out, const R1VectorTC &v ) 12 | { 13 | out << v[0] << " "; 14 | return out; 15 | } 16 | 17 | /// 18 | template 19 | inline istream& operator>>( istream &in, R1VectorTC &v ) 20 | { 21 | in >> v[0]; 22 | return in; 23 | } 24 | 25 | template 26 | inline ostream& operator<<( ostream &out, const R1CoVectorTC &v ) 27 | { 28 | out << v[0] << " "; 29 | return out; 30 | } 31 | 32 | template 33 | inline istream& operator>>( istream &in, R1CoVectorTC &v ) 34 | { 35 | in >> v[0]; 36 | return in; 37 | } 38 | 39 | 40 | /// 41 | template 42 | inline ostream& operator<<( ostream &out, const R1PointTC &p ) 43 | { 44 | out << p[0] << " "; 45 | return out; 46 | } 47 | 48 | /// 49 | template 50 | inline istream& operator>>( istream &in, R1PointTC &p ) 51 | { 52 | in >> p[0]; 53 | return in; 54 | } 55 | //@} 56 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /vipss/src/surfacer/utils/Rn_Polynomial_i.H: -------------------------------------------------------------------------------- 1 | /* ------------------------------------------------------------------------- 2 | * DESCR : Accessors for 1 dimension 3 | * ------------------------------------------------------------------------- */ 4 | inline double 5 | RNPolynomial::operator[](int i) const 6 | { 7 | return Array::operator[](i); 8 | } 9 | 10 | inline double & 11 | RNPolynomial::operator[](int i) 12 | { 13 | return Array::operator[](i); 14 | } 15 | 16 | inline double 17 | RNPolynomial::Coef(int which) const 18 | { 19 | ASSERT( m_iDim == 1 ); 20 | return (*this)[which]; 21 | } 22 | 23 | inline double & 24 | RNPolynomial::Coef(int which) 25 | { 26 | ASSERT( m_iDim == 1 ); 27 | return (*this)[which]; 28 | } 29 | 30 | /* ------------------------------------------------------------------------- 31 | * DESCR : Accessors for 2 dimensions 32 | * ------------------------------------------------------------------------- */ 33 | inline double & 34 | RNPolynomial::Coef(int which_s, int which_t) 35 | { 36 | ASSERT( m_iDim == 2 ); 37 | return (*this)[which_t * (Degree()+1) + which_s]; 38 | } 39 | 40 | inline double 41 | RNPolynomial::Coef(int which_s, int which_t) const 42 | { 43 | ASSERT( m_iDim == 2 ); 44 | return (*this)[which_t * (Degree()+1) + which_s]; 45 | } 46 | -------------------------------------------------------------------------------- /vipss/src/surfacer/ImplicitedSurfacing.h: -------------------------------------------------------------------------------- 1 | #ifndef IMPLICITEDSURFACING_H 2 | #define IMPLICITEDSURFACING_H 3 | 4 | #include "Polygonizer.h" 5 | #include "../readers.h" 6 | 7 | 8 | class Surfacer{ 9 | 10 | public: 11 | 12 | R3Pt s_ptMin, s_ptMax; 13 | Array s_aptSurface; 14 | Array s_avecSurface; 15 | Array s_afaceSurface; 16 | 17 | 18 | vectorall_v; 19 | vectorall_fv; 20 | 21 | R3Pt st; 22 | double dSize; 23 | int iBound; 24 | 25 | 26 | Surfacer(){} 27 | 28 | void CalSurfacingPara(vector&Vs, int nvoxels); 29 | 30 | double Surfacing_Implicit(vector&Vs, int n_voxels, bool ischeckall, 31 | double (*function)(const R3Pt &in_pt)); 32 | 33 | 34 | 35 | void WriteSurface(string fname); 36 | void WriteSurface(vector &v, vector&fv); 37 | void WriteSurface(vector **v, vector**fv); 38 | 39 | void ClearBuffer(); 40 | 41 | void ClearSingleComponentBuffer(); 42 | 43 | private: 44 | void GetCurSurface(vector &v, vector&fv); 45 | void InsertToCurSurface(vector&v,vector&fv); 46 | 47 | 48 | 49 | 50 | 51 | }; 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | #endif // IMPLICITEDSURFACING_H 71 | -------------------------------------------------------------------------------- /vipss/src/surfacer/utils/Mesh_Pool.H: -------------------------------------------------------------------------------- 1 | // This may look like C code, but it is really -*- C++ -*- 2 | // Copyright (c) 1993 Hugues H. Hoppe; All rights reserved. 3 | 4 | #ifndef Pool_h 5 | #define Pool_h 6 | 7 | // See notes in Pool.C 8 | 9 | #define POOLALLOCATION(class) \ 10 | void* operator new(size_t s) \ 11 | { return s==sizeof(class)?pool.alloc():pool.specialalloc(s); } \ 12 | void operator delete(void* p, size_t s) \ 13 | { s==sizeof(class)?pool.free(p):pool.specialfree(p,s); } \ 14 | static Pool pool 15 | 16 | #define ALLOCATEPOOL(class) Pool class::pool(sizeof(class),#class) 17 | 18 | class Pool { 19 | public: 20 | Pool(unsigned pesize, const char* pname); 21 | ~Pool(); 22 | void* alloc(); 23 | void free(void* p); 24 | void* specialalloc(size_t s); 25 | void specialfree(void* p, size_t s); 26 | private: 27 | struct Link { Link* next; }; 28 | struct Chunk { Chunk* next; }; 29 | int esize; 30 | const char* iname; 31 | Link* h; 32 | Chunk* chunkh; 33 | int nalloc; 34 | int offset; 35 | void grow(); 36 | DISABLECOPY(Pool); 37 | }; 38 | 39 | //---------------------------------------------------------------------- 40 | 41 | inline void* Pool::alloc() 42 | { 43 | if (!h) grow(); 44 | Link* p=h; h=p->next; return p; 45 | } 46 | 47 | inline void Pool::free(void* pp) 48 | { 49 | Link* p=(Link*)pp; 50 | p->next=h; h=p; 51 | } 52 | 53 | #endif 54 | 55 | -------------------------------------------------------------------------------- /vipss/src/surfacer/utils/Utils_IcosahedralSampler.H: -------------------------------------------------------------------------------- 1 | #ifndef UTILS_ICOSAHEDRALSAMPLER_DEFS_H 2 | #define UTILS_ICOSAHEDRALSAMPLER_DEFS_H 3 | 4 | #include 5 | 6 | /** \class UTILSIcosahedralSampler Utils_IcosahedralSampler.H utils/Utils_IcosahedralSampler.H 7 | \ingroup UtilitiesGeom 8 | \brief Samples evenly spaced on an icosahedran. 9 | 10 | You can subsample by spliting each triangle. 11 | 12 | Files:
13 | - include/utils/Utils_IcosahedralSampler.H 14 | - src/utils/utils/UTILSIcosahedralSampler.cpp */ 15 | class UTILSIcosahedralSampler { 16 | private: 17 | SArray m_avecVertices; 18 | SArray m_aiTriangles; // indices of triangles vertices 19 | SArray m_aiEdges; // indices of edge vertices 20 | 21 | R3Vec RectangularCoordsOf(double in_dPhi, double in_dTheta ); 22 | void TriangleEdges(const R3Pt_i &in_aiTri, SArray &out_aiEdges); 23 | void GetEdgeSamples(int in_iN, Array &); 24 | void GetFaceSamples(int in_iN, Array &); 25 | 26 | public: 27 | /** Get samples as unit vectors. 28 | @param in_iN number of times to divide edge of icosohedran. 29 | @param out_avecSamples The samples */ 30 | void GetSamples(int in_iN, Array &out_avecSamples ); 31 | 32 | /// 33 | UTILSIcosahedralSampler() ; 34 | /// 35 | ~UTILSIcosahedralSampler() {} 36 | 37 | }; 38 | 39 | #endif 40 | 41 | -------------------------------------------------------------------------------- /vipss/src/surfacer/utils/Utils_EditStamp.H: -------------------------------------------------------------------------------- 1 | #ifndef _UTILS_DEFS_EDIT_STAMP_H 2 | #define _UTILS_DEFS_EDIT_STAMP_H 3 | 4 | 5 | #include 6 | 7 | /** \class UTILSEditStamp Utils_EditStamp.H utils/Utils_EditStamp.H 8 | \ingroup UtilitiesFunc 9 | \brief A way to do time stamping 10 | 11 | I'm sure there's a boost or std version of this; essentially a time stamp. Everytime 12 | Edit is called, the time stamp id is incremented by one. Makes lazy/delayed evaluation 13 | possible in the UniformMflds code. 14 | 15 | Both the class that's changing and the class that needs to know about the first class 16 | need to have an instance. The changing class calls Edit() whenever something changes. The 17 | second class can check to see if it's version is the same by keeping an instance around 18 | and using OutOfDate and Update to check the current status wrt the changing class. 19 | */ 20 | class UTILSEditStamp { 21 | protected: 22 | int m_iStamp; 23 | 24 | public: 25 | /// 26 | void Edit() { m_iStamp++; } 27 | /// 28 | WINbool OutOfDate( const UTILSEditStamp &in_i ) const { return in_i.m_iStamp == m_iStamp ? FALSE : TRUE; } 29 | /// 30 | void Update( const UTILSEditStamp &in_i ) { m_iStamp = in_i.m_iStamp; } 31 | /// For reading in new data 32 | void Reset( ) { m_iStamp = 0; } 33 | 34 | /// 35 | UTILSEditStamp() : m_iStamp(0) {} 36 | /// 37 | virtual ~UTILSEditStamp() { m_iStamp = -1; } 38 | }; 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /vipss/src/surfacer/utils/R2_Contour_i.H: -------------------------------------------------------------------------------- 1 | inline const R2Polygon & R2Contour::operator[] (int in_iPoly) const 2 | { 3 | return m_apolygons[in_iPoly]; 4 | } 5 | 6 | /// 7 | inline R2Polygon & R2Contour::operator[] (int in_iPoly) 8 | { 9 | return m_apolygons[in_iPoly]; 10 | } 11 | /// 12 | inline WINbool R2Contour::Valid() const 13 | { 14 | for (int i = 0; i < m_apolygons.num(); i++) 15 | if ( m_apolygons[i].Valid() == FALSE ) return FALSE; 16 | 17 | if ( m_apolygons.num() == 0 ) 18 | return FALSE; 19 | 20 | return TRUE; 21 | } 22 | 23 | inline void R2Contour::SetPlane( const R3Vec & in_vec, 24 | double in_dZLevel ) 25 | { 26 | m_vecPlaneNormal = UnitSafe( in_vec ); 27 | m_dZLevel = in_dZLevel; 28 | } 29 | 30 | 31 | inline R2Contour &R2Contour::operator=(const R2Contour &in_oContour) 32 | { 33 | m_apolygons = in_oContour.m_apolygons; 34 | m_aavecNorm = in_oContour.m_aavecNorm; 35 | m_dZLevel = in_oContour.m_dZLevel; 36 | m_dWidth = in_oContour.m_dWidth; 37 | m_vecPlaneNormal = in_oContour.m_vecPlaneNormal; 38 | 39 | return *this; 40 | } 41 | 42 | inline R2Contour::R2Contour( ) 43 | { 44 | SetPlane( R3Vec(0,1,0), 0 ); 45 | m_dWidth = 0; 46 | } 47 | 48 | /// 49 | inline void R2Contour::Add( const R2Polygon &in_oPoly, const Array &in_avec ) 50 | { 51 | m_apolygons += in_oPoly; 52 | m_aavecNorm += in_avec; 53 | 54 | ASSERT( in_oPoly.Num_pts() == in_avec.num() ); 55 | } 56 | /// 57 | inline R2Contour::R2Contour( const R2Contour &in_contour ) 58 | { 59 | (*this) = in_contour; 60 | } 61 | -------------------------------------------------------------------------------- /data/torus/multisample_n50/input.xyz: -------------------------------------------------------------------------------- 1 | -0.152945 -0.813124 0.237378 2 | -0.255387 -0.447786 0.0871892 3 | -0.270748 0.42036 0.00711631 4 | -0.464248 -0.883138 0.0295921 5 | 0.534273 0.645807 -0.233601 6 | -0.600283 -0.103088 0.206784 7 | 0.635311 -0.443989 -0.248618 8 | 0.874768 0.478155 0.0343471 9 | -0.0203024 -0.812189 -0.241586 10 | 0.711551 0.284684 0.249175 11 | -0.925116 0.342081 0.0775029 12 | -0.812014 0.170478 -0.236541 13 | -0.662652 0.272458 0.247472 14 | 0.751976 -0.63498 0.0849935 15 | 0.989059 0.0983004 0.0536481 16 | -0.708243 -0.675748 -0.0982322 17 | 0.51961 0.845233 0.0563046 18 | 0.365487 -0.599877 -0.2455 19 | -0.784092 0.61835 0.0133768 20 | 0.449054 -0.220041 0.0126803 21 | -0.438277 -0.652932 0.247021 22 | -0.445856 -0.246051 -0.0676526 23 | 0.223679 0.606567 -0.227619 24 | -0.618374 0.427775 -0.249881 25 | 0.33247 0.522781 0.213242 26 | 0.0927198 -0.518024 -0.111795 27 | -0.999023 0.0124489 0.00743087 28 | 0.227023 0.950237 0.10174 29 | 0.820299 0.225896 -0.228151 30 | -0.131969 0.964774 0.108568 31 | -0.465599 0.718528 -0.225754 32 | 0.460194 0.286623 -0.139697 33 | 0.0355582 0.728401 0.249025 34 | -0.0046456 -0.999148 0.0126894 35 | 0.637003 -0.393158 0.249971 36 | -0.100987 0.859039 -0.221543 37 | 0.831422 -0.0862866 -0.234397 38 | 0.105606 -0.597217 0.204807 39 | -0.510068 0.644839 0.239161 40 | 0.0500732 0.498423 0.0199338 41 | 0.390286 -0.919973 -0.00572716 42 | -0.859623 -0.474853 0.091031 43 | 0.954717 -0.280953 0.0462485 44 | -0.43916 -0.60326 -0.249855 45 | -0.451125 0.887029 0.0437271 46 | 0.591402 6.10348e-11 0.193252 47 | 0.783475 -0.0814389 0.24681 48 | 0.472568 -0.722052 0.222626 49 | -0.502545 0.159082 -0.113361 50 | -0.892161 -0.275734 -0.168778 51 | -------------------------------------------------------------------------------- /vipss/src/surfacer/utils/Mesh_Bbox.H: -------------------------------------------------------------------------------- 1 | // This may look like C code, but it is really -*- C++ -*- 2 | // Copyright (c) 1992 Hugues H. Hoppe; All rights reserved. 3 | 4 | #ifndef Bbox_h 5 | #define Bbox_h 6 | 7 | #include 8 | 9 | /** \class Bbox Mesh_BBox.H utils/Mesh_BBox.H 10 | \ingroup MeshesHelper 11 | \brief Axis-aligned bounding boxes, defined by min/max points. 12 | 13 | Can do boolean operations on these bounding boxes. 14 | */ 15 | class Bbox { 16 | public: 17 | /// 18 | Bbox() { } 19 | /// Initialize with given end points 20 | Bbox(const R3Pt& pmin, const R3Pt& pmax); 21 | /// 22 | ~Bbox() { } 23 | /// Make zero size 24 | void clear(); 25 | /// Make infinitely big 26 | void infinite(); 27 | /// return min (0) or max (1) bounding box points. 28 | R3Pt& operator[](int i) { return p[i]; } 29 | /// return min (0) or max (1) bounding box points. 30 | const R3Pt& operator[](int i) const { return p[i]; } 31 | /// Make this box contain the input box 32 | void takeunion(const Bbox& bb); 33 | /// Expand box (if necessary) so it contains this point 34 | void takeunion(const R3Pt& pp); 35 | /// Only keep the bounding box contained inside of both this one and the input one 36 | void intersect(const Bbox& bb); 37 | /// Does this bounding box contain the input one? 38 | int inside(const Bbox& bb) const; 39 | /// uniform scaling into unit cube, centered on x & y, rest at z=0 40 | R4Matrix getFrameToCube() const; 41 | /// non-uniform scaling (?) into unit cube, centered on x & y, rest at z=0 42 | R4Matrix getFrameToSmallCube() const; 43 | private: 44 | /// p[0] is min point, p[1] is max point 45 | R3Pt p[2]; 46 | // shallow copy ok 47 | }; 48 | 49 | #endif 50 | 51 | -------------------------------------------------------------------------------- /vipss/makefigure.sh: -------------------------------------------------------------------------------- 1 | 2 | # Figure 12 3 | ./vipss -i ../data/hand_ok/input.xyz -l 0 -s 200 4 | 5 | # Figure 1 6 | ./vipss -i ../data/walrus/input.xyz -l 0.003 -s 100 7 | 8 | # Figure 9, 11 9 | ./vipss -i ../data/bathtub/input.xyz -l 0 -s 200 10 | 11 | # Figure 12 12 | ./vipss -i ../data/phone/input.xyz -l 0 -s 100 13 | 14 | # Figure 5 15 | ./vipss -i ../data/planck/multisample_n500/input.xyz -l 0 -s 100 -t 16 | ./vipss -i ../data/planck/multisample_n1000/input.xyz -l 0 -s 100 -t 17 | ./vipss -i ../data/planck/multisample_n2000/input.xyz -l 0 -s 100 -t 18 | ./vipss -i ../data/planck/multisample_n4000/input.xyz -l 0 -s 100 -t 19 | 20 | # Figure 6 21 | ./vipss -i ../data/wireframes/doghead/input.xyz -l 0 -s 100 22 | ./vipss -i ../data/wireframes/phone/input.xyz -l 0 -s 100 23 | ./vipss -i ../data/wireframes/trebol/input.xyz -l 0 -s 100 24 | ./vipss -i ../data/wireframes/spring/input.xyz -l 0 -s 100 25 | ./vipss -i ../data/surfaces_500/vertebra/input.xyz -l 0 -s 100 26 | ./vipss -i ../data/surfaces_500/hand/input.xyz -l 0 -s 100 27 | 28 | # Figure 4 29 | ./vipss -i ../data/torus/crosscut/input.xyz -l 0 -s 50 30 | ./vipss -i ../data/torus/halfsamplel500_r25/input.xyz -l 0 -s 50 31 | ./vipss -i ../data/torus/multisample_n25/input.xyz -l 0 -s 50 32 | ./vipss -i ../data/torus/multisample_n50/input.xyz -l 0 -s 50 33 | ./vipss -i ../data/torus/wires/input.xyz -l 0 -s 50 34 | ./vipss -i ../data/torus/parallelcut/input.xyz -l 0 -s 50 35 | 36 | # Figure 7 37 | ./vipss -i ../data/noise_kitten/kitten_h0.01/input.xyz -o ../data/noise_kitten/kitten_h001/l0001_ -l 0.001 -s 100 38 | ./vipss -i ../data/noise_kitten/kitten_h0.01/input.xyz -o ../data/noise_kitten/kitten_h001/l001_ -l 0.01 -s 100 39 | 40 | ./vipss -i ../data/noise_kitten/kitten_h0.04/input.xyz -o ../data/noise_kitten/kitten_h004/l0001_ -l 0.001 -s 100 41 | ./vipss -i ../data/noise_kitten/kitten_h0.04/input.xyz -o ../data/noise_kitten/kitten_h004/l001_ -l 0.01 -s 100 42 | -------------------------------------------------------------------------------- /vipss/src/surfacer/utils/Rn_Io2_i.H: -------------------------------------------------------------------------------- 1 | // ========================================================= 2 | // 3 | // IO operators on affine1 classes 4 | // 5 | // ========================================================= 6 | 7 | /** \ingroup SimpleGeometryIO */ 8 | //@{ 9 | 10 | /// 11 | template 12 | inline ostream& operator<<( ostream &out, const R2VectorTC &v ) 13 | { 14 | out << v[0] << " " << v[1] << " "; 15 | return out; 16 | } 17 | 18 | /// 19 | template 20 | inline istream& operator>>( istream &in, R2VectorTC &v ) 21 | { 22 | in >> v[0] >> v[1]; 23 | return in; 24 | } 25 | 26 | 27 | 28 | /// 29 | template 30 | inline ostream& operator<<( ostream &out, const R2CoVectorTC &v ) 31 | { 32 | out << v[0] << " " << v[1] << " "; 33 | return out; 34 | } 35 | 36 | /// 37 | template 38 | inline istream& operator>>( istream &in, R2CoVectorTC &v ) 39 | { 40 | in >> v[0] >> v[1]; 41 | return in; 42 | } 43 | 44 | 45 | 46 | /// 47 | template 48 | inline ostream& operator<<( ostream &out, const R2PointTC &p ) 49 | { 50 | out << p[0] << " " << p[1] << " "; 51 | return out; 52 | } 53 | 54 | /// 55 | template 56 | inline istream& operator>>( istream &in, R2PointTC &p ) 57 | { 58 | in >> p[0] >> p[1]; 59 | return in; 60 | } 61 | 62 | 63 | 64 | 65 | template 66 | inline ostream& operator<<( ostream &out, const R2MatrixTC &m ) 67 | { 68 | for (int i = 0; i < 2; i++) { 69 | for ( int j = 0; j < 2; j++) { 70 | out << m(i,j) << " "; 71 | } 72 | out << " "; 73 | } 74 | 75 | return out; 76 | } 77 | 78 | template 79 | inline istream& operator>>( istream &in, R2MatrixTC &m ) 80 | { 81 | for (int i = 0; i < 2; i++) 82 | for ( int j = 0; j < 2; j++) 83 | in >> m(i,j); 84 | 85 | return in; 86 | } 87 | 88 | 89 | 90 | //@} 91 | 92 | -------------------------------------------------------------------------------- /vipss/src/surfacer/utils/Rn_Io3_i.H: -------------------------------------------------------------------------------- 1 | // ========================================================= 2 | // 3 | // IO operators on affine1 classes 4 | // 5 | // ========================================================= 6 | 7 | /** \ingroup SimpleGeometryIO */ 8 | //@{ 9 | 10 | /// 11 | template 12 | inline ostream& operator<<( ostream &out, const R3VectorTC &v ) 13 | { 14 | out << v[0] << " " << v[1] << " " << v[2] << " "; 15 | return out; 16 | } 17 | 18 | /// 19 | template 20 | inline istream& operator>>( istream &in, R3VectorTC &v ) 21 | { 22 | in >> v[0] >> v[1] >> v[2]; 23 | return in; 24 | } 25 | 26 | 27 | /// 28 | template 29 | inline ostream& operator<<( ostream &out, const R3CoVectorTC &v ) 30 | { 31 | out << v[0] << " " << v[1] << " " << v[2] << " "; 32 | return out; 33 | } 34 | 35 | /// 36 | template 37 | inline istream& operator>>( istream &in, R3CoVectorTC &v ) 38 | { 39 | in >> v[0] >> v[1] >> v[2]; 40 | return in; 41 | } 42 | 43 | 44 | 45 | /// 46 | template 47 | inline ostream& operator<<( ostream &out, const R3PointTC &p ) 48 | { 49 | out << p[0] << " " << p[1] << " " << p[2] << " " ; 50 | return out; 51 | } 52 | 53 | /// 54 | template 55 | inline istream& operator>>( istream &in, R3PointTC &p ) 56 | { 57 | in >> p[0] >> p[1] >> p[2]; 58 | return in; 59 | } 60 | 61 | 62 | 63 | /// 64 | template 65 | inline ostream& operator<<( ostream &out, const R3MatrixTC &m ) 66 | { 67 | for (int i = 0; i < 3; i++) { 68 | for ( int j = 0; j < 3; j++) { 69 | out << m(i, j) << " "; 70 | } 71 | out << " "; 72 | } 73 | 74 | return out; 75 | } 76 | 77 | /// 78 | template 79 | inline istream& operator>>( istream &in, R3MatrixTC &m ) 80 | { 81 | for (int i = 0; i < 3; i++) 82 | for ( int j = 0; j < 3; j++) 83 | in >> m(i, j); 84 | 85 | return in; 86 | } 87 | 88 | 89 | 90 | //@} 91 | -------------------------------------------------------------------------------- /vipss/src/surfacer/utils/Rn_Io4_i.H: -------------------------------------------------------------------------------- 1 | // ========================================================= 2 | // 3 | // IO operators on affine1 classes 4 | // 5 | // ========================================================= 6 | 7 | /** \ingroup SimpleGeometryIO */ 8 | //@{ 9 | 10 | /// 11 | template 12 | inline ostream& operator<<( ostream &out, const R4VectorTC &v ) 13 | { 14 | out << v[0] << " " << v[1] << " " << v[2] << " " << v[3] << " "; 15 | return out; 16 | } 17 | 18 | /// 19 | template 20 | inline istream& operator>>( istream &in, R4VectorTC &v ) 21 | { 22 | in >> v[0] >> v[1] >> v[2] >> v[3]; 23 | return in; 24 | } 25 | 26 | 27 | /// 28 | template 29 | inline ostream& operator<<( ostream &out, const R4CoVectorTC &v ) 30 | { 31 | out << v[0] << " " << v[1] << " " << v[2] << " " << v[3] << " "; 32 | return out; 33 | } 34 | 35 | /// 36 | template 37 | inline istream& operator>>( istream &in, R4CoVectorTC &v ) 38 | { 39 | in >> v[0] >> v[1] >> v[2] >> v[3]; 40 | return in; 41 | } 42 | 43 | 44 | 45 | /// 46 | template 47 | inline ostream& operator<<( ostream &out, const R4PointTC &p ) 48 | { 49 | out << p[0] << " " << p[1] << " " << p[2] << " " << p[3] << " "; 50 | return out; 51 | } 52 | 53 | /// 54 | template 55 | inline istream& operator>>( istream &in, R4PointTC &p ) 56 | { 57 | in >> p[0] >> p[1] >> p[2] >> p[3]; 58 | return in; 59 | } 60 | 61 | 62 | 63 | /// 64 | template 65 | inline ostream& operator<<( ostream &out, const R4MatrixTC &m ) 66 | { 67 | for (int i = 0; i < 4; i++) { 68 | for ( int j = 0; j < 4; j++) { 69 | out << m(i, j) << " "; 70 | } 71 | out << " "; 72 | } 73 | 74 | return out; 75 | } 76 | 77 | /// 78 | template 79 | inline istream& operator>>( istream &in, R4MatrixTC &m ) 80 | { 81 | for (int i = 0; i < 4; i++) 82 | for ( int j = 0; j < 4; j++) 83 | in >> m(i, j); 84 | 85 | return in; 86 | } 87 | 88 | 89 | 90 | //@} 91 | -------------------------------------------------------------------------------- /vipss/src/surfacer/utils/Rn_Point1_i.H: -------------------------------------------------------------------------------- 1 | // ========================================================= 2 | // 3 | // Methods for R1PointTC template class 4 | // 5 | // ========================================================= 6 | 7 | 8 | // ------------------------------------- 9 | // constructors 10 | //------------------------------------ 11 | 12 | template 13 | inline 14 | R1PointTC::R1PointTC ( const Coord _u ) 15 | { 16 | 17 | u = _u; 18 | } 19 | 20 | // ------------------------------------- 21 | // constructors 22 | //------------------------------------ 23 | 24 | template 25 | inline R1PointTC& 26 | R1PointTC::operator += (const R1VectorTC& vDelta ) 27 | { 28 | 29 | u += vDelta[0]; 30 | 31 | return *this; 32 | } 33 | 34 | 35 | template 36 | inline R1PointTC& 37 | R1PointTC::operator -= (const R1VectorTC& vDelta ) 38 | { 39 | 40 | u -= vDelta.d; 41 | 42 | return *this; 43 | } 44 | 45 | // ------------------------------------- 46 | // point dominance 47 | // ------------------------------------ 48 | 49 | /// 50 | template 51 | inline WINbool 52 | R1PointTC::operator < ( const R1PointTC& p ) const 53 | { 54 | 55 | return (u < p[0]) ? TRUE : FALSE; 56 | } 57 | 58 | 59 | /// 60 | template 61 | inline WINbool 62 | R1PointTC::operator<= ( const R1PointTC& p ) const 63 | { 64 | 65 | return (u <= p[0]) ? TRUE : FALSE; 66 | } 67 | 68 | 69 | // ------------------------------------- 70 | // Read/write/print functions 71 | // ------------------------------------- 72 | template 73 | inline void R1PointTC::Write(ofstream &out) const 74 | { 75 | out << u; 76 | out << " "; 77 | } 78 | 79 | template 80 | inline WINbool R1PointTC::Read(ifstream &in) 81 | { 82 | in >> u; 83 | 84 | return in.good() ? TRUE : FALSE; 85 | } 86 | 87 | template 88 | inline void R1PointTC::Print( const WINbool in_bDoReturn ) const 89 | { 90 | TRACE("%f", u); 91 | if ( in_bDoReturn == TRUE ) 92 | TRACE("\n"); 93 | else 94 | TRACE("\n"); 95 | } 96 | 97 | 98 | 99 | -------------------------------------------------------------------------------- /vipss/src/surfacer/utils/Utils_Polygon_mapping.H: -------------------------------------------------------------------------------- 1 | #ifndef polygon_mapping_DEFS 2 | #define polygon_mapping_DEFS 3 | 4 | #include 5 | 6 | /* ----------------------- Constants ------------------------------- */ 7 | 8 | /* ----------------------- Classes ------------------------------- */ 9 | 10 | /** \class UTILSPolygon Utils_Polygon_mapping.H utils/Utils_Polygon_mapping.H 11 | \ingroup UtilitiesGeom 12 | 13 | \brief Map a quadrilateral to the unit square and back again. 14 | 15 | This map can be combined to take any non-coplanar quadrilateral to another non-coplanar quadrilateral, mapping the edges of one to the egdes of the other. Preserves lines.
16 | 17 | The mapping is a 3X3 matrix, which takes (x,y,1) to (s,t,w). To go from point to point, divide s,t by w. 18 | 19 | For Barycentric coordinates, see Utils_Barys.H 20 | 21 |
Files: 22 | - include/utils/Utils_Polygon_mapping.H 23 | - utils/utils/UTILSPolygon.cpp 24 | */ 25 | class UTILSPolygon { 26 | private: 27 | UTILSPolygon &operator=(UTILSPolygon &); 28 | static R3Matrix &MakeMatrix(const R2Polygon &p); 29 | 30 | public: 31 | /** Find the matrix that takes a quadrilateral to the unit square. 32 | The unit square is (0,0) to (1,1). The polygon must be 4-sided */ 33 | static R3Matrix Polygon_to_unit( const R2Polygon &p ); 34 | /** Find the matrix that takes the unit square to a quadrilateral. 35 | The unit square is (0,0) to (1,1). The polygon must be 4-sided */ 36 | static R3Matrix Unit_to_polygon( const R2Polygon &p ); 37 | /** Find the matrix that takes the quadrilateral to a quadrilateral. 38 | Combines polygon->unit->polygon. */ 39 | static R3Matrix Polygon_to_polygon( const R2Polygon & in_polyFrom, 40 | const R2Polygon & in_polyTo ); 41 | 42 | /** Map the 2D vector through the 3X3 matrix. 43 | Turns the vector into an homogenous point. */ 44 | static R2Vec Map(const R3Matrix &m, const R2Vec &v); 45 | /** Map the 2D point through the 3X3 matrix. 46 | Turns the point into an homogenous point. */ 47 | static R2Pt Map(const R3Matrix &m, const R2Pt &v); 48 | 49 | /// 50 | UTILSPolygon() {} 51 | /// 52 | virtual ~UTILSPolygon() {} 53 | 54 | /// 55 | static WINbool Test(); 56 | }; 57 | 58 | #endif 59 | 60 | -------------------------------------------------------------------------------- /vipss/src/surfacer/utils/Rn_CoVector1_i.H: -------------------------------------------------------------------------------- 1 | // ========================================================= 2 | // 3 | // Methods for R1CoVectorTC template class 4 | // 5 | // ========================================================= 6 | 7 | 8 | // ------------------------------------- 9 | // constructors 10 | // ------------------------------------- 11 | 12 | template 13 | inline 14 | R1CoVectorTC::R1CoVectorTC( const Coord _d ) 15 | { 16 | d = _d; 17 | } 18 | 19 | 20 | // ------------------------------------- 21 | // assignment operators 22 | // ------------------------------------- 23 | 24 | template 25 | inline R1CoVectorTC& 26 | R1CoVectorTC::operator += ( const R1CoVectorTC& v ) 27 | { 28 | d += v.d; 29 | return *this; 30 | } 31 | 32 | // 33 | template 34 | inline R1CoVectorTC& 35 | R1CoVectorTC::operator -= ( const R1CoVectorTC& v ) 36 | { 37 | d -= v.d; 38 | return *this; 39 | } 40 | 41 | template 42 | inline R1CoVectorTC& 43 | R1CoVectorTC::operator *= ( const Coord& s ) 44 | { 45 | d *= s; 46 | return *this; 47 | } 48 | 49 | template 50 | inline R1CoVectorTC& 51 | R1CoVectorTC::operator /= ( const Coord& s ) 52 | { 53 | d /= s; 54 | return *this; 55 | } 56 | 57 | 58 | 59 | template 60 | inline R1CoVectorTC 61 | R1CoVectorTC::operator + () const 62 | { 63 | return *this; 64 | } 65 | 66 | 67 | template 68 | inline R1CoVectorTC 69 | R1CoVectorTC::operator - () const 70 | { 71 | return R1CoVectorTC( -d ); 72 | } 73 | 74 | 75 | // ------------------------------------- 76 | // Read/write/print functions 77 | // ------------------------------------- 78 | template 79 | inline void R1CoVectorTC::Write(ofstream &out) const 80 | { 81 | out << d << " "; 82 | } 83 | 84 | template 85 | inline WINbool R1CoVectorTC::Read(ifstream &in) 86 | { 87 | in >> d; 88 | 89 | return in.good() ? TRUE : FALSE; 90 | } 91 | 92 | template 93 | inline void R1CoVectorTC::Print( WINbool in_bDoReturn ) const 94 | { 95 | cout << d; 96 | if ( in_bDoReturn == TRUE ) 97 | cout << "\n"; 98 | else 99 | cout << " "; 100 | } 101 | -------------------------------------------------------------------------------- /vipss/src/surfacer/utils/R2_Polygon_i.H: -------------------------------------------------------------------------------- 1 | /* ------------------------------------------------------------------------- 2 | * DESCR : Accessors 3 | * ------------------------------------------------------------------------- */ 4 | inline const R2Pt &R2Polygon::operator[] (int in_iVert) const 5 | { 6 | return m_apts[in_iVert]; 7 | } 8 | 9 | inline R2Pt &R2Polygon::operator[] (int in_iVert) 10 | { 11 | return m_apts[in_iVert]; 12 | } 13 | 14 | // Accessor that wraps the indices around 15 | inline const R2Pt &R2Polygon::PtWrap (int in_iVert) const 16 | { 17 | return m_apts.wrap(in_iVert); 18 | } 19 | 20 | inline R2Pt &R2Polygon::PtWrap ( int in_iVert) 21 | { 22 | return m_apts.wrap(in_iVert); 23 | } 24 | 25 | /* ------------------------------------------------------------------------- 26 | * DESCR : See if the polygon is valid by checking it\'s points 27 | * ------------------------------------------------------------------------- */ 28 | inline 29 | WINbool R2Polygon::Valid() const 30 | { 31 | if (Num_pts() == 0) return FALSE; 32 | 33 | for (int i = 0; i < Num_pts(); i++) 34 | if (RNIsValid(m_apts[i]) == FALSE) return FALSE; 35 | 36 | return TRUE; 37 | } 38 | 39 | /* ------------------------------------------------------------------------- 40 | * DESCR : Constructor 41 | * ------------------------------------------------------------------------- */ 42 | inline R2Polygon::R2Polygon( int in_iNPts) : m_apts(in_iNPts) 43 | { 44 | for (int i = 0; i < in_iNPts; i++) 45 | RNZero(m_apts[i]); 46 | } 47 | 48 | /* ------------------------------------------------------------------------- 49 | * DESCR : Copy a polygon 50 | * ------------------------------------------------------------------------- */ 51 | inline 52 | R2Polygon &R2Polygon::operator=(const R2Polygon &in_polygon) 53 | { 54 | m_apts = in_polygon.m_apts; 55 | 56 | return (*this); 57 | } 58 | 59 | 60 | /* ------------------------------------------------------------------------- 61 | * DESCR : Edges and lines 62 | * ------------------------------------------------------------------------- */ 63 | inline 64 | R2Line_seg R2Polygon::Edge(int in_iV1ToV2) const 65 | { 66 | return R2Line_seg( PtWrap( in_iV1ToV2 ), PtWrap( in_iV1ToV2 + 1 ) ); 67 | } 68 | 69 | inline 70 | R2Line R2Polygon::Line(int in_iV1ToV2) const 71 | { 72 | return R2Line( PtWrap( in_iV1ToV2 ), PtWrap( in_iV1ToV2 + 1 ) ); 73 | } 74 | 75 | -------------------------------------------------------------------------------- /vipss/src/surfacer/utils/R3_Polygon_i.H: -------------------------------------------------------------------------------- 1 | /* ------------------------------------------------------------------------- 2 | * DESCR : Accessors 3 | * ------------------------------------------------------------------------- */ 4 | inline const R3Pt &R3Polygon::operator[] (int in_iVert) const 5 | { 6 | return m_apts[in_iVert]; 7 | } 8 | 9 | inline R3Pt &R3Polygon::operator[] (int in_iVert) 10 | { 11 | return m_apts[in_iVert]; 12 | } 13 | 14 | // Accessor that wraps the indices around 15 | inline const R3Pt &R3Polygon::PtWrap (int in_iVert) const 16 | { 17 | return m_apts.wrap(in_iVert); 18 | } 19 | 20 | inline R3Pt &R3Polygon::PtWrap ( int in_iVert) 21 | { 22 | return m_apts.wrap(in_iVert); 23 | } 24 | 25 | /* ------------------------------------------------------------------------- 26 | * DESCR : See if the polygon is valid by checking it\'s points 27 | * ------------------------------------------------------------------------- */ 28 | inline 29 | WINbool R3Polygon::Valid() const 30 | { 31 | if (Num_pts() == 0) return FALSE; 32 | 33 | for (int i = 0; i < Num_pts(); i++) 34 | if (RNIsValid(m_apts[i]) == FALSE) return FALSE; 35 | 36 | return TRUE; 37 | } 38 | 39 | /* ------------------------------------------------------------------------- 40 | * DESCR : Constructor 41 | * ------------------------------------------------------------------------- */ 42 | inline R3Polygon::R3Polygon( int in_iNPts) : m_apts(in_iNPts) 43 | { 44 | for (int i = 0; i < in_iNPts; i++) 45 | RNZero(m_apts[i]); 46 | } 47 | 48 | /* ------------------------------------------------------------------------- 49 | * DESCR : Copy a polygon 50 | * ------------------------------------------------------------------------- */ 51 | inline 52 | R3Polygon &R3Polygon::operator=(const R3Polygon &in_polygon) 53 | { 54 | m_apts = in_polygon.m_apts; 55 | 56 | return (*this); 57 | } 58 | 59 | 60 | /* ------------------------------------------------------------------------- 61 | * DESCR : Edges and lines 62 | * ------------------------------------------------------------------------- */ 63 | inline 64 | R3Line_seg R3Polygon::Edge(int in_iV1ToV2) const 65 | { 66 | return R3Line_seg( PtWrap( in_iV1ToV2 ), PtWrap( in_iV1ToV2 + 1 ) ); 67 | } 68 | 69 | inline 70 | R3Line R3Polygon::Line(int in_iV1ToV2) const 71 | { 72 | return R3Line( PtWrap( in_iV1ToV2 ), PtWrap( in_iV1ToV2 + 1 ) ); 73 | } 74 | 75 | -------------------------------------------------------------------------------- /vipss/src/surfacer/utils/Mesh_Stat.H: -------------------------------------------------------------------------------- 1 | // This may look like C code, but it is really -*- C++ -*- 2 | // Copyright (c) 1992 Hugues H. Hoppe; All rights reserved. 3 | 4 | #ifndef Stat_h 5 | #define Stat_h 6 | 7 | #if 0 8 | { 9 | NEST { STAT(Svdeg); for (i=0;i<10;i++) Svdeg+=vdeg[i]; } 10 | SSTAT(Svanum,va.num()); 11 | } 12 | #endif 13 | 14 | // GetenvValue("STATFILES") -> store data values in files. 15 | 16 | class Stat { 17 | public: 18 | Stat(const char* pname=0, int pprint=0, int isstatic=0); 19 | ~Stat(); 20 | void setname(const char* pname); 21 | void setprint(int pprint); 22 | void zero(); 23 | void terminate(); 24 | double enter(double f); // ret same f 25 | Stat& operator+=(double f); 26 | Stat& operator+=(const Stat& st); 27 | const char* name() const; 28 | int num() const; 29 | double smin() const; 30 | double smax() const; 31 | double avg() const; 32 | double var() const; 33 | double sdv() const; 34 | double sum() const; 35 | const char* string() const; // no leading name, no trailing '\n' 36 | const char* namestring() const; // operator<< uses namestring format 37 | friend ostream& operator<<(ostream& s, const Stat& st); 38 | private: 39 | const char* iname; 40 | int iprint; // print statistics in destructor 41 | int n; 42 | double isum; 43 | double isum2; 44 | double imin; 45 | double imax; 46 | ofstream* fos; // if getenv("STATFILES") 47 | void output(double f) const; 48 | DISABLECOPY(Stat); 49 | }; 50 | 51 | #define STAT(Svar) Stat Svar(#Svar,1) 52 | #define STATNP(Svar) Stat Svar(#Svar,0) 53 | #define SSTAT(Svar,v) { static Stat Svar(#Svar,1,1); Svar+=v; } 54 | 55 | //---------------------------------------------------------------------------- 56 | 57 | inline const char* Stat::name() const { return iname; } 58 | inline int Stat::num() const { return n; } 59 | inline double Stat::smin() const { return imin; } 60 | inline double Stat::smax() const { return imax; } 61 | inline double Stat::sdv() const { return mysqrt(var()); } 62 | inline double Stat::avg() const { return MESHassertw1(n)?0:isum/n; } 63 | inline double Stat::sum() const { return isum; } 64 | inline void Stat::setprint(int pprint) { iprint=pprint; } 65 | 66 | inline Stat& Stat::operator+=(double f) 67 | { 68 | n++; isum+=f; isum2+=f*f; 69 | if (fimax) imax=f; 71 | if (fos) output(f); 72 | return *this; 73 | } 74 | 75 | inline double Stat::enter(double f) 76 | { 77 | *this+=f; 78 | return f; 79 | } 80 | 81 | #endif 82 | 83 | -------------------------------------------------------------------------------- /vipss/src/surfacer/utils/R3_Sphere_i.H: -------------------------------------------------------------------------------- 1 | /* ------------------------------------------------------------------------- 2 | * DESCR : Interior area 3 | * ------------------------------------------------------------------------- */ 4 | inline double R3Sphere::Area() const 5 | { 6 | return 4.0 / 3.0 * M_PI * Radius() * Radius() * Radius(); 7 | } 8 | 9 | /* ------------------------------------------------------------------------- 10 | * DESCR : Compare two points 11 | * ------------------------------------------------------------------------- */ 12 | inline 13 | WINbool R3Sphere::operator==(const R3Sphere &in_sphere) const 14 | { 15 | if (ApproxEqual(Center(), in_sphere.Center()) == FALSE) return FALSE; 16 | 17 | if (!RNIsZero(in_sphere.Radius() - Radius())) return FALSE; 18 | 19 | return TRUE; 20 | } 21 | 22 | /* ------------------------------------------------------------------------- 23 | * DESCR : Are we inside the circle (open disk)? 24 | * ------------------------------------------------------------------------- */ 25 | inline 26 | WINbool R3Sphere::Inside(const R3Pt &in_pt) const 27 | { 28 | if (Length(in_pt - Center()) < Radius()) return TRUE; 29 | 30 | return FALSE; 31 | } 32 | 33 | /* ------------------------------------------------------------------------- 34 | * DESCR : Are we on the circle ? 35 | * ------------------------------------------------------------------------- */ 36 | inline 37 | WINbool R3Sphere::On(const R3Pt &in_pt) const 38 | { 39 | const double dLen = Length(in_pt - Center()); 40 | if (RNIsZero(Radius() - dLen)) 41 | return TRUE; 42 | 43 | return FALSE; 44 | } 45 | 46 | /* ------------------------------------------------------------------------- 47 | * DESCR : Set two points to be equal 48 | * ------------------------------------------------------------------------- */ 49 | inline 50 | R3Sphere & 51 | R3Sphere::operator=(const R3Sphere &in_s) 52 | { 53 | m_ptCenter = in_s.Center(); 54 | m_dRadius = in_s.Radius(); 55 | 56 | return *this; 57 | } 58 | 59 | 60 | /* ------------------------------------------------------------------------- 61 | * DESCR : Make a sphere from a sphere 62 | * ------------------------------------------------------------------------- */ 63 | inline 64 | R3Sphere::R3Sphere(const R3Pt &in_ptCenter, double in_dR) 65 | : m_dRadius(in_dR), m_ptCenter(in_ptCenter) 66 | { 67 | } 68 | 69 | inline 70 | R3Sphere::R3Sphere(double in_dR) : m_dRadius(in_dR) 71 | { 72 | RNZero(m_ptCenter); 73 | } 74 | 75 | 76 | -------------------------------------------------------------------------------- /vipss/src/surfacer/utils/R2_Boxed_polygon_i.H: -------------------------------------------------------------------------------- 1 | inline WINbool R2BoxedPolygon::IsOutsideBox( double dX, double dY ) const 2 | { 3 | if ( dX < m_dWMin || dX > m_dWMax || 4 | dY < m_dHMin || dY > m_dHMax ) 5 | return TRUE; 6 | return FALSE; 7 | } 8 | 9 | inline WINbool R2BoxedPolygon::IsInsideBox( double dX, double dY ) const 10 | { 11 | if ( dX > m_dWMin && dX < m_dWMax && dY > m_dHMin && dY < m_dHMax ) 12 | return TRUE; 13 | return FALSE; 14 | } 15 | 16 | inline 17 | R2BoxedPolygon::R2BoxedPolygon(int in_iNPts) : R2Polygon(in_iNPts) 18 | { 19 | Set_dim(); 20 | } 21 | 22 | inline void R2BoxedPolygon::Set_dim() 23 | { 24 | if (Num_pts() <= 0) { 25 | m_dHMax = m_dHMin = m_dWMax = m_dWMin = 1e30; 26 | return; 27 | } 28 | 29 | m_dHMax = (*this)[0][1]; 30 | m_dHMin = (*this)[0][1]; 31 | m_dWMax = (*this)[0][0]; 32 | m_dWMin = (*this)[0][0]; 33 | m_ptCentroid = (*this)[0]; 34 | for (int i = 1; i < Num_pts(); i++) { 35 | m_dHMax = WINmax( m_dHMax, (*this)[i][1] ); 36 | m_dHMin = WINmin( m_dHMin, (*this)[i][1] ); 37 | m_dWMax = WINmax( m_dWMax, (*this)[i][0] ); 38 | m_dWMin = WINmin( m_dWMin, (*this)[i][0] ); 39 | m_ptCentroid[0] += (*this)[i][0]; 40 | m_ptCentroid[1] += (*this)[i][1]; 41 | } 42 | m_ptCentroid[0] /= (double) Num_pts(); 43 | m_ptCentroid[1] /= (double) Num_pts(); 44 | 45 | R2Vec v1( (*this)[1] - (*this)[0] ), v2 ( (*this)[2] - (*this)[1] ); 46 | R3Vec cross( Cross( R3Vec(v1[0], v1[1], 0), R3Vec(v2[0], v2[1], 0) ) ); 47 | if ( cross[2] > 0 ) 48 | m_bClockwise = TRUE; 49 | else 50 | m_bClockwise = FALSE; 51 | } 52 | 53 | inline 54 | R2BoxedPolygon::R2BoxedPolygon( const R2Polygon &in_oPoly) : R2Polygon(in_oPoly) 55 | { 56 | Set_dim(); 57 | } 58 | 59 | inline R2BoxedPolygon &R2BoxedPolygon::operator=( const R2BoxedPolygon &in_oPoly) 60 | { 61 | (*this).R2Polygon::operator=(in_oPoly); 62 | m_dHMax = in_oPoly.m_dHMax; 63 | m_dHMin = in_oPoly.m_dHMin; 64 | m_dWMax = in_oPoly.m_dWMax; 65 | m_dWMin = in_oPoly.m_dWMin; 66 | m_ptCentroid = in_oPoly.m_ptCentroid; 67 | m_bClockwise = in_oPoly.m_bClockwise; 68 | 69 | return *this; 70 | } 71 | inline R2BoxedPolygon &R2BoxedPolygon::operator=( const R2Polygon &in_oPoly) 72 | { 73 | (*this).R2Polygon::operator=(in_oPoly); 74 | Set_dim(); 75 | return *this; 76 | } 77 | 78 | inline 79 | R2BoxedPolygon::R2BoxedPolygon( const R2BoxedPolygon &in_oPoly) 80 | { 81 | (*this) = in_oPoly; 82 | } 83 | -------------------------------------------------------------------------------- /vipss/src/surfacer/utils/Rn_Point4_i.H: -------------------------------------------------------------------------------- 1 | // ========================================================= 2 | // 3 | // Methods for R4PointTC template class 4 | // 5 | // ========================================================= 6 | 7 | 8 | // ------------------------------------- 9 | // constructors 10 | // ------------------------------------- 11 | 12 | template 13 | inline 14 | R4PointTC::R4PointTC ( const Coord& _x, const Coord& _y, const Coord& _z, const Coord& _w ) 15 | { 16 | x = _x; y = _y; z = _z; w = _w; 17 | } 18 | 19 | 20 | // ------------------------------------- 21 | // constructors 22 | // ------------------------------------- 23 | 24 | template 25 | inline R4PointTC& 26 | R4PointTC::operator += ( const R4VectorTC& vDelta ) 27 | { 28 | x += vDelta[0]; 29 | y += vDelta[1]; 30 | z += vDelta[2]; 31 | w += vDelta[3]; 32 | return *this; 33 | } 34 | 35 | template 36 | inline R4PointTC& 37 | R4PointTC::operator -= (const R4VectorTC& vDelta ) 38 | { 39 | x -= vDelta[0]; 40 | y -= vDelta[1]; 41 | z -= vDelta[2]; 42 | 2 -= vDelta[3]; 43 | return *this; 44 | } 45 | 46 | // ------------------------------------- 47 | // binary operators 48 | // ------------------------------------- 49 | 50 | 51 | 52 | // ------------------------------------- 53 | // point dominance 54 | // ------------------------------------- 55 | 56 | template 57 | inline WINbool 58 | R4PointTC::operator < ( const R4PointTC& p ) const 59 | { 60 | return (x < p.x && y < p.y && z < p.z && w < p.w) ? TRUE : FALSE; 61 | } 62 | 63 | template 64 | inline WINbool 65 | R4PointTC::operator<= ( const R4PointTC& p ) const 66 | { 67 | return (x <= p.x && y <= p.y && z <= p.z && w <= p.w) ? TRUE : FALSE; 68 | } 69 | 70 | 71 | 72 | // ------------------------------------- 73 | // Read/write/print functions 74 | // ------------------------------------- 75 | template 76 | inline void R4PointTC::Write(ofstream &out) const 77 | { 78 | out << x << " " << y << " " << z << " " << w << " "; 79 | } 80 | 81 | template 82 | inline WINbool R4PointTC::Read(ifstream &in) 83 | { 84 | in >> x >> y >> z >> w; 85 | 86 | return in.good() ? TRUE : FALSE; 87 | } 88 | 89 | template 90 | inline void R4PointTC::Print( const WINbool in_bDoReturn ) const 91 | { 92 | TRACE("(%f, %f, %f, %f)", x,y,z,w); 93 | if ( in_bDoReturn == TRUE ) 94 | TRACE("\n"); 95 | else 96 | TRACE("\n"); 97 | } 98 | 99 | -------------------------------------------------------------------------------- /vipss/src/surfacer/utils/Rn_Vector1_i.H: -------------------------------------------------------------------------------- 1 | // ========================================================= 2 | // 3 | // Methods for R1VectorTC template class 4 | // 5 | // ========================================================= 6 | 7 | // ------------------------------------- 8 | // constructors 9 | // ------------------------------------- 10 | 11 | template 12 | inline 13 | R1VectorTC::R1VectorTC( const Coord _d ) 14 | { 15 | d = _d; 16 | } 17 | 18 | template 19 | inline R1VectorTC 20 | R1VectorTC::operator + () const 21 | { 22 | return *this; 23 | } 24 | 25 | template 26 | inline R1VectorTC 27 | R1VectorTC::operator - () const 28 | { 29 | return R1VectorTC( -d ); 30 | } 31 | 32 | 33 | // ------------------------------------- 34 | // assignment operators 35 | // ------------------------------------- 36 | 37 | template 38 | inline R1VectorTC& 39 | R1VectorTC::operator += ( const R1VectorTC& v ) 40 | { 41 | d += v.d; 42 | return *this; 43 | } 44 | 45 | template 46 | inline R1VectorTC& 47 | R1VectorTC::operator -= ( const R1VectorTC& v ) 48 | { 49 | d -= v.d; 50 | return *this; 51 | } 52 | 53 | 54 | template 55 | inline R1VectorTC& 56 | R1VectorTC::operator *= ( const Coord& s ) 57 | { 58 | d *= s; 59 | return *this; 60 | } 61 | 62 | template 63 | inline R1VectorTC& 64 | R1VectorTC::operator /= ( const Coord& s ) 65 | { 66 | d /= s; 67 | return *this; 68 | } 69 | 70 | // ------------------------------------- 71 | // Self-editing functions 72 | // ------------------------------------- 73 | 74 | template 75 | inline double R1VectorTC::Normalize() 76 | { 77 | const double dLen = d; 78 | 79 | d = 1.0; 80 | return dLen; 81 | } 82 | 83 | // ------------------------------------- 84 | // Read/write/print functions 85 | // ------------------------------------- 86 | template 87 | inline void R1VectorTC::Write(ofstream &out) const 88 | { 89 | out << d << " "; 90 | } 91 | 92 | template 93 | inline WINbool R1VectorTC::Read(ifstream &in) 94 | { 95 | in >> d; 96 | 97 | return in.good() ? TRUE : FALSE; 98 | } 99 | 100 | template 101 | inline void R1VectorTC::Print( const WINbool in_bDoReturn ) const 102 | { 103 | cout << d; 104 | if ( in_bDoReturn == TRUE ) 105 | cout << "\n"; 106 | else 107 | cout << " "; 108 | } 109 | -------------------------------------------------------------------------------- /vipss/src/surfacer/utils/Rn_CoVector2_i.H: -------------------------------------------------------------------------------- 1 | 2 | // ========================================================= 3 | // 4 | // Methods for R2CoVectorTC template class 5 | // 6 | // ========================================================= 7 | 8 | 9 | // ------------------------------------- 10 | // constructors 11 | // ------------------------------------- 12 | 13 | template 14 | inline 15 | R2CoVectorTC::R2CoVectorTC( const Coord& _du, const Coord& _dv ) 16 | { 17 | du = _du; dv = _dv; 18 | } 19 | 20 | // ------------------------------------- 21 | // assignment operators 22 | // ------------------------------------- 23 | 24 | template 25 | inline R2CoVectorTC& 26 | R2CoVectorTC::operator += ( const R2CoVectorTC& v ) 27 | { 28 | du += v.du; 29 | dv += v.dv; 30 | return *this; 31 | } 32 | 33 | template 34 | inline R2CoVectorTC& 35 | R2CoVectorTC::operator -= ( const R2CoVectorTC& v ) 36 | { 37 | du -= v.du; 38 | dv -= v.dv; 39 | return *this; 40 | } 41 | 42 | template 43 | inline R2CoVectorTC& 44 | R2CoVectorTC::operator *= ( const Coord& s ) 45 | { 46 | du *= s; 47 | dv *= s; 48 | return *this; 49 | } 50 | 51 | template 52 | inline R2CoVectorTC& 53 | R2CoVectorTC::operator /= ( const Coord& s ) 54 | { 55 | du /= s; 56 | dv /= s; 57 | return *this; 58 | } 59 | 60 | // ------------------------------------- 61 | // unary operators 62 | // ------------------------------------- 63 | 64 | template 65 | inline R2CoVectorTC 66 | R2CoVectorTC::operator + () const 67 | { 68 | return *this; 69 | } 70 | 71 | template 72 | inline R2CoVectorTC 73 | R2CoVectorTC::operator - () const 74 | { 75 | return R2CoVectorTC( -du, -dv ); 76 | } 77 | 78 | 79 | 80 | 81 | // ------------------------------------- 82 | // Read/write/print functions 83 | // ------------------------------------- 84 | template 85 | inline void R2CoVectorTC::Write(ofstream &out) const 86 | { 87 | out << du << " " << dv << " "; 88 | } 89 | 90 | template 91 | inline WINbool R2CoVectorTC::Read(ifstream &in) 92 | { 93 | in >> du >> dv; 94 | 95 | return in.good() ? TRUE : FALSE; 96 | } 97 | 98 | template 99 | inline void R2CoVectorTC::Print( WINbool in_bDoReturn ) const 100 | { 101 | cout << du << dv; 102 | if ( in_bDoReturn == TRUE ) 103 | cout << "\n"; 104 | else 105 | cout << " "; 106 | } 107 | -------------------------------------------------------------------------------- /vipss/src/surfacer/utils/C2_ComplexNumbers.H: -------------------------------------------------------------------------------- 1 | #ifndef _CS_COMPLEX_NUMBERS_DEFS_H 2 | #define _CS_COMPLEX_NUMBERS_DEFS_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | //#include 10 | 11 | 12 | /// 13 | template 14 | inline 15 | void C2FindRoots( const Array &in_adPoly, Array< C2PointTC > &out_adRoots ) 16 | { 17 | int iHighestPower = 0; 18 | for ( int i = 0; i < in_adPoly.num(); i++ ) { 19 | if ( !RNIsZero( (T) in_adPoly[i] ) ) 20 | iHighestPower = i; 21 | } 22 | 23 | out_adRoots.need( iHighestPower ); 24 | 25 | if ( iHighestPower == 0 ) { 26 | return; 27 | } else if ( iHighestPower == 1 ) { 28 | // a x + b == 0 => x == - b / a 29 | out_adRoots[0] = C2PointTC( -in_adPoly[0] / in_adPoly[1], 0.0 ); 30 | } else if ( iHighestPower == 2 ) { 31 | const T dSqrt = pow(in_adPoly[1], 2) - 4.0 * in_adPoly[0] * in_adPoly[2]; 32 | if ( dSqrt >= 0.0 ) { 33 | out_adRoots[0] = C2PointTC( ( - in_adPoly[1] + sqrt( dSqrt ) ) / (2.0 * in_adPoly[2]), 0.0); 34 | out_adRoots[1] = C2PointTC( ( - in_adPoly[1] - sqrt( dSqrt ) ) / (2.0 * in_adPoly[2]), 0.0); 35 | } else { 36 | out_adRoots[0] = C2PointTC( - in_adPoly[1] / (2.0), -sqrt(-dSqrt) / (2.0 * in_adPoly[2]) ); 37 | out_adRoots[1] = C2PointTC( - in_adPoly[1] / (2.0), sqrt(-dSqrt) / (2.0 * in_adPoly[2]) ); 38 | } 39 | } else if ( iHighestPower == 3 ) { 40 | const T dA = in_adPoly[2] / in_adPoly[3]; 41 | const T dB = in_adPoly[1] / in_adPoly[3]; 42 | const T dC = in_adPoly[0] / in_adPoly[3]; 43 | const T dR = ( 9.0 * dA * dB - 27.0 * dC - 2.0 * pow(dA, 3.0) ); 44 | const T dT = ::pow((T)dA,(int)2) - dB * 3.0; 45 | const T dC0 = ::pow(2.0, 1.0 / 3.0); 46 | const T dC1 = ::pow(2.0, 2.0 / 3.0); 47 | const C2PointTC dC2 = C2PointTC(0,2) * dC0; 48 | const C2PointTC dQ = pow( dT,3.0) * -4.0; 49 | const C2PointTC dS = pow( sqrt(dQ + pow(-dR,2.0)) + dR, 1.0 / 3.0); 50 | out_adRoots[0] = ( ( (C2PointTC) dT * 2.0 * dC0 ) / dS + 51 | dS * dC1 - 52 | 2.0 * dA ) * (1.0 / 6.0); 53 | 54 | out_adRoots[1] = ( -( dC2 * ( C2PointTC(0,-1) + ::sqrt(3.0) ) * dT ) / dS + 55 | C2PointTC(0,1) * dC1 * (C2PointTC(0,1) + ::sqrt(3.0) ) * dS - 4.0 * dA) / 12.0; 56 | 57 | out_adRoots[2] = ( ( dC2 * (C2PointTC(0,1) + sqrt(3.0) ) * dT)/ 58 | dS - (C2PointTC) dC1 * (C2PointTC(0,1) * ::sqrt(3.0) + 1.0)* 59 | dS - 4.0 * dA) / 12.0; 60 | } 61 | } 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /vipss/src/surfacer/utils/Rn_Point2_i.H: -------------------------------------------------------------------------------- 1 | 2 | // ========================================================= 3 | // 4 | // Methods for R2PointTC template class 5 | // 6 | // ========================================================= 7 | 8 | 9 | // ------------------------------------- 10 | // constructors 11 | // ------------------------------------- 12 | 13 | template 14 | inline 15 | R2PointTC::R2PointTC ( const Coord _u, const Coord _v ) 16 | { 17 | u = _u; v = _v; 18 | } 19 | 20 | // ------------------------------------- 21 | // Unary operators 22 | // ------------------------------------- 23 | 24 | template 25 | inline R2PointTC& 26 | R2PointTC::operator += (const R2VectorTC& vDelta ) 27 | { 28 | u += vDelta[0]; 29 | v += vDelta[1]; 30 | return *this; 31 | } 32 | 33 | template 34 | inline R2PointTC& 35 | R2PointTC::operator -= (const R2VectorTC& vDelta ) 36 | { 37 | u -= vDelta[0]; 38 | v -= vDelta[1]; 39 | return *this; 40 | } 41 | 42 | // ------------------------------------- 43 | // point dominance 44 | // ------------------------------------- 45 | 46 | /// 47 | template 48 | inline bool 49 | R2PointTC::operator < ( const R2PointTC& p ) const 50 | { 51 | if ( u < p[0] ) return true; 52 | if ( u > p[0] ) return false; 53 | return v < p[1]; 54 | } 55 | 56 | /// 57 | template 58 | inline bool 59 | R2PointTC::operator<= ( const R2PointTC& p ) const 60 | { 61 | if ( u <= p[0] ) return true; 62 | if ( u > p[0] ) return false; 63 | return v <= p[1]; 64 | } 65 | 66 | 67 | 68 | // ------------------------------------- 69 | // Read/write/print functions 70 | // ------------------------------------- 71 | template 72 | inline void R2PointTC::Write(ofstream &out) const 73 | { 74 | out << u << " " << v << " "; 75 | } 76 | 77 | template 78 | inline WINbool R2PointTC::Read(ifstream &in) 79 | { 80 | in >> u >> v; 81 | 82 | return in.good() ? TRUE : FALSE; 83 | } 84 | 85 | template 86 | inline void R2PointTC::WriteBinary(ofstream &out) const 87 | { 88 | out.write( (const char *) &u, Dim() * sizeof(Coord) ); 89 | } 90 | 91 | 92 | template 93 | inline WINbool R2PointTC::ReadBinary(ifstream &in) 94 | { 95 | in.read( (char *) &u, Dim() * sizeof(Coord) ); 96 | 97 | return in.good() ? TRUE : FALSE; 98 | } 99 | 100 | 101 | template 102 | inline void R2PointTC::Print( const WINbool in_bDoReturn ) const 103 | { 104 | TRACE("(%f, %f)", u, v); 105 | if ( in_bDoReturn == TRUE ) 106 | TRACE("\n"); 107 | else 108 | TRACE("\n"); 109 | } 110 | -------------------------------------------------------------------------------- /vipss/src/surfacer/utils/C2_PointTC.H: -------------------------------------------------------------------------------- 1 | #ifndef _C2_POINT_TC_H_DEFS_ 2 | #define _C2_POINT_TC_H_DEFS_ 3 | 4 | #include 5 | 6 | /**name 7 | * A complex number. 8 | * Mirrors the complex number class that windows has yet to deign to add. 9 | */ 10 | template 11 | class C2PointTC { 12 | protected : 13 | T m_dRe, m_dIm; 14 | 15 | public: 16 | /**@name Access */ 17 | //@{ 18 | /// 19 | T real() const { return m_dRe; } 20 | /// 21 | T imag() const { return m_dIm; } 22 | /// 23 | T Length() const { return sqrt( m_dRe * m_dRe + m_dIm * m_dIm ); } 24 | /// 25 | WINbool IsReal( const T in_dEps = RNEpsilon_d) const { return fabs( m_dIm ) < in_dEps ? TRUE : FALSE; } 26 | //@} 27 | 28 | /**@name Setting */ 29 | //@{ 30 | /// 31 | T &real() { return m_dRe; } 32 | /// 33 | T &imag() { return m_dIm; } 34 | /// 35 | void Set( const T in_dRe, const T in_dIm ); 36 | /// 37 | void SetRadiusTheta( const T in_dRadius, const T in_dTheta ); 38 | //@} 39 | 40 | /**@name Assignment operators */ 41 | //@{ 42 | /// 43 | C2PointTC& operator += ( const C2PointTC & ); 44 | /// 45 | C2PointTC& operator -= ( const C2PointTC & ); 46 | /// 47 | C2PointTC& operator *= ( const C2PointTC & ); 48 | /// 49 | C2PointTC& operator /= ( const C2PointTC & ); 50 | //@} 51 | 52 | /**@name operators */ 53 | //@{ 54 | /// 55 | C2PointTC operator+( const C2PointTC &in_pt ) const; 56 | /// 57 | C2PointTC operator+( const T &in_pt ) const; 58 | /// 59 | C2PointTC operator-( const C2PointTC &in_pt ) const; 60 | /// 61 | C2PointTC operator-( const T &in_pt ) const; 62 | /// 63 | C2PointTC operator-( ) const; 64 | /// 65 | C2PointTC operator*( const C2PointTC &in_pt ) const; 66 | /// 67 | C2PointTC operator/( const C2PointTC &in_pt ) const; 68 | //@} 69 | 70 | /**@name Comparison operators */ 71 | //@{ 72 | /// 73 | WINbool operator==( const C2PointTC &in_pt ) const; 74 | /// 75 | WINbool operator!=( const C2PointTC &in_pt ) const; 76 | //@} 77 | 78 | /// 79 | C2PointTC( const T in_dRe, const T in_dIm = 0.0 ) { Set(in_dRe, in_dIm); } 80 | /// 81 | C2PointTC( const C2PointTC &in_pt ) { Set(in_pt.real(), in_pt.imag()); } 82 | /// 83 | C2PointTC() : m_dRe(0), m_dIm(0) {} 84 | /// 85 | ~C2PointTC() {} 86 | 87 | /// 88 | void Write(ostream &out) const { out << m_dRe << " " << m_dIm << "\n"; } 89 | /// 90 | void Read(ifstream &in) { in >> m_dRe >> m_dIm; } 91 | 92 | static WINbool Test(); 93 | }; 94 | 95 | #include "C2_PointTC_i.H" 96 | 97 | typedef C2PointTC C2Pt; 98 | 99 | #endif 100 | -------------------------------------------------------------------------------- /vipss/src/surfacer/utils/R3_Line_seg_i.H: -------------------------------------------------------------------------------- 1 | inline 2 | WINbool R3Line_seg::IsPtOnSeg(const R3Pt &in_pt) const 3 | { 4 | R3Pt out_pt; 5 | double out_t, out_d; 6 | return FindPtOnSeg(in_pt, out_pt, out_t, out_d); 7 | } 8 | 9 | inline 10 | double R3Line_seg::Dist_to_seg(const R3Pt &in_pt) const 11 | { 12 | R3Pt out_pt; 13 | double out_t, out_d; 14 | FindPtOnSeg(in_pt, out_pt, out_t, out_d); 15 | 16 | return out_d; 17 | } 18 | 19 | inline 20 | R3Pt R3Line_seg::Project(const R3Pt &in_pt) const 21 | { 22 | R3Pt out_pt; 23 | double out_t, out_d; 24 | FindPtOnSeg(in_pt, out_pt, out_t, out_d); 25 | 26 | return out_pt; 27 | } 28 | 29 | inline 30 | double 31 | R3Line_seg::Projected_dist_on_seg(const R3Pt &in_pt) const 32 | { 33 | R3Pt out_pt; 34 | double out_t, out_d; 35 | FindPtOnSeg(in_pt, out_pt, out_t, out_d); 36 | 37 | return out_t; 38 | } 39 | 40 | 41 | /* ------------------------------------------------------------------------- 42 | * DESCR : Parallel & perpendicular - use RNline routines 43 | * ------------------------------------------------------------------------- */ 44 | inline 45 | WINbool 46 | IsParallelSeg(const R3Line_seg &in_l1, const R3Line_seg &in_l2) 47 | { 48 | R3Line l1(in_l1.P1(), in_l1.P2() - in_l1.P1()); 49 | R3Line l2(in_l2.P1(), in_l2.P2() - in_l2.P1()); 50 | 51 | return IsParallel(l1, l2); 52 | } 53 | 54 | inline 55 | WINbool 56 | IsPerpendicularSeg(const R3Line_seg &in_l1, const R3Line_seg &in_l2) 57 | { 58 | R3Line l1(in_l1.P1(), in_l1.P2() - in_l1.P1()); 59 | R3Line l2(in_l2.P1(), in_l2.P2() - in_l2.P1()); 60 | 61 | return IsPerpendicular(l1, l2); 62 | } 63 | 64 | 65 | 66 | /* ------------------------------------------------------------------------- 67 | * DESCR : Compare two lines 68 | * ------------------------------------------------------------------------- */ 69 | inline 70 | WINbool R3Line_seg::operator==(const R3Line_seg &in_l) const 71 | { 72 | if (P1() == in_l.P1() && P2() == in_l.P2()) 73 | return TRUE; 74 | 75 | if (P1() == in_l.P2() && P2() == in_l.P1()) 76 | return TRUE; 77 | 78 | return FALSE; 79 | } 80 | 81 | /* ------------------------------------------------------------------------- 82 | * DESCR : Calculate the length of the line segment 83 | * ------------------------------------------------------------------------- */ 84 | inline 85 | double R3Line_seg::Length() const 86 | { 87 | return ::Length(P2() - P1() ); 88 | } 89 | 90 | 91 | inline 92 | R3Pt R3Line_seg::operator()( double s) const 93 | { 94 | return m_pt1 + (m_pt2 - m_pt1) * s; 95 | } 96 | 97 | inline 98 | R3Line_seg &R3Line_seg::operator=(const R3Line_seg &in_l) 99 | { 100 | m_pt1 = in_l.m_pt1; 101 | m_pt2 = in_l.m_pt2; 102 | 103 | return *this; 104 | } 105 | -------------------------------------------------------------------------------- /vipss/src/surfacer/utils/C2_LFTTC.H: -------------------------------------------------------------------------------- 1 | #ifndef _C2_LFTTC_H_DEFS_ 2 | #define _C2_LFTTC_H_DEFS_ 3 | 4 | /** Linear fractional transform 5 | * Essentially a 2x2 matrix made of complex numbers 6 | */ 7 | template 8 | class C2LFTTC { 9 | protected: 10 | C2PointTC m_mat[2][2]; 11 | 12 | public: 13 | /**@name Accessors */ 14 | //@{ 15 | /// Matrix entry 16 | const C2PointTC &operator()( const int i, const int j ) const { return m_mat[i][j]; } 17 | //@} 18 | 19 | /**@name Queries */ 20 | //@{ 21 | /// 22 | WINbool IsIdentity( const T dEps = RNEpsilon_d ) const; 23 | //@} 24 | 25 | //@name Assignment */ 26 | //@{ 27 | /// Matrix entry 28 | C2PointTC &operator()( const int i, const int j ) { return m_mat[i][j]; } 29 | 30 | /// Identity 31 | /// 1 0 32 | /// 0 1 33 | void SetIdentity( ); 34 | /// Scale the point up (s is the scale factor) 35 | /// s 0 36 | /// 0 1 37 | void SetScale( const C2PointTC &in_pt ); 38 | /// translate 39 | /// 1 t 40 | /// 0 1 41 | void SetTrans( const C2PointTC &in_pt ); 42 | /// Invert matrix 43 | /// a b ^-1 = d -b 44 | // c d -c a 45 | void SetInvert( const C2LFTTC &in_mat ); 46 | /// Rotation 47 | /// 1 r 48 | /// r* 1 49 | void SetFlip( const C2PointTC &in_pt ); 50 | //@} 51 | 52 | //@name operators */ 53 | //@{ 54 | /// Multiplication by a point (like multiplication of a homogeneous point by a matrix) 55 | /// a b z = (a z + b) / (c z + d) 56 | /// c d 1 57 | C2PointTC operator *( const C2PointTC &in_pt ) const; 58 | 59 | /// Multiplication by a matrix (like a regular matrix) 60 | C2LFTTC operator *( const C2LFTTC &in_mat ) const; 61 | //@} 62 | 63 | /**@name Comparisonn operators */ 64 | //@{ 65 | /// Comparison 66 | WINbool operator==( const C2LFTTC &in_mat ) const; 67 | /// 68 | WINbool operator!=( const C2LFTTC &in_mat ) const; 69 | //@} 70 | 71 | 72 | /**@name Constructors */ 73 | //@{ 74 | C2LFTTC( const C2PointTC &in_a00, 75 | const C2PointTC &in_a01, 76 | const C2PointTC &in_a10, 77 | const C2PointTC &in_a11 ); 78 | /// 79 | C2LFTTC( ) { SetIdentity(); } 80 | /// 81 | C2LFTTC( const C2LFTTC &in_mat ) { *this = in_mat; } 82 | ~C2LFTTC() { } 83 | //@} 84 | 85 | /// 86 | void Write(ofstream &out) const ; 87 | /// 88 | void Read(ifstream &in) ; 89 | /// 90 | void WriteBinary(ofstream &out) const ; 91 | /// 92 | void ReadBinary(ifstream &in) ; 93 | 94 | static void TestLFT(); 95 | }; 96 | 97 | #include "C2_LFTTC_i.H" 98 | 99 | typedef C2LFTTC C2LFT; 100 | 101 | #endif 102 | -------------------------------------------------------------------------------- /vipss/src/surfacer/utils/Rn_Point3_i.H: -------------------------------------------------------------------------------- 1 | // ========================================================= 2 | // 3 | // Methods for R3PointTC template class 4 | // 5 | // ========================================================= 6 | 7 | 8 | // ------------------------------------- 9 | // constructors 10 | // ------------------------------------- 11 | 12 | template 13 | inline 14 | R3PointTC::R3PointTC ( const Coord& _x, const Coord& _y, const Coord& _z ) 15 | { 16 | x = _x; y = _y; z = _z; 17 | } 18 | 19 | 20 | 21 | // ------------------------------------- 22 | // constructors 23 | // ------------------------------------- 24 | 25 | template 26 | inline R3PointTC& 27 | R3PointTC::operator += ( const R3VectorTC& vDelta ) 28 | { 29 | x += vDelta[0]; 30 | y += vDelta[1]; 31 | z += vDelta[2]; 32 | return *this; 33 | } 34 | 35 | template 36 | inline R3PointTC& 37 | R3PointTC::operator -= (const R3VectorTC& vDelta ) 38 | { 39 | x -= vDelta[0]; 40 | y -= vDelta[1]; 41 | z -= vDelta[2]; 42 | return *this; 43 | } 44 | 45 | // ------------------------------------- 46 | // binary operators 47 | // ------------------------------------- 48 | 49 | 50 | 51 | // ------------------------------------- 52 | // point dominance 53 | // ------------------------------------- 54 | 55 | template 56 | inline WINbool 57 | R3PointTC::operator < ( const R3PointTC& p ) const 58 | { 59 | return (x < p.x && y < p.y && z < p.z) ? TRUE : FALSE; 60 | } 61 | 62 | template 63 | inline WINbool 64 | R3PointTC::operator<= ( const R3PointTC& p ) const 65 | { 66 | return (x <= p.x && y <= p.y && z <= p.z) ? TRUE : FALSE; 67 | } 68 | 69 | 70 | // ------------------------------------- 71 | // Read/write/print functions 72 | // ------------------------------------- 73 | template 74 | inline void R3PointTC::Write(ofstream &out) const 75 | { 76 | out << x << " " << y << " " << z << " "; 77 | } 78 | 79 | template 80 | inline void R3PointTC::WriteBinary(ofstream &out) const 81 | { 82 | out.write( (const char *) &x, Dim() * sizeof(Coord) ); 83 | } 84 | 85 | template 86 | inline WINbool R3PointTC::Read(ifstream &in) 87 | { 88 | in >> x >> y >> z; 89 | 90 | return in.good() ? TRUE : FALSE; 91 | } 92 | 93 | template 94 | inline WINbool R3PointTC::ReadBinary(ifstream &in) 95 | { 96 | in.read( (char *) &x, Dim() * sizeof(Coord) ); 97 | 98 | return in.good() ? TRUE : FALSE; 99 | } 100 | 101 | template 102 | inline void R3PointTC::Print( const WINbool in_bDoReturn ) const 103 | { 104 | TRACE("(%f, %f, %f)", x,y,z); 105 | 106 | if ( in_bDoReturn == TRUE ) 107 | TRACE("\n"); 108 | else 109 | TRACE("\n"); 110 | } 111 | -------------------------------------------------------------------------------- /vipss/src/surfacer/utils/BaryPoly.h: -------------------------------------------------------------------------------- 1 | #ifndef BARY_POLY_H 2 | #define BARY_POLY_H 3 | 4 | #include 5 | 6 | WINbool CalculateWeights( const PMeshLite &in_mesh, const R3Pt &in_pt, Array &out_adWeights ); 7 | 8 | /// Sorts points by angle in tangent plane first 9 | double LaplacianWeights( const R3Pt &in_pt, const R3Vec &in_vecNorm, const Array &in_apt, Array &out_adWeights ); 10 | 11 | /// Assumes points ordered 12 | double LaplacianWeights( const R3Pt &in_pt, const Array &in_apt, Array &out_adWeights ); 13 | 14 | // Project onto plane by distributing angle error and keeping length 15 | void ProjectPlane( const R3Pt &in_pt, const Array &in_apt, Array &out_apt2D ); 16 | 17 | /// Uses projection to sort 18 | double FloaterWeights( const R3Pt &in_pt, const R3Vec &in_vecNorm, const Array &in_apt, Array &out_adWeights ); 19 | 20 | /// Assumes points are already sorted 21 | double FloaterWeights( const R3Pt &in_pt, const Array &in_apt, Array &out_adWeights ); 22 | 23 | namespace Strain { 24 | 25 | /// Find the symmetric matrix that aligns the two points 26 | R3Matrix MatrixAlign( const Array &in_apt1, const Array &in_apt2 ); 27 | 28 | void DiscreteStrain( const Array &in_apt1, const Array &in_apt2, const R3Vec &in_vecNormPts2, 29 | R3Matrix &out_matF, R3Matrix &out_matR1To2 ); 30 | 31 | /// Calculate the max,min strain of the deformation between two sets of points 32 | pair DiscreteStrain( const Array &in_apt1, const Array &in_apt2, const R3Vec &in_vecNormPts2, 33 | R3Matrix &out_matF ); 34 | 35 | /// Same as above, but calculates the normal for you. 36 | pair DiscreteStrain( const Array &in_apt1, const Array &in_apt2, R3Matrix &out_matF ); 37 | 38 | /// Same as above, but uses vecDs and vecDt to determine normal 39 | /// Returns the 2D tensor in out_matFij 40 | pair DiscreteStrain( const Array &in_apt1, const Array &in_apt2, const R3Vec &in_vecDs, const R3Vec &in_vecDt, R3Matrix &out_matFij ); 41 | 42 | 43 | /// Calculates strains based on fitting a surface to the points and using derivatives 44 | /// Assumes points are sampled at same s,t values 45 | /// Returns the 2D tensor in out_matFij 46 | pair AnalyticStrain( const Array &in_apt1, const Array &in_apt2 ); 47 | 48 | /// Works from the raw derivatives - assumes using the same parameter space, i.e., f(s,t) = f'(s,t) everywhere 49 | /// Returns the 2D tensor in out_matFij 50 | pair AnalyticStrain( R2Matrix &out_matFij, const R3Vec &in_vecDs1, const R3Vec &in_vecDt1, const R3Vec &in_vecDs2, const R3Vec &in_vecDt2 ); 51 | 52 | void AnalyticStrain3D(const R3Vec &vSA, const R3Vec &vTA, const R3Vec &vSB, const R3Vec &vTB, 53 | double &out_E1, double &out_E2, double &out_e1, double &out_e2); 54 | } 55 | #endif 56 | -------------------------------------------------------------------------------- /vipss/src/surfacer/utils/Rn_CoVector4_i.H: -------------------------------------------------------------------------------- 1 | // ========================================================= 2 | // 3 | // Methods for R4CoVectorTC template class 4 | // 5 | // ========================================================= 6 | 7 | 8 | // ------------------------------------- 9 | // constructors 10 | // ------------------------------------- 11 | 12 | template 13 | inline 14 | R4CoVectorTC::R4CoVectorTC( const Coord& _dx, const Coord& _dy, const Coord& _dz, const Coord & _dw ) 15 | { 16 | dx = _dx; dy = _dy; dz = _dz; dw = _dw; 17 | } 18 | 19 | // ------------------------------------- 20 | // assignment operators 21 | // ------------------------------------- 22 | 23 | template 24 | inline R4CoVectorTC& 25 | R4CoVectorTC::operator += ( const R4CoVectorTC& v) 26 | { 27 | dx += v[0]; 28 | dy += v[1]; 29 | dz += v[2]; 30 | dw += v[3]; 31 | return *this; 32 | } 33 | 34 | template 35 | inline R4CoVectorTC& 36 | R4CoVectorTC::operator -= ( const R4CoVectorTC& v ) 37 | { 38 | dx -= v[0]; 39 | dy -= v[1]; 40 | dz -= v[2]; 41 | dw -= v[3]; 42 | return *this; 43 | } 44 | 45 | template 46 | inline R4CoVectorTC& 47 | R4CoVectorTC::operator *= ( const Coord& s ) 48 | { 49 | dx *= s; 50 | dy *= s; 51 | dz *= s; 52 | dw *= s; 53 | return *this; 54 | } 55 | 56 | template 57 | inline R4CoVectorTC& 58 | R4CoVectorTC::operator /= ( const Coord& s ) 59 | { 60 | ASSERT( !RNIsZero( s ) ); 61 | Coord s1 = Coord(1.0f) / s; 62 | dx *= s1; 63 | dy *= s1; 64 | dz *= s1; 65 | dw *= s1; 66 | return *this; 67 | } 68 | 69 | // ------------------------------------- 70 | // unary operators 71 | // ------------------------------------- 72 | 73 | template 74 | inline R4CoVectorTC 75 | R4CoVectorTC::operator + () const 76 | { 77 | return *this; 78 | } 79 | 80 | template 81 | inline R4CoVectorTC 82 | R4CoVectorTC::operator - () const 83 | { 84 | return R4CoVectorTC( -dx, -dy, -dz, -dw ); 85 | } 86 | 87 | 88 | 89 | // ------------------------------------- 90 | // Read/write/print functions 91 | // ------------------------------------- 92 | template 93 | inline void R4CoVectorTC::Write(ofstream &out) const 94 | { 95 | out << dx << " " << dy << " " << dz << " " << dw << " "; 96 | } 97 | 98 | template 99 | inline WINbool R4CoVectorTC::Read(ifstream &in) 100 | { 101 | in >> dx >> dy >> dz >> dw; 102 | 103 | return in.good() ? TRUE : FALSE; 104 | } 105 | 106 | template 107 | inline void R4CoVectorTC::Print( WINbool in_bDoReturn ) const 108 | { 109 | cout << dx << " " << dy << " " << dz << " " << dw; 110 | if ( in_bDoReturn == TRUE ) 111 | cout << "\n"; 112 | else 113 | cout << " "; 114 | } 115 | -------------------------------------------------------------------------------- /vipss/src/surfacer/utils/Utils_EdgeFilter.H: -------------------------------------------------------------------------------- 1 | /* 2 | * Utils_EdgeFilter.H 3 | * utils 4 | * 5 | * Created by Cindy Grimm on 12/16/11. 6 | * Copyright 2011 Washington University in St. Louis. All rights reserved. 7 | * 8 | */ 9 | 10 | #ifndef _UTILS_EDGE_FILTER_DEFS_H_ 11 | #define _UTILS_EDGE_FILTER_DEFS_H_ 12 | 13 | #include 14 | 15 | /* Edge filter function 16 | * Difference of Gaussians in the x direction (e1(x) - e2(x)) multiplied 17 | * by a Gaussian in the y direction that is designed to fall off at roughly 3 times 18 | * the width of the x direction filter 19 | * Ie, if you clip the filter at 2 times sigma, the filter will be mostly zero by then, with 1/2 of the 20 | * radius a "big" peak 21 | * 22 | * sigma 1 is the 23 | */ 24 | class Utils_EdgeFilter { 25 | private: 26 | double m_dTheta, m_dSigma1, m_dSigma2, m_dSigmaY; 27 | double m_dRotCos, m_dRotSin; 28 | double m_dScaleFactorFirst, m_dScaleFactorSecond, m_dScaleFactorY; 29 | double m_dGaussScaleFactorFirst, m_dGaussScaleFactorSecond, m_dGaussScaleFactorY; 30 | 31 | public: 32 | /** Set the filter up 33 | * @param in_dTheta Angle of edge 34 | * @param in_dSigma Width of wider Gaussian 35 | * @param in_dSigmaRatio (should be < 1) width of skinnier Gaussian. Default is 0.25 36 | */ 37 | void SetFilterParams( const double in_dTheta, const double in_dSigma, const double in_dSigmaRatio ) 38 | { 39 | m_dTheta = in_dTheta; 40 | m_dRotCos = cos(m_dTheta); 41 | m_dRotSin = sin(m_dTheta); 42 | m_dSigma1 = in_dSigma < 0.0 ? 1.0 : in_dSigma; 43 | m_dSigma2 = m_dSigma1 * ( in_dSigmaRatio < 0.0 ? 0.25 : in_dSigmaRatio); 44 | m_dSigmaY = 3.0 * m_dSigma1; 45 | m_dScaleFactorFirst = 1.0 / ( m_dSigma1 * std::sqrt(2.0*M_PI) ); 46 | m_dScaleFactorSecond = 1.0 / ( m_dSigma2 * std::sqrt(2.0*M_PI) ); 47 | m_dScaleFactorY = 1.0 / ( m_dSigmaY * std::sqrt(2.0*M_PI) ); 48 | m_dGaussScaleFactorFirst = (2.0*m_dSigma1*m_dSigma1); 49 | m_dGaussScaleFactorSecond = (2.0*m_dSigma2*m_dSigma2); 50 | m_dGaussScaleFactorY = (2.0*m_dSigmaY*m_dSigmaY); 51 | } 52 | 53 | double operator()( const double in_dX, const double in_dY ) const 54 | { 55 | const double dX = m_dRotCos * in_dX + m_dRotSin * in_dY; 56 | const double dY = -m_dRotSin * in_dX + m_dRotCos * in_dY; 57 | const double dYFalloff = m_dScaleFactorY * std::exp( -pow(dY,2.0) / m_dGaussScaleFactorY ); 58 | const double dXFalloff = 59 | -m_dScaleFactorFirst * std::exp( -pow(dX,2.0) / m_dGaussScaleFactorFirst ) + 60 | m_dScaleFactorSecond * std::exp( -pow(dX,2.0) / m_dGaussScaleFactorSecond ); 61 | return dXFalloff * dYFalloff; 62 | } 63 | double MaxEdgeFunction( ) const 64 | { 65 | return m_dScaleFactorY * ( m_dScaleFactorFirst - m_dScaleFactorSecond ); 66 | } 67 | 68 | 69 | Utils_EdgeFilter() { SetFilterParams( 0.0, 1.0, 0.25 ); } 70 | ~Utils_EdgeFilter() {} 71 | }; 72 | 73 | #endif -------------------------------------------------------------------------------- /vipss/src/surfacer/utils/R2_Ellipse_i.H: -------------------------------------------------------------------------------- 1 | /* ------------------------------------------------------------------------- 2 | * DESCR : Compare two points 3 | * ------------------------------------------------------------------------- */ 4 | inline 5 | WINbool R2Ellipse::operator==(const R2Ellipse &in_Ellipse) const 6 | { 7 | return ApproxEqual( *this, in_Ellipse ); 8 | } 9 | 10 | inline 11 | WINbool R2Ellipse::ApproxEqual(const R2Ellipse &in_ell1, const R2Ellipse &in_ell2, const double in_dEps) 12 | { 13 | if (::ApproxEqual(in_ell1.Center(), in_ell2.Center(), in_dEps) == FALSE) return FALSE; 14 | 15 | if ( RNApproxEqual( in_ell1.Rotation(), in_ell2.Rotation(), in_dEps ) || 16 | RNApproxEqual( in_ell1.Rotation(), in_ell2.Rotation() - M_PI, in_dEps ) || 17 | RNApproxEqual( in_ell1.Rotation(), in_ell2.Rotation() + M_PI, in_dEps ) ) { 18 | 19 | if (!RNIsZero(in_ell2.XRadius() - in_ell1.XRadius(), in_dEps)) return FALSE; 20 | if (!RNIsZero(in_ell2.YRadius() - in_ell1.YRadius(), in_dEps)) return FALSE; 21 | 22 | return TRUE; 23 | } 24 | 25 | if ( RNApproxEqual( in_ell1.Rotation(), in_ell2.Rotation() - M_PI / 2.0, in_dEps ) || 26 | RNApproxEqual( in_ell1.Rotation(), in_ell2.Rotation() + M_PI / 2.0, in_dEps ) || 27 | RNApproxEqual( in_ell1.Rotation(), in_ell2.Rotation() + 3.0 * M_PI / 2.0, in_dEps ) || 28 | RNApproxEqual( in_ell1.Rotation(), in_ell2.Rotation() - 3.0 * M_PI / 2.0, in_dEps ) ) { 29 | 30 | if (!RNIsZero(in_ell2.XRadius() - in_ell1.YRadius(), in_dEps)) return FALSE; 31 | if (!RNIsZero(in_ell2.YRadius() - in_ell1.XRadius(), in_dEps)) return FALSE; 32 | 33 | return TRUE; 34 | } 35 | 36 | return FALSE; 37 | } 38 | 39 | /* ------------------------------------------------------------------------- 40 | * DESCR : Evaluate implicit equation 41 | * ------------------------------------------------------------------------- */ 42 | inline 43 | double R2Ellipse::operator()( const R2Pt &in_pt ) const 44 | { 45 | return m_adCoef[0] * in_pt[0] * in_pt[0] + 46 | m_adCoef[1] * in_pt[0] * in_pt[1] + 47 | m_adCoef[2] * in_pt[1] * in_pt[1] + 48 | m_adCoef[3] * in_pt[0] + 49 | m_adCoef[4] * in_pt[1] + 50 | m_adCoef[5]; 51 | 52 | } 53 | 54 | 55 | /* ------------------------------------------------------------------------- 56 | * DESCR : Are we inside the circle (open disk)? 57 | * ------------------------------------------------------------------------- */ 58 | inline 59 | WINbool R2Ellipse::Inside(const R2Pt &in_pt) const 60 | { 61 | if ( (*this)(in_pt) <= 0 ) return TRUE; 62 | 63 | return FALSE; 64 | } 65 | 66 | /* ------------------------------------------------------------------------- 67 | * DESCR : Are we on the circle ? 68 | * ------------------------------------------------------------------------- */ 69 | inline 70 | WINbool R2Ellipse::On(const R2Pt &in_pt) const 71 | { 72 | return RNIsZero( (*this)(in_pt) ); 73 | } 74 | 75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /vipss/src/surfacer/utils/Utils_GaborFilter.H: -------------------------------------------------------------------------------- 1 | /* 2 | * Utils_GaborFilter.H 3 | * utils 4 | * 5 | * Created by Cindy Grimm on 12/13/11. 6 | * Copyright 2011 Washington University in St. Louis. All rights reserved. 7 | * 8 | */ 9 | 10 | #ifndef _UTILS_GABOR_FILTER_DEFS_H_ 11 | #define _UTILS_GABOR_FILTER_DEFS_H_ 12 | 13 | #include 14 | 15 | /* Gabor filter function 16 | * dx : the horizontal distance between the focal point and center of the filter 17 | * dy : the vertical distance between the focal point and center of the filter 18 | * angle (theta) : the angle of the Gabor filter 19 | * frequency (phi) : the frequency of the Gabor filter 20 | * sigma : the variance of the normal distribution, or: the effective distance (i.e. size) of the filter. 21 | * 22 | * g(x,y) exp( 2 pi i phi( x cos theta + y sin theta) ) 23 | * 24 | * g(x,y) = 1 / (2 pi sigma^2) e( -(x^2 + y^2) / (2 sigma^2) ) 25 | * 26 | * G(x,y,S,F,W,P)=k*Gaussian(x,y,S)*(Sinusoid(x,y,F,W,P)-DC(F,S,P)), 27 | * where: 28 | * Gaussian(x,y,S)=exp(-pi*S^2*(x^2+y^2)) 29 | * Sinusoid(x,y,F,W,P)=exp(j*(2*pi*F*(x*cos(W)+y*sin(W))+P))) 30 | * DC(F,S,P)=exp(-pi*(F/S)^2+j*P) 31 | */ 32 | class Utils_GaborFilter { 33 | private: 34 | double m_dTheta, m_dSigma, m_dFrequency; 35 | double m_dGaborScaleX, m_dGaborScaleY, m_dScaleFactor, m_dGaussScaleFactor; 36 | 37 | public: 38 | void SetFilterParams( const double in_dTheta, const double in_dSigma, const double in_dFrequency ) 39 | { 40 | m_dTheta = in_dTheta; 41 | m_dSigma = in_dSigma < 0.0 ? 1.0 : in_dSigma; 42 | m_dFrequency = in_dFrequency; 43 | m_dGaborScaleX = std::cos(in_dTheta)* m_dFrequency; //Sometimes called 'k0x' 44 | m_dGaborScaleY = std::sin(in_dTheta)* m_dFrequency; //Sometimes called 'k0y' 45 | m_dScaleFactor = 1.0 / ( std::sqrt(2.0*M_PI*m_dSigma*m_dSigma) ); 46 | m_dGaussScaleFactor = (2.0*m_dSigma*m_dSigma); 47 | } 48 | 49 | double operator()( const double in_dX, const double in_dY ) const 50 | { 51 | return (std::cos((m_dGaborScaleX * in_dX)+(m_dGaborScaleY * in_dY)) 52 | * m_dScaleFactor // g(x,y) 53 | * std::exp(-1.0 * ((in_dX*in_dX)+(in_dY*in_dY)) / m_dGaussScaleFactor) 54 | 55 | ); 56 | } 57 | std::pair ComplexEval( const double in_dX, const double in_dY ) const 58 | { 59 | const double dGaussFactor = m_dScaleFactor * std::exp(-1.0 * ((in_dX*in_dX)+(in_dY*in_dY)) / m_dGaussScaleFactor); 60 | const double dExpVal = (m_dGaborScaleX * in_dX)+(m_dGaborScaleY * in_dY); 61 | std::pair ptRet; 62 | ptRet.first = std::cos(dExpVal) * dGaussFactor; 63 | ptRet.second = std::sin(dExpVal) * dGaussFactor; 64 | 65 | return ptRet; 66 | } 67 | double MaxGaborFunction( ) const 68 | { 69 | return m_dScaleFactor; 70 | } 71 | 72 | 73 | Utils_GaborFilter() { SetFilterParams( 0.0, 1.0, 1.0 ); } 74 | ~Utils_GaborFilter() {} 75 | }; 76 | 77 | #endif -------------------------------------------------------------------------------- /vipss/src/surfacer/utils/R2_Sphere_i.H: -------------------------------------------------------------------------------- 1 | /* ------------------------------------------------------------------------- 2 | * DESCR : Compare two points 3 | * ------------------------------------------------------------------------- */ 4 | inline 5 | WINbool R2Sphere::operator==(const R2Sphere &in_sphere) const 6 | { 7 | if (ApproxEqual(Center(), in_sphere.Center()) == FALSE) return FALSE; 8 | 9 | if (!RNIsZero(in_sphere.Radius() - Radius())) return FALSE; 10 | 11 | return TRUE; 12 | } 13 | 14 | /* ------------------------------------------------------------------------- 15 | * DESCR : Are we inside the circle (open disk)? 16 | * ------------------------------------------------------------------------- */ 17 | inline 18 | WINbool R2Sphere::Inside(const R2Pt &in_pt) const 19 | { 20 | if (Length(in_pt - Center()) < Radius()) return TRUE; 21 | 22 | return FALSE; 23 | } 24 | 25 | /* ------------------------------------------------------------------------- 26 | * DESCR : Are we inside the circle (open disk)? 27 | * ------------------------------------------------------------------------- */ 28 | inline 29 | WINbool R2Sphere::OnOrInside(const R2Pt &in_pt) const 30 | { 31 | const double dLen = Length(in_pt - Center()); 32 | if ( dLen <= Radius() ) return TRUE; 33 | if ( RNApproxEqual( dLen, Radius() ) ) 34 | return TRUE; 35 | 36 | return FALSE; 37 | } 38 | 39 | 40 | /* ------------------------------------------------------------------------- 41 | * DESCR : Are we on the circle ? 42 | * ------------------------------------------------------------------------- */ 43 | inline 44 | WINbool R2Sphere::On(const R2Pt &in_pt) const 45 | { 46 | if (RNIsZero(Radius() - Length(in_pt - Center()))) return TRUE; 47 | 48 | return FALSE; 49 | } 50 | 51 | /* ------------------------------------------------------------------------- 52 | * DESCR : Distance between centers 53 | * ------------------------------------------------------------------------- */ 54 | inline 55 | WINbool R2Sphere::Overlaps( const R2Sphere & in_circ ) const 56 | { 57 | const double dLen = Length( in_circ.Center() - Center() ); 58 | if ( dLen <= in_circ.Radius() + Radius() ) 59 | return TRUE; 60 | 61 | return FALSE; 62 | } 63 | 64 | /* ------------------------------------------------------------------------- 65 | * DESCR : Set two points to be equal 66 | * ------------------------------------------------------------------------- */ 67 | inline 68 | R2Sphere & 69 | R2Sphere::operator=(const R2Sphere &in_s) 70 | { 71 | m_ptCenter = in_s.Center(); 72 | m_dRadius = in_s.Radius(); 73 | 74 | return *this; 75 | } 76 | 77 | 78 | /* ------------------------------------------------------------------------- 79 | * DESCR : Make a sphere from a sphere 80 | * ------------------------------------------------------------------------- */ 81 | inline 82 | R2Sphere::R2Sphere(const R2Pt &in_ptCenter, double in_dR) 83 | : m_dRadius(in_dR), m_ptCenter(in_ptCenter) 84 | { 85 | } 86 | 87 | inline 88 | R2Sphere::R2Sphere(double in_dR) : m_dRadius(in_dR) 89 | { 90 | RNZero(m_ptCenter); 91 | } 92 | 93 | 94 | -------------------------------------------------------------------------------- /vipss/src/surfacer/utils/Utils_Barys.H: -------------------------------------------------------------------------------- 1 | /* $Id: Utils_Barys.H,v 1.3 2007/10/03 18:53:11 cmg Exp $ */ 2 | 3 | /* Copyright 1991, Brown Computer Graphics Group. All Rights Reserved. */ 4 | 5 | 6 | 7 | /* ------------------------------------------------------------------------- 8 | * 9 | * Bary centric coords on a polygon 10 | * 11 | * ------------------------------------------------------------------------- */ 12 | 13 | #ifndef UTILS_BARY_DEFS 14 | #define UTILS_BARY_DEFS 15 | 16 | #include 17 | 18 | /* ----------------------- Constants ------------------------------- */ 19 | 20 | /* ----------------------- Classes ------------------------------- */ 21 | 22 | /** \class UTILSBarys Utils_Barys.H utils/Utils_Barys.H 23 | \ingroup UtilitiesGeom 24 | \brief Barycentric coords of a triangle, sphere, polygon 25 | 26 | Most of these methods are static functions. Can also create an instance 27 | by passing the class a polygon, then call operators. 28 | 29 | b[0], b[1], b[2] such that sum b[i] = 1 and b[i] * p[i] = point. 30 | 31 |
Files: 32 | - include/utils/Utils_Barys.H 33 | - src/utils/utils/UTILSBarys.cpp 34 | 35 | */ 36 | class UTILSBarys { 37 | private: 38 | UTILSBarys( UTILSBarys & ); 39 | UTILSBarys &operator=( UTILSBarys & ); 40 | 41 | R2Polygon m_poly; 42 | 43 | public: 44 | /// Take barycentric coordinates and return a point in the polygon 45 | R2Pt operator()(const R3Pt &in_ptBary) const; 46 | 47 | /// Take a point in the polygon and return barycentric coordinates 48 | R3Pt Inverse(const R2Pt &in_ptPoly) const; 49 | 50 | /// BaryCoords, triangle 51 | static R3Pt BaryCoords( const R2Polygon &in_poly, const R2Pt &in_pt ); 52 | /// Bary coords, polygon 53 | static Array BaryCoordsFull( const R2Polygon &in_poly, const R2Pt &in_pt ); 54 | /// Reconstruct point, triangle 55 | static R2Pt ReconstructBaryCoords( const R2Polygon &in_poly, const R3Pt &in_ptBary ); /// 56 | /// Reconstruct point, polygon 57 | static R2Pt ReconstructBaryCoords( const R2Polygon &in_poly, const Array &in_adBary ); 58 | /// Spherical bary coords (triangle) 59 | static R3Pt SphericalBaryCoords( const Array &in_avecTri, const R3Vec & ); 60 | /// Reconstruct point on sphere (triangle) 61 | static R3Vec ReconstructSphericalBaryCoords( const Array &in_avecTri, const R3Pt &in_ptBary ); 62 | 63 | /// 64 | UTILSBarys &operator=( const R2Polygon &in_poly ) 65 | { ASSERT( in_poly.Num_pts() == 3 ); m_poly = in_poly; return *this; } 66 | 67 | /// A three sided polygon 68 | UTILSBarys( const R2Polygon &in_poly ) : m_poly(in_poly) 69 | { ASSERT( m_poly.Num_pts() == 3 ); } 70 | /// 71 | virtual ~UTILSBarys() {} 72 | 73 | /// 74 | void Print() const { m_poly.Print(); } 75 | /// 76 | static WINbool Test(); 77 | }; 78 | 79 | inline 80 | R2Pt UTILSBarys::operator()(const R3Pt &in_ptB) const 81 | { 82 | return R2Pt( m_poly[0][0] * in_ptB[0] + m_poly[1][0] * in_ptB[1] + m_poly[2][0] * in_ptB[2], 83 | m_poly[0][1] * in_ptB[0] + m_poly[1][1] * in_ptB[1] + m_poly[2][1] * in_ptB[2] ); 84 | 85 | } 86 | 87 | 88 | #endif 89 | 90 | -------------------------------------------------------------------------------- /vipss/src/surfacer/utils/R3_Line_i.H: -------------------------------------------------------------------------------- 1 | /* ------------------------------------------------------------------------- 2 | * DESCR : Variations on FindPtOnLine 3 | * ------------------------------------------------------------------------- */ 4 | inline double R3Line::Dist_to_line(const R3Pt &in_pt) const 5 | { 6 | R3Pt out_pt; 7 | double out_t, out_d; 8 | FindPtOnLine(in_pt, out_pt, out_t, out_d); 9 | 10 | return out_d; 11 | } 12 | 13 | inline R3Pt R3Line::Project(const R3Pt &in_pt) const 14 | { 15 | R3Pt out_pt; 16 | double out_t, out_d; 17 | FindPtOnLine(in_pt, out_pt, out_t, out_d); 18 | 19 | return out_pt; 20 | } 21 | 22 | inline 23 | double R3Line::Projected_dist_on_line(const R3Pt &in_pt) const 24 | { 25 | R3Pt out_pt; 26 | double out_t, out_d; 27 | FindPtOnLine(in_pt, out_pt, out_t, out_d); 28 | 29 | return out_t; 30 | } 31 | 32 | 33 | /* ------------------------------------------------------------------------- 34 | * DESCR : Determine if the two lines are parallel 35 | * ------------------------------------------------------------------------- */ 36 | inline 37 | WINbool IsParallel(const R3Line &in_l1, const R3Line &in_l3) 38 | { 39 | double res = 1.0f - (double) fabs( Dot(in_l1.Vec(), in_l3.Vec()) ); 40 | if ( RNIsZero( res ) ) 41 | return TRUE; 42 | 43 | return FALSE; 44 | } 45 | 46 | /* ------------------------------------------------------------------------- 47 | * DESCR : Determine if the two lines are perpendicular 48 | * ------------------------------------------------------------------------- */ 49 | inline 50 | WINbool IsPerpendicular(const R3Line &in_l1, const R3Line &in_l3) 51 | { 52 | if ( RNIsZero( Dot( in_l1.Vec(), in_l3.Vec() ) ) ) 53 | return TRUE; 54 | 55 | return FALSE; 56 | } 57 | 58 | 59 | /* ------------------------------------------------------------------------- 60 | * DESCR : Comparison 61 | * ------------------------------------------------------------------------- */ 62 | inline WINbool R3Line::operator==(const R3Line &in_l) const 63 | { 64 | if (ApproxEqual(Vec(), in_l.Vec()) == FALSE) return FALSE; 65 | 66 | if (ApproxEqual(Pt(), in_l.Pt()) == TRUE) return TRUE; 67 | 68 | return FALSE; 69 | } 70 | 71 | 72 | /* ------------------------------------------------------------------------- 73 | * DESCR : Constructors 74 | * ------------------------------------------------------------------------- */ 75 | inline R3Line &R3Line::operator=(const R3Line &in_l) 76 | { 77 | m_pt = in_l.m_pt; 78 | m_vec = in_l.m_vec; 79 | 80 | return *this; 81 | } 82 | 83 | inline void R3Line::SetVec(const R3Vec &in_vec) 84 | { 85 | //ASSERT( ! RNIsZero( Length( m_vec ) ) ); 86 | m_vec = UnitSafe(in_vec); 87 | } 88 | 89 | inline R3Line::R3Line(const R3Pt &in_pt, const R3Vec &in_vec) 90 | : m_pt(in_pt), m_vec( UnitSafe( in_vec ) ) 91 | { 92 | //ASSERT( ! RNIsZero( Length( m_vec ) ) ); 93 | } 94 | 95 | inline R3Line::R3Line(const R3Pt &in_pt1, const R3Pt &in_pt2) 96 | : m_pt( in_pt1 ), m_vec( UnitSafe( in_pt2 - in_pt1 ) ) 97 | { 98 | //ASSERT( ! RNIsZero( Length( m_vec ) ) ); 99 | } 100 | -------------------------------------------------------------------------------- /vipss/src/surfacer/utils/Rn_Unary1_i.H: -------------------------------------------------------------------------------- 1 | // ========================================================= 2 | // 3 | // Unary operators on affine1 classes 4 | // 5 | // ========================================================= 6 | 7 | /** \ingroup SimpleGeometryUnary */ 8 | //@{ 9 | 10 | /// Returns non-negative number 11 | template 12 | inline Coord 13 | Length( const R1VectorTC& v) 14 | { 15 | return (Coord) fabs(v[0]); 16 | } 17 | 18 | /// Length squared 19 | template 20 | inline Coord 21 | LengthSq( const R1VectorTC& v) 22 | { 23 | return v[0]*v[0]; 24 | } 25 | 26 | /// Return a unit length vector. Will fail if length zero 27 | template 28 | inline R1VectorTC 29 | Unit( const R1VectorTC& v) 30 | { 31 | return v / Length(v); 32 | } 33 | 34 | /** \brief "Safe" version of Unit 35 | 36 | @param v input vector 37 | @param out_vIfBad vector to return if v is small 38 | @returns Unit length vector 39 | Returns unit length vector, or out_vIfBad if length is small (1e-12) 40 | */ 41 | template 42 | inline R1VectorTC 43 | UnitSafe( const R1VectorTC& v, const R1VectorTC& out_vIfBad ) 44 | { 45 | Coord dLength = Length( v ); 46 | 47 | if ( fabs( dLength ) < (Coord) 1e-12 ) 48 | return out_vIfBad; 49 | 50 | return v / dLength; 51 | } 52 | 53 | /// Return unit length vector, or vector if length is small (1e-12) 54 | template 55 | inline R1VectorTC 56 | UnitSafe( const R1VectorTC& v ) 57 | { 58 | Coord dLength = Length( v ); 59 | 60 | if ( fabs( dLength ) < (Coord) 1e-12 ) 61 | return v; 62 | 63 | return v / dLength; 64 | } 65 | 66 | /// Maximum of any coordinate 67 | template 68 | inline Coord 69 | MaximumNorm( const R1VectorTC&v) 70 | { 71 | // L-infinity norm 72 | return v[0]; 73 | } 74 | 75 | /// Returns non-negative number 76 | template 77 | inline Coord 78 | Length( const R1CoVectorTC& v) 79 | { 80 | 81 | return (Coord) fabs(v[0]); 82 | } 83 | 84 | 85 | /// Length Squared 86 | template 87 | inline Coord 88 | LengthSq( const R1CoVectorTC& v) 89 | { 90 | 91 | return v[0]*v[0]; 92 | } 93 | 94 | 95 | /// Return a unit length vector. Will fail if length zero 96 | template 97 | inline R1CoVectorTC 98 | Unit( const R1CoVectorTC& v) 99 | { 100 | 101 | return v / Length(v); 102 | } 103 | 104 | 105 | /// Maximum of any coordinate 106 | template 107 | inline Coord 108 | MaximumNorm( const R1CoVectorTC& v ) 109 | { 110 | /// L-infinity norm 111 | return v[0]; 112 | } 113 | //@} 114 | 115 | /** \ingroup SimpleGeometryConversion*/ 116 | //@{ 117 | /// Safe conversion 118 | template 119 | inline R1CoVectorTC 120 | VecToCov( const R1VectorTC& v ) 121 | { 122 | return R1CoVectorTC( v[0] ); 123 | } 124 | 125 | /// Safe conversion 126 | template 127 | inline R1VectorTC 128 | CovToVec( const R1CoVectorTC& cv ) 129 | { 130 | return R1VectorTC( cv[0] ); 131 | } 132 | 133 | 134 | //@} 135 | 136 | -------------------------------------------------------------------------------- /vipss/src/surfacer/utils/Rn_CoVector3_i.H: -------------------------------------------------------------------------------- 1 | // ========================================================= 2 | // 3 | // Methods for R3CoVectorTC template class 4 | // 5 | // ========================================================= 6 | 7 | 8 | // ------------------------------------- 9 | // constructors 10 | // ------------------------------------- 11 | 12 | 13 | template 14 | inline 15 | R3CoVectorTC::R3CoVectorTC( const Coord& _dx, const Coord& _dy, const Coord& _dz ) 16 | { 17 | dx = _dx; dy = _dy; dz = _dz; 18 | } 19 | 20 | // ------------------------------------- 21 | // assignment operators 22 | // ------------------------------------- 23 | 24 | template 25 | inline R3CoVectorTC& 26 | R3CoVectorTC::operator += ( const R3CoVectorTC& v) 27 | { 28 | dx += v.dx; 29 | dy += v.dy; 30 | dz += v.dz; 31 | return *this; 32 | } 33 | 34 | template 35 | inline R3CoVectorTC& 36 | R3CoVectorTC::operator -= ( const R3CoVectorTC& v ) 37 | { 38 | dx -= v.dx; 39 | dy -= v.dy; 40 | dz -= v.dz; 41 | return *this; 42 | } 43 | 44 | template 45 | inline R3CoVectorTC& 46 | R3CoVectorTC::operator *= ( const Coord& s ) 47 | { 48 | dx *= s; 49 | dy *= s; 50 | dz *= s; 51 | return *this; 52 | } 53 | 54 | template 55 | inline R3CoVectorTC& 56 | R3CoVectorTC::operator /= ( const Coord& s ) 57 | { 58 | Coord s1 = Coord(1.0f) / s; 59 | dx *= s1; 60 | dy *= s1; 61 | dz *= s1; 62 | return *this; 63 | } 64 | 65 | // ------------------------------------- 66 | // unary operators 67 | // ------------------------------------- 68 | 69 | template 70 | inline R3CoVectorTC 71 | R3CoVectorTC::operator + () const 72 | { 73 | return *this; 74 | } 75 | 76 | template 77 | inline R3CoVectorTC 78 | R3CoVectorTC::operator - () const 79 | { 80 | return R3CoVectorTC( -dx, -dy, -dz ); 81 | } 82 | 83 | 84 | 85 | // ------------------------------------- 86 | // Read/write/print functions 87 | // ------------------------------------- 88 | template 89 | inline void R3CoVectorTC::Write(ofstream &out) const 90 | { 91 | out << dx << " " << dy << " " << dz << " "; 92 | } 93 | 94 | 95 | template 96 | inline void R3CoVectorTC::WriteBinary(ofstream &out) const 97 | { 98 | out.write( (const char *) &dx, Dim() * sizeof(Coord) ); 99 | } 100 | 101 | template 102 | inline WINbool R3CoVectorTC::Read(ifstream &in) 103 | { 104 | in >> dx >> dy >> dz; 105 | 106 | return in.good() ? TRUE : FALSE; 107 | } 108 | 109 | template 110 | inline WINbool R3CoVectorTC::ReadBinary(ifstream &in) 111 | { 112 | in.read( (char *) &dx, Dim() * sizeof(Coord) ); 113 | 114 | return in.good() ? TRUE : FALSE; 115 | } 116 | 117 | template 118 | inline void R3CoVectorTC::Print( WINbool in_bDoReturn ) const 119 | { 120 | cout << dx << " " << dy << " " << dz; 121 | if ( in_bDoReturn == TRUE ) 122 | cout << "\n"; 123 | else 124 | cout << " "; 125 | } 126 | -------------------------------------------------------------------------------- /vipss/src/surfacer/utils/R3_Ellipse_i.H: -------------------------------------------------------------------------------- 1 | /* ------------------------------------------------------------------------- 2 | * DESCR : Compare two points 3 | * ------------------------------------------------------------------------- */ 4 | inline 5 | WINbool R3Ellipse::operator==(const R3Ellipse &in_Ellipse) const 6 | { 7 | if (ApproxEqual(Center(), in_Ellipse.Center()) == FALSE) return FALSE; 8 | 9 | if (!RNIsZero(in_Ellipse.m_dA - m_dA )) return FALSE; 10 | 11 | if (!RNIsZero(in_Ellipse.m_dB - m_dB )) return FALSE; 12 | 13 | if (!RNIsZero(in_Ellipse.m_dC - m_dC )) return FALSE; 14 | 15 | if (!RNIsZero(in_Ellipse.m_dZRot - m_dZRot )) return FALSE; 16 | if (!RNIsZero(in_Ellipse.m_dYRot - m_dYRot )) return FALSE; 17 | if (!RNIsZero(in_Ellipse.m_dXRot - m_dXRot )) return FALSE; 18 | 19 | return TRUE; 20 | } 21 | 22 | /* ------------------------------------------------------------------------- 23 | * DESCR : Evaluate implicit equation 24 | * ------------------------------------------------------------------------- */ 25 | inline 26 | double R3Ellipse::operator()( const R3Pt &in_pt ) const 27 | { 28 | const R4Matrix mat = ToNormal(); 29 | 30 | const R3Pt ptNormal = mat * in_pt; 31 | 32 | return (ptNormal[0] * ptNormal[0]) / (m_dA * m_dA) + 33 | (ptNormal[1] * ptNormal[1]) / (m_dB * m_dB) + 34 | (ptNormal[2] * ptNormal[2]) / (m_dC * m_dC) - 1.0; 35 | } 36 | 37 | /* ------------------------------------------------------------------------- 38 | * DESCR : Are we inside the circle (open disk)? 39 | * ------------------------------------------------------------------------- */ 40 | inline 41 | WINbool R3Ellipse::Inside(const R3Pt &in_pt) const 42 | { 43 | if ( (*this)( in_pt ) <= 0 ) return TRUE; 44 | 45 | return FALSE; 46 | } 47 | 48 | /* ------------------------------------------------------------------------- 49 | * DESCR : Are we on the circle ? 50 | * ------------------------------------------------------------------------- */ 51 | inline 52 | WINbool R3Ellipse::On(const R3Pt &in_pt) const 53 | { 54 | if (RNIsZero( (*this)(in_pt) ) ) return TRUE; 55 | 56 | return FALSE; 57 | } 58 | 59 | /* ------------------------------------------------------------------------- 60 | * DESCR : Set two points to be equal 61 | * ------------------------------------------------------------------------- */ 62 | inline 63 | R3Ellipse & 64 | R3Ellipse::operator=(const R3Ellipse &in_s) 65 | { 66 | m_ptCenter = in_s.Center(); 67 | m_dA = in_s.m_dA; 68 | m_dB = in_s.m_dB; 69 | m_dC = in_s.m_dC; 70 | m_dXRot = in_s.m_dXRot; 71 | m_dYRot = in_s.m_dYRot; 72 | m_dZRot = in_s.m_dZRot; 73 | 74 | return *this; 75 | } 76 | 77 | 78 | /* ------------------------------------------------------------------------- 79 | * DESCR : Make a Ellipse from a Ellipse 80 | * ------------------------------------------------------------------------- */ 81 | inline 82 | R3Ellipse::R3Ellipse(const R3Pt &in_ptCenter) 83 | : m_ptCenter(in_ptCenter) 84 | { 85 | m_dA = m_dB = m_dC = 1.0; 86 | m_dXRot = m_dYRot = m_dZRot = 0.0; 87 | } 88 | 89 | inline 90 | R3Ellipse::R3Ellipse() 91 | { 92 | RNZero(m_ptCenter); 93 | m_dA = m_dB = m_dC = 1.0; 94 | m_dXRot = m_dYRot = m_dZRot = 0.0; 95 | } 96 | 97 | 98 | -------------------------------------------------------------------------------- /vipss/src/surfacer/utils/Rn_Vector4_i.H: -------------------------------------------------------------------------------- 1 | // ========================================================= 2 | // 3 | // Methods for R4VectorTC template class 4 | // 5 | // ========================================================= 6 | 7 | 8 | // ------------------------------------- 9 | // constructors 10 | // ------------------------------------- 11 | 12 | template 13 | inline 14 | R4VectorTC::R4VectorTC( const Coord& _dx, const Coord& _dy, const Coord& _dz, const Coord& _dw ) 15 | { 16 | dx = _dx; dy = _dy; dz = _dz; dw = _dw; 17 | } 18 | 19 | // ------------------------------------- 20 | // assignment operators 21 | // ------------------------------------- 22 | 23 | template 24 | inline R4VectorTC& 25 | R4VectorTC::operator += ( const R4VectorTC& v) 26 | { 27 | dx += v.dx; 28 | dy += v.dy; 29 | dz += v.dz; 30 | dw += v.dw; 31 | return *this; 32 | } 33 | 34 | template 35 | inline R4VectorTC& 36 | R4VectorTC::operator -= ( const R4VectorTC& v ) 37 | { 38 | dx -= v.dx; 39 | dy -= v.dy; 40 | dz -= v.dz; 41 | dw -= v.d2; 42 | return *this; 43 | } 44 | 45 | template 46 | inline R4VectorTC& 47 | R4VectorTC::operator *= ( const Coord& s ) 48 | { 49 | dx *= s; 50 | dy *= s; 51 | dz *= s; 52 | dw *= s; 53 | return *this; 54 | } 55 | 56 | template 57 | inline R4VectorTC& 58 | R4VectorTC::operator /= ( const Coord& s ) 59 | { 60 | ASSERT( !RNIsZero( s ) ); 61 | Coord s1 = 1.0f / s; 62 | dx *= s1; 63 | dy *= s1; 64 | dz *= s1; 65 | dw *= s1; 66 | return *this; 67 | } 68 | 69 | // ------------------------------------- 70 | // unary operators 71 | // ------------------------------------- 72 | 73 | template 74 | inline R4VectorTC 75 | R4VectorTC::operator + () const 76 | { 77 | return *this; 78 | } 79 | 80 | template 81 | inline R4VectorTC 82 | R4VectorTC::operator - () const 83 | { 84 | return R4VectorTC( -dx, -dy, -dz, -dw ); 85 | } 86 | 87 | // ------------------------------------- 88 | // Self-editing functions 89 | // ------------------------------------- 90 | template 91 | inline Coord R4VectorTC::Normalize() 92 | { 93 | const Coord dLen = Length( *this ); 94 | if ( ! RNIsZero( dLen ) ) { 95 | dx = dx / dLen; 96 | dy = dy / dLen; 97 | dz = dz / dLen; 98 | dw = dw / dLen; 99 | } 100 | 101 | return dLen; 102 | } 103 | 104 | 105 | 106 | // ------------------------------------- 107 | // Read/write/print functions 108 | // ------------------------------------- 109 | template 110 | inline void R4VectorTC::Write(ofstream &out) const 111 | { 112 | out << dx << " " << dy << " " << dz << " " << dw << " "; 113 | } 114 | 115 | template 116 | inline WINbool R4VectorTC::Read(ifstream &in) 117 | { 118 | in >> dx >> dy >> dz >> dw; 119 | 120 | return in.good() ? TRUE : FALSE; 121 | } 122 | 123 | template 124 | inline void R4VectorTC::Print( const WINbool in_bDoReturn ) const 125 | { 126 | cout << dx << " " << dy << " " << dz << " " << dw; 127 | if ( in_bDoReturn == TRUE ) 128 | cout << "\n"; 129 | else 130 | cout << " "; 131 | } 132 | 133 | 134 | 135 | -------------------------------------------------------------------------------- /vipss/src/surfacer/utils/Rn_Vector2_i.H: -------------------------------------------------------------------------------- 1 | // ========================================================= 2 | // 3 | // Methods for Vector2TC template class 4 | // 5 | // ========================================================= 6 | 7 | 8 | // ------------------------------------- 9 | // constructors 10 | // ------------------------------------- 11 | 12 | template 13 | inline 14 | R2VectorTC::R2VectorTC( const Coord& _du, const Coord& _dv ) 15 | { 16 | du = _du; dv = _dv; 17 | } 18 | 19 | // ------------------------------------- 20 | // assignment operators 21 | // ------------------------------------- 22 | 23 | template 24 | inline R2VectorTC& 25 | R2VectorTC::operator += ( const R2VectorTC& v ) 26 | { 27 | du += v.du; 28 | dv += v.dv; 29 | return *this; 30 | } 31 | 32 | template 33 | inline R2VectorTC& 34 | R2VectorTC::operator -= ( const R2VectorTC& v ) 35 | { 36 | du -= v.du; 37 | dv -= v.dv; 38 | return *this; 39 | } 40 | 41 | template 42 | inline R2VectorTC& 43 | R2VectorTC::operator *= ( const Coord& s ) 44 | { 45 | du *= s; 46 | dv *= s; 47 | return *this; 48 | } 49 | 50 | template 51 | inline R2VectorTC& 52 | R2VectorTC::operator /= ( const Coord& s ) 53 | { 54 | du /= s; 55 | dv /= s; 56 | return *this; 57 | } 58 | 59 | // ------------------------------------- 60 | // unary operators 61 | // ------------------------------------- 62 | 63 | template 64 | inline R2VectorTC 65 | R2VectorTC::operator + () const 66 | { 67 | return *this; 68 | } 69 | 70 | template 71 | inline R2VectorTC 72 | R2VectorTC::operator - () const 73 | { 74 | return R2VectorTC( -du, -dv ); 75 | } 76 | 77 | 78 | // ------------------------------------- 79 | // Self-editing functions 80 | // ------------------------------------- 81 | 82 | template 83 | inline Coord R2VectorTC::Normalize() 84 | { 85 | const Coord dLen = sqrt(du * du + dv * dv); 86 | if ( ! RNIsZero( dLen ) ) { 87 | du = du / dLen; 88 | dv = dv / dLen; 89 | } 90 | return dLen; 91 | } 92 | 93 | 94 | 95 | // ------------------------------------- 96 | // Read/write/print functions 97 | // ------------------------------------- 98 | template 99 | inline void R2VectorTC::Write(ofstream &out) const 100 | { 101 | out << du << " " << dv << " "; 102 | } 103 | 104 | template 105 | inline WINbool R2VectorTC::Read(ifstream &in) 106 | { 107 | in >> du >> dv; 108 | 109 | return in.good() ? TRUE : FALSE; 110 | } 111 | 112 | template 113 | inline void R2VectorTC::WriteBinary(ofstream &out) const 114 | { 115 | out.write( (const char *) &du, Dim() * sizeof(Coord) ); 116 | } 117 | 118 | 119 | template 120 | inline WINbool R2VectorTC::ReadBinary(ifstream &in) 121 | { 122 | in.read( (char *) &du, Dim() * sizeof(Coord) ); 123 | 124 | return in.good() ? TRUE : FALSE; 125 | } 126 | 127 | 128 | template 129 | inline void R2VectorTC::Print( const WINbool in_bDoReturn ) const 130 | { 131 | cout << du << " " << dv; 132 | if ( in_bDoReturn == TRUE ) 133 | cout << "\n"; 134 | else 135 | cout << " "; 136 | } 137 | 138 | -------------------------------------------------------------------------------- /vipss/src/surfacer/utils/Mesh_Stack.H: -------------------------------------------------------------------------------- 1 | // This may look like C code, but it is really -*- C++ -*- 2 | // Copyright (c) 1992 Hugues H. Hoppe; All rights reserved. 3 | 4 | #ifndef Stack_h 5 | #define Stack_h 6 | 7 | #if 0 8 | { 9 | Stack stack; 10 | while (!stack.empty()) delete stack.pop(); 11 | ForStack(stack,Point*,p) { consider(p); } EndFor; 12 | } 13 | #endif 14 | 15 | #include 16 | 17 | 18 | class BStack { 19 | public: 20 | BStack(); 21 | ~BStack(); 22 | void clear(); 23 | void push(Univ e); 24 | Univ pop(); // ret e, else die 25 | Univ top() const; // ret e, else die 26 | int empty() const; 27 | int height() const; // slow O(n) 28 | int contains(Univ e) const; // slow O(n) 29 | int remove(Univ e); // slow O(n), ret: was_there 30 | static const BStack EMPTY; 31 | POOLALLOCATION(BStack); 32 | private: 33 | friend class BStackIter; 34 | struct Node { 35 | POOLALLOCATION(Node); 36 | Univ data; 37 | Node* next; 38 | }; 39 | Node* itop; 40 | DISABLECOPY(BStack); 41 | }; 42 | 43 | class BStackIter { 44 | public: 45 | BStackIter(const BStack& s); 46 | ~BStackIter(); 47 | operator void*() const; 48 | Univ next(); 49 | Univ operator()() const; 50 | void reinit(const BStack& s); 51 | private: 52 | const BStack::Node* n; 53 | // operator= is safe 54 | }; 55 | 56 | //---------------------------------------------------------------------------- 57 | 58 | inline BStackIter::BStackIter(const BStack& s) : n(s.itop) { } 59 | inline BStackIter::~BStackIter() { } 60 | inline Univ BStackIter::next() { Univ d=n->data; n=n->next; return d; } 61 | inline BStackIter::operator void*() const { return n?(void*)1:0; } 62 | inline Univ BStackIter::operator()() const { return n->data; } 63 | inline void BStackIter::reinit(const BStack& s) { n=s.itop; } 64 | 65 | 66 | inline BStack::BStack() : itop(0) { } 67 | inline int BStack::empty() const { return !itop; } 68 | inline Univ BStack::top() const { return itop->data; } 69 | 70 | inline void BStack::push(Univ e) 71 | { 72 | Node* n=new Node; 73 | n->data=e; 74 | n->next=itop; 75 | itop=n; 76 | } 77 | 78 | inline Univ BStack::pop() 79 | { 80 | Node* n=MESHassertv(itop); 81 | Univ e=n->data; 82 | itop=n->next; 83 | delete n; 84 | return e; 85 | } 86 | 87 | //---------------------------------------------------------------------------- 88 | 89 | template class StackIter; 90 | 91 | template 92 | class Stack : public BStack { 93 | public: 94 | inline Stack() { } 95 | inline ~Stack() { } 96 | inline void push(T e) { BStack::push(Conv::e(e)); } 97 | inline T pop() { return Conv::d(BStack::pop()); } 98 | inline T top() { return Conv::d(BStack::top()); } 99 | inline int contains(T e) const 100 | { return BStack::contains(Conv::e(e)); } 101 | inline int remove(T e) 102 | { return BStack::remove(Conv::e(e)); } 103 | // typedef StackIter Iter; 104 | }; 105 | 106 | template 107 | class StackIter : public BStackIter { 108 | public: 109 | inline StackIter(const Stack& s) : BStackIter(s) { } 110 | inline ~StackIter() { } 111 | inline T next() { return Conv::d(BStackIter::next()); } 112 | inline T operator()() const 113 | {return Conv::d(BStackIter::operator()());} 114 | inline void reinit(const Stack& s) { BStackIter::reinit(s); } 115 | }; 116 | 117 | #define ForStack(S,T,V) { for (StackIter zz(S);zz;zz.next()) { T V=zz(); 118 | 119 | #endif 120 | 121 | -------------------------------------------------------------------------------- /vipss/src/surfacer/utils/Rn_Projective.H: -------------------------------------------------------------------------------- 1 | #if _MSC_VER > 1000 2 | #pragma once 3 | #endif 4 | // _MSC_VER > 1000 5 | 6 | #ifndef __BASETYPE_PROJECTIVE_H 7 | #define __BASETYPE_PROJECTIVE_H 8 | 9 | 10 | /** \defgroup ProjectiveGeometry Homogenous 2D and 3D Points and Pluecker lines 11 | 12 | \ingroup SimpleGeometry 13 | 14 | Note: operators such as addition and Length are written as global methods, so they don't appear in the class definition but as functions in the documentation 15 | 16 | I don't know if these classes are actually used anywhere... 17 | 18 | Copyright (C) 1998 Microsoft Corporation. All Rights Reserved.
19 |
20 | File: include/utils/Rn_Projective.H, include/utils/Rn_Projective_i.H
21 |
22 | Content: 2D and 3D projective - space classes
23 | - R2HPointTC - 2D Projective point
24 | - R3HPointTC - 3D Projective point
25 | - R3HPlaneTC - 3D Projective plane
26 | - R3HLineTC - 3D Pluecker line
27 |
28 | */ 29 | //@{ 30 | //@} 31 | 32 | 33 | /** 34 | \class R2HPointTC Rn_Projective.H utils/Rn_Projective.H 35 | \ingroup ProjectiveGeometry 36 | \brief An R2 homogenous point */ 37 | template 38 | class R2HPointTC 39 | { 40 | public: 41 | /// 42 | R2HPointTC() { } 43 | /// 44 | R2HPointTC( const Coord& _u, const Coord& _v, const Coord& _w ): 45 | v(_u, _v, _w) { } 46 | /// 47 | inline R2HPointTC( const R2PointTC& p ); 48 | /// 49 | inline operator R2PointTC (); 50 | 51 | public: 52 | /// 53 | Coord u, v, w; 54 | }; 55 | 56 | 57 | /** 58 | \class R3HPointTC Rn_Projective.H utils/Rn_Projective.H 59 | \ingroup ProjectiveGeometry 60 | \brief An R3 homogenous point */ 61 | template 62 | class R3HPointTC 63 | { 64 | public: 65 | /// 66 | R3HPointTC() { } 67 | /// 68 | inline R3HPointTC( const Coord& _x, const Coord& _y, const Coord& _z, const Coord& _w ); 69 | /// 70 | inline R3HPointTC( const R3PointTC& p ); 71 | /// 72 | inline operator R3PointTC (); 73 | 74 | public: 75 | /// 76 | Coord x, y, z, w; 77 | }; 78 | 79 | 80 | /** 81 | \class R3HPlaneTC Rn_Projective.H utils/Rn_Projective.H 82 | \ingroup ProjectiveGeometry 83 | \brief An R3 homogenous plane */ 84 | template 85 | class R3HPlaneTC 86 | { 87 | public: 88 | /// 89 | R3HPlaneTC() { } 90 | /// 91 | inline R3HPlaneTC( const Coord& _x, const Coord& _y, const Coord& _z, const Coord& _w ); 92 | /// 93 | inline R3HPlaneTC( const R3PointTC& p1, 94 | const R3PointTC& p2, 95 | const R3PointTC& p3); 96 | 97 | 98 | public: 99 | /// 100 | Coord x, y, z, w; 101 | }; 102 | 103 | 104 | /** 105 | \class R3HLineTC Rn_Projective.H utils/Rn_Projective.H 106 | \ingroup ProjectiveGeometry 107 | \brief R3HLineTC: Pluecker line class */ 108 | template 109 | class R3HLineTC 110 | { 111 | public: 112 | /// 113 | R3HLineTC() { } 114 | /// 115 | inline R3HLineTC( const R3HPointTC&, const R3HPointTC& ); 116 | /// 117 | inline R3HLineTC( const R3HPlaneTC&, const R3HPlaneTC& ); 118 | 119 | 120 | public: 121 | /// 122 | Coord pl[6]; 123 | }; 124 | 125 | 126 | 127 | #include "Rn_Projective_i.H" 128 | 129 | #endif 130 | // #ifndef __BASETYPE_PROJECTIVE_H 131 | 132 | -------------------------------------------------------------------------------- /vipss/src/surfacer/utils/Rn_Unary2_i.H: -------------------------------------------------------------------------------- 1 | // ========================================================= 2 | // 3 | // Unary operators on affine2 classes 4 | // 5 | // ========================================================= 6 | 7 | /** \ingroup SimpleGeometryUnary */ 8 | //@{ 9 | 10 | 11 | /// Returns non-negative number 12 | template 13 | inline Coord 14 | Length( const R2VectorTC& v) 15 | { 16 | return (Coord) sqrt(v[0]*v[0] + v[1]*v[1]); 17 | } 18 | 19 | /// Length squared 20 | template 21 | inline Coord 22 | LengthSq( const R2VectorTC& v) 23 | { 24 | return v[0]*v[0] + v[1] * v[1]; 25 | } 26 | 27 | /// Return a unit length vector. Will fail if length zero 28 | template 29 | inline R2VectorTC 30 | Unit( const R2VectorTC& v) 31 | { 32 | return v / Length(v); 33 | } 34 | 35 | /** \brief "Safe" version of Unit 36 | 37 | @param v input vector 38 | @param out_vIfBad vector to return if v is small 39 | @returns Unit length vector 40 | Returns unit length vector, or out_vIfBad if length is small (1e-12) 41 | */ 42 | template 43 | inline R2VectorTC 44 | UnitSafe( const R2VectorTC& v, const R2VectorTC& out_vIfBad ) 45 | { 46 | Coord dLength = Length( v ); 47 | 48 | if ( fabs( dLength ) < (Coord) 1e-12 ) 49 | return out_vIfBad; 50 | 51 | return v / dLength; 52 | } 53 | 54 | /// Return unit length vector, or vector if length is small (1e-12) 55 | template 56 | inline R2VectorTC 57 | UnitSafe( const R2VectorTC& v ) 58 | { 59 | Coord dLength = Length( v ); 60 | 61 | if ( fabs( dLength ) < (Coord) 1e-12 ) 62 | return v; 63 | 64 | return v / dLength; 65 | } 66 | 67 | /// Maximum of any coordinate 68 | template 69 | inline Coord 70 | MaximumNorm( const R2VectorTC&v) 71 | { 72 | // L-infinity norm 73 | Coord max = (Coord) fabs(v[0]); 74 | if ((Coord) fabs(v[1]) > max) 75 | max = (Coord) fabs(v[1]); 76 | return max; 77 | } 78 | 79 | 80 | /// Returns non-negative number 81 | template 82 | inline Coord 83 | Length( const R2CoVectorTC& v) 84 | { 85 | return (Coord) sqrt(v[0]*v[0] + v[1]*v[1]); 86 | } 87 | 88 | /// Length Squared 89 | template 90 | inline Coord 91 | LengthSq( const R2CoVectorTC& v) 92 | { 93 | return v[0]*v[0] + v[1] * v[1]; 94 | } 95 | 96 | /// Return a unit length vector. Will fail if length zero 97 | template 98 | inline R2CoVectorTC 99 | Unit( const R2CoVectorTC& v) 100 | { 101 | return v / Length(v); 102 | } 103 | 104 | /// Maximum of any coordinate 105 | template 106 | inline Coord 107 | MaximumNorm( const R2CoVectorTC& v ) 108 | { 109 | // L-infinity norm 110 | Coord max = (Coord) fabs(v[0]); 111 | if ( (Coord) fabs(v[1]) > max) 112 | max = (Coord) fabs(v[1]); 113 | return max; 114 | } 115 | 116 | //@} 117 | 118 | /** \ingroup SimpleGeometryConversion*/ 119 | //@{ 120 | 121 | 122 | /// Safe conversion 123 | template 124 | inline R2CoVectorTC 125 | VecToCov( const R2VectorTC& v ) 126 | { 127 | return R2CoVectorTC( v[0], v[1] ); 128 | } 129 | 130 | /// Safe conversion 131 | template 132 | inline R2VectorTC 133 | CovToVec( const R2CoVectorTC& cv ) 134 | { 135 | return R2VectorTC( cv[0], cv[1] ); 136 | } 137 | 138 | //@} 139 | 140 | -------------------------------------------------------------------------------- /vipss/src/surfacer/utils/Mesh_Set.H: -------------------------------------------------------------------------------- 1 | // This may look like C code, but it is really -*- C++ -*- 2 | // Copyright (c) 1992 Hugues H. Hoppe; All rights reserved. 3 | 4 | #ifndef Set_h 5 | #define Set_h 6 | 7 | #include 8 | 9 | #include 10 | 11 | 12 | #if 0 13 | { 14 | Set sete; 15 | ForSet(set,Edge,e) { consider(e); } EndFor; 16 | } 17 | #endif 18 | 19 | class BSet { 20 | public: 21 | BSet() { } 22 | ~BSet() { } 23 | void clear(); 24 | // e may be zero 25 | void enter(Univ e); // e must be new 26 | int add(Univ e); // ret is_new 27 | int remove(Univ e); // ret was_present 28 | int contains(Univ e) const; // ret does_contain 29 | int num() const; 30 | int empty() const; 31 | Univ getone() const; // die if empty 32 | Univ removeone(); // die if empty 33 | void OK() const; 34 | static const BSet EMPTY; 35 | POOLALLOCATION(BSet); 36 | private: 37 | friend class BSetIter; 38 | BMap m; 39 | DISABLECOPY(BSet); 40 | }; 41 | 42 | class MeshRandom; 43 | 44 | class BSetIter { 45 | public: 46 | BSetIter(const BSet& s); 47 | BSetIter(const BSet& s, MeshRandom& r); 48 | ~BSetIter() { } 49 | Univ operator()() const; 50 | operator void*() const; 51 | void next(); 52 | private: 53 | BMapIter mi; 54 | DISABLECOPY(BSetIter); 55 | }; 56 | 57 | //---------------------------------------------------------------------------- 58 | 59 | inline BSetIter::BSetIter(const BSet& s) : mi(s.m) { } 60 | inline BSetIter::BSetIter(const BSet& s, MeshRandom& r) : mi(s.m,r) { } 61 | inline Univ BSetIter::operator()() const { return mi.key(); } 62 | inline BSetIter::operator void*() const { return mi; } 63 | inline void BSetIter::next() { mi.next(); } 64 | 65 | inline void BSet::clear() { m.clear(); } 66 | inline void BSet::enter(Univ e) { m.enter(e,Conv::e(1)); } 67 | inline int BSet::contains(Univ e) const { return m.contains(e); } 68 | inline int BSet::remove(Univ e) { return m.remove(e)?1:0; } 69 | 70 | inline int BSet::add(Univ e) { return m.specialadd(e,Conv::e(1)); } 71 | 72 | inline int BSet::num() const { return m.num(); } 73 | inline int BSet::empty() const { return m.empty(); } 74 | inline Univ BSet::getone() const { BSetIter si(*this); return si(); } 75 | inline Univ BSet::removeone() { Univ e=getone(); remove(e); return e; } 76 | inline void BSet::OK() const { m.OK(); } 77 | 78 | //---------------------------------------------------------------------------- 79 | 80 | template class SetIter; 81 | 82 | template 83 | class Set : public BSet { 84 | public: 85 | Set() { } 86 | ~Set() { } 87 | inline void enter(T e) { BSet::enter(Conv::e(e)); } 88 | inline int add(T e) { return BSet::add(Conv::e(e)); } 89 | inline int remove(T e) { return BSet::remove(Conv::e(e)); } 90 | inline int contains(T e) const 91 | { return BSet::contains(Conv::e(e)); } 92 | inline T getone() const { return Conv::d(BSet::getone()); } 93 | inline T removeone() { return Conv::d(BSet::removeone()); } 94 | // typedef SetIter Iter; 95 | }; 96 | 97 | template 98 | class SetIter : public BSetIter { 99 | public: 100 | inline SetIter(const Set& s) : BSetIter(s) { } 101 | inline SetIter(const Set& s, MeshRandom& r) : BSetIter(s,r) { } 102 | inline ~SetIter() { } 103 | inline T operator()() const 104 | { return Conv::d(BSetIter::operator()()); } 105 | }; 106 | 107 | #define ForSet(S,T,V) { for (SetIter zz(S);zz;zz.next()) { T V=zz(); 108 | 109 | #endif 110 | 111 | -------------------------------------------------------------------------------- /vipss/src/surfacer/utils/Rn_Projective_i.H: -------------------------------------------------------------------------------- 1 | 2 | // ========================================================= 3 | // inline function implementations 4 | // ========================================================= 5 | 6 | /** \ingroup ProjectiveGeometry 7 | \defgroup ProjectiveGeometryAlgebraic Algebraic operators 8 | 9 | Adding, subtracting, multiplying, dot products 10 | */ 11 | //@{ 12 | /// 13 | template 14 | inline Coord 15 | Dot( const R3HPointTC& p1, const R3HPlaneTC& p2 ) 16 | { 17 | return p1.x*p2.x + p1.y*p2.y + p1.z*p2.z + p1.w*p2.w; 18 | } 19 | 20 | /// 21 | template 22 | inline Coord 23 | Dot( const R3HPlaneTC& p1, const R3HPointTC& p2 ) 24 | { 25 | return p1.x*p2.x + p1.y*p2.y + p1.z*p2.z + p1.w*p2.w; 26 | } 27 | 28 | /// 29 | template 30 | inline 31 | Coord 32 | SignedDistance( const R3HLineTC& a, const R3HLineTC& b ) 33 | { 34 | return a.pl[0]*b.pl[4] + 35 | a.pl[1]*b.pl[5] + 36 | a.pl[2]*b.pl[3] + 37 | a.pl[3]*b.pl[0] + 38 | a.pl[4]*b.pl[1] + 39 | a.pl[5]*b.pl[2]; 40 | } 41 | 42 | //@} 43 | 44 | template 45 | inline 46 | R2HPointTC::R2HPointTC( const R2PointTC& p ) 47 | { 48 | u = p.u; v = p.v; w = 1.0f; 49 | } 50 | 51 | template 52 | inline 53 | R2HPointTC::operator R2PointTC ( ) 54 | { 55 | return R2PointTC( u / w, v / w ); 56 | } 57 | 58 | template 59 | inline 60 | R3HPointTC::R3HPointTC( const Coord& _x, const Coord& _y, 61 | const Coord& _z, const Coord& _w) 62 | { 63 | x = _x; y = _y; z = _z; w = _w; 64 | } 65 | 66 | template 67 | inline 68 | R3HPointTC::R3HPointTC( const R3PointTC& p ) 69 | { 70 | x = p.x; y = p.y; z = p.z; w = 1.0f; 71 | } 72 | 73 | template 74 | inline 75 | R3HPointTC::operator R3PointTC ( ) 76 | { 77 | return R3PointTC( x / w, y / w, z / w ); 78 | } 79 | 80 | 81 | template 82 | inline 83 | R3HPlaneTC::R3HPlaneTC( const Coord& _x, const Coord& _y, 84 | const Coord& _z, const Coord& _w) 85 | { 86 | x = _x; y = _y; z = _z; w = _w; 87 | } 88 | 89 | template 90 | inline 91 | R3HPlaneTC::R3HPlaneTC( const R3PointTC& p1, 92 | const R3PointTC& p2, 93 | const R3PointTC& p3) 94 | { 95 | R3VectorTC v2 = p2 - p1; 96 | R3VectorTC v3 = p3 - p1; 97 | x = v2.dy*v3.dz-v2.dz*v3.dy; 98 | y = v2.dz*v3.dx-v2.dx*v3.dz; 99 | z = v2.dx*v3.dy-v2.dy*v3.dx; 100 | w = -p1.x*x - p1.y*y - p1.z*z; 101 | } 102 | 103 | template 104 | inline 105 | R3HLineTC::R3HLineTC( const R3HPointTC& p, const R3HPointTC& q ) 106 | { 107 | pl[0] = p.x*q.y - q.x*p.y; 108 | pl[1] = p.x*q.z - q.x*p.z; 109 | pl[2] = p.x*q.w - q.x*p.w; 110 | pl[3] = p.y*q.z - q.y*p.z; 111 | pl[4] = p.z*q.w - q.z*p.w; 112 | pl[5] = q.y*q.w - p.y*p.w; 113 | } 114 | 115 | /// 116 | template 117 | inline 118 | R3HLineTC::R3HLineTC( const R3HPlaneTC& p, const R3HPlaneTC& q ) 119 | { 120 | pl[0] = p.x*q.y - q.x*p.y; 121 | pl[1] = p.x*q.z - q.x*p.z; 122 | pl[2] = p.x*q.w - q.x*p.w; 123 | pl[3] = p.y*q.z - q.y*p.z; 124 | pl[4] = p.z*q.w - q.z*p.w; 125 | pl[5] = q.y*q.w - p.y*p.w; 126 | } 127 | 128 | -------------------------------------------------------------------------------- /vipss/src/surfacer/utils/Rn_Unary3_i.H: -------------------------------------------------------------------------------- 1 | // ========================================================= 2 | // 3 | // Unary operators on affine3 classes 4 | // 5 | // ========================================================= 6 | 7 | /** \ingroup SimpleGeometryUnary */ 8 | //@{ 9 | 10 | /// Returns non-negative number 11 | template 12 | inline Coord 13 | Length( const R3VectorTC& v ) 14 | { 15 | return (Coord) sqrt( v[0]*v[0] + v[1]*v[1] + v[2]*v[2] ); 16 | } 17 | 18 | /// Length squared 19 | template 20 | inline Coord 21 | LengthSq( const R3VectorTC& v ) 22 | { 23 | return v[0]*v[0] + v[1]*v[1] + v[2]*v[2]; 24 | } 25 | 26 | /// Return a unit length vector. Will fail if length zero 27 | template 28 | inline R3VectorTC 29 | Unit( const R3VectorTC& v ) 30 | { 31 | return v / Length(v); 32 | } 33 | 34 | /** \brief "Safe" version of Unit 35 | 36 | @param v input vector 37 | @param out_vIfBad vector to return if v is small 38 | @returns Unit length vector 39 | Returns unit length vector, or out_vIfBad if length is small (1e-12) 40 | */ 41 | template 42 | inline R3VectorTC 43 | UnitSafe( const R3VectorTC& v, const R3VectorTC& out_vIfBad ) 44 | { 45 | Coord dLength = Length( v ); 46 | 47 | if ( fabs( dLength ) < (Coord) 1e-12 ) 48 | return out_vIfBad; 49 | 50 | return v / dLength; 51 | } 52 | 53 | /// Return unit length vector, or vector if length is small (1e-12) 54 | template 55 | inline R3VectorTC 56 | UnitSafe( const R3VectorTC& v ) 57 | { 58 | Coord dLength = Length( v ); 59 | 60 | if ( fabs( dLength ) < (Coord) 1e-12 ) 61 | return v; 62 | 63 | return v / dLength; 64 | } 65 | 66 | /// Maximum of any coordinate 67 | template 68 | inline Coord 69 | MaximumNorm( const R3VectorTC& v ) 70 | { 71 | // L-infinity norm 72 | Coord max = (Coord) fabs(v[0]); 73 | if ((Coord) fabs(v[1]) > max) 74 | max = (Coord) fabs(v[1]); 75 | if ((Coord) fabs(v[2]) > max) 76 | max = (Coord) fabs(v[2]); 77 | return max; 78 | } 79 | 80 | 81 | /// Returns non-negative number 82 | template 83 | inline Coord 84 | Length( const R3CoVectorTC& v ) 85 | { 86 | return (Coord) sqrt( v[0]*v[0] + v[1]*v[1] + v[2]*v[2] ); 87 | } 88 | 89 | /// Length Squared 90 | template 91 | inline Coord 92 | LengthSq( const R3CoVectorTC& v ) 93 | { 94 | return v[0]*v[0] + v[1]*v[1] + v[2]*v[2]; 95 | } 96 | 97 | /// Return a unit length vector. Will fail if length zero 98 | template 99 | inline R3CoVectorTC 100 | Unit( const R3CoVectorTC& v ) 101 | { 102 | return v / Length(v); 103 | } 104 | 105 | /// Maximum of any coordinate 106 | template 107 | inline Coord 108 | MaximumNorm( const R3CoVectorTC& v ) 109 | { 110 | // L-infinity norm 111 | Coord max = (Coord) fabs(v[0]); 112 | if ((Coord) fabs(v[1]) > max) 113 | max = (Coord) fabs(v[1]); 114 | if ((Coord) fabs(v[2]) > max) 115 | max = (Coord) fabs(v[2]); 116 | return max; 117 | } 118 | 119 | 120 | //@} 121 | 122 | /** \ingroup SimpleGeometryConversion*/ 123 | //@{ 124 | 125 | /// Safe conversion 126 | template 127 | inline R3CoVectorTC 128 | VecToCov( const R3VectorTC& v ) 129 | { 130 | return R3CoVectorTC( v[0], v[1], v[2] ); 131 | } 132 | 133 | /// Safe conversion 134 | template 135 | inline R3VectorTC 136 | CovToVec( const R3CoVectorTC& cv ) 137 | { 138 | return R3VectorTC( cv[0], cv[1], cv[2] ); 139 | } 140 | 141 | //@} 142 | -------------------------------------------------------------------------------- /vipss/src/surfacer/utils/Mesh_Queue.H: -------------------------------------------------------------------------------- 1 | // This may look like C code, but it is really -*- C++ -*- 2 | // Copyright (c) 1992 Hugues H. Hoppe; All rights reserved. 3 | 4 | #ifndef Queue_h 5 | #define Queue_h 6 | 7 | #if 0 8 | { 9 | Queue queuev; 10 | while (!queue.empty()) delete queue.dequeue(); 11 | ForStack(stack,Point*,p) { consider(p); } EndFor; 12 | } 13 | #endif 14 | 15 | #include 16 | 17 | 18 | class BQueue { 19 | public: 20 | BQueue(); 21 | ~BQueue(); 22 | void clear(); 23 | void enqueue(Univ e); // "insertlast" 24 | Univ dequeue(); // ret e, else die 25 | Univ front() const; // ret e, else die (only look) 26 | void insertfirst(Univ e); 27 | int empty() const; 28 | int length() const; // slow O(n) 29 | int contains(Univ e) const; // slow O(n) 30 | void addtoend(BQueue& q); // quick merge, clears q 31 | void addtofront(BQueue& q); // quick merge, clears q 32 | static const BQueue EMPTY; 33 | private: 34 | friend class BQueueIter; 35 | struct Node { 36 | POOLALLOCATION(Node); 37 | Univ data; 38 | Node* next; 39 | }; 40 | Node* ifront; 41 | Node* irear; 42 | DISABLECOPY(BQueue); 43 | }; 44 | 45 | class BQueueIter { 46 | public: 47 | BQueueIter(const BQueue& s); 48 | virtual ~BQueueIter(); 49 | operator void*() const; 50 | void next(); 51 | Univ operator()() const; 52 | private: 53 | const BQueue::Node* n; 54 | // operator= is safe 55 | }; 56 | 57 | //---------------------------------------------------------------------------- 58 | 59 | inline BQueueIter::BQueueIter(const BQueue& s) : n(s.ifront) { } 60 | inline BQueueIter::~BQueueIter() { } 61 | inline void BQueueIter::next() { n=n->next; } 62 | inline BQueueIter::operator void*() const { return n?(void*)1:0; } 63 | inline Univ BQueueIter::operator()() const { return n->data; } 64 | 65 | 66 | inline BQueue::BQueue() : ifront(0), irear(0) { } 67 | inline int BQueue::empty() const { return !ifront; } 68 | inline Univ BQueue::front() const { return ifront->data; } 69 | 70 | inline void BQueue::enqueue(Univ e) 71 | { 72 | Node* n=new Node; 73 | n->data=e; 74 | n->next=0; 75 | if (irear) irear->next=n; 76 | else ifront=n; 77 | irear=n; 78 | } 79 | 80 | inline void BQueue::insertfirst(Univ e) 81 | { 82 | Node* n=new Node; 83 | n->data=e; 84 | n->next=ifront; 85 | ifront=n; 86 | if (!irear) irear=n; 87 | } 88 | 89 | inline Univ BQueue::dequeue() 90 | { 91 | Node* n=MESHassertv(ifront); 92 | Univ e=n->data; 93 | ifront=n->next; 94 | delete n; 95 | if (!ifront) irear=0; 96 | return e; 97 | } 98 | 99 | //---------------------------------------------------------------------------- 100 | 101 | template class QueueIter; 102 | 103 | template 104 | class Queue : public BQueue { 105 | public: 106 | Queue() { } 107 | ~Queue() { } 108 | inline void enqueue(T e) { BQueue::enqueue(Conv::e(e)); } 109 | inline T dequeue() { return Conv::d(BQueue::dequeue()); } 110 | inline T front() const { return Conv::d(BQueue::front()); } 111 | inline void insertfirst(T e) { BQueue::insertfirst(Conv::e(e)); } 112 | inline int contains(T e) const 113 | { return BQueue::contains(Conv::e(e)); } 114 | inline void addtoend(Queue& q) { BQueue::addtoend(q); } 115 | inline void addtofront(Queue& q) { BQueue::addtofront(q); } 116 | // typedef QueueIter Iter; 117 | }; 118 | 119 | template 120 | class QueueIter : public BQueueIter { 121 | public: 122 | inline QueueIter(const Queue& q) : BQueueIter(q) { } 123 | inline ~QueueIter() { } 124 | inline T operator()() const 125 | {return Conv::d(BQueueIter::operator()());} 126 | }; 127 | 128 | #define ForQueue(S,T,V) { for (QueueIter zz(S);zz;zz.next()) { T V=zz(); 129 | 130 | #endif 131 | 132 | -------------------------------------------------------------------------------- /vipss/src/Solver.h: -------------------------------------------------------------------------------- 1 | #ifndef SOLVER_H 2 | #define SOLVER_H 3 | 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | 11 | using namespace std; 12 | 13 | enum ConstraintMethod{ 14 | CM_EQUAL, 15 | CM_LESS, 16 | CM_GREATER, 17 | CM_RANGE 18 | }; 19 | 20 | 21 | struct triple{ 22 | int i; 23 | int j; 24 | double val; 25 | triple(int i,int j,double val):i(i),j(j),val(val){} 26 | }; 27 | 28 | struct LinearVec{ 29 | 30 | vectorts; 31 | vectorws; 32 | double a; 33 | double b; 34 | int label; 35 | ConstraintMethod mt; 36 | 37 | 38 | LinearVec(){} 39 | LinearVec(int label):label(label){} 40 | void clear(); 41 | void push_back(int t, double w); 42 | void set_label(int label); 43 | void set_ab(double a, double b); 44 | }; 45 | 46 | struct QuadraticVec{ 47 | 48 | vectorts; 49 | double b; 50 | ConstraintMethod mt; 51 | 52 | QuadraticVec(){} 53 | QuadraticVec(vector&ts, double b):ts(ts),b(b){} 54 | 55 | void push_back(int i,int j,double val); 56 | void set_b(double b); 57 | void clear(); 58 | }; 59 | 60 | struct NLOptConstraint{ 61 | nlopt::vfunc constraintfunc; 62 | ConstraintMethod mt; 63 | void *data; 64 | 65 | }; 66 | 67 | 68 | struct Solution_Struct{ 69 | int Statue; 70 | double init_energy; 71 | double energy; 72 | double time; 73 | vectorsolveval; 74 | arma::vec solvec_arma; 75 | 76 | Solution_Struct():init_energy(-1),energy(-1){} 77 | void init(int n); 78 | }; 79 | 80 | class Solver{ 81 | 82 | 83 | public: 84 | 85 | // GRBEnv objenv; 86 | // GRBModel objmodel; 87 | 88 | // vectorc_vars; 89 | 90 | public: 91 | // Solver():objenv(GRBEnv()),objmodel(GRBModel(objenv)){ 92 | 93 | // objmodel.getEnv().set(GRB_IntParam_OutputFlag, 0); 94 | 95 | // } 96 | 97 | Solver(){} 98 | 99 | 100 | public: 101 | 102 | 103 | // static int solveQuadraticProgramming(vector &M, vector &Ab,int n, vector&solveval); 104 | 105 | // static int solveQuadraticProgramming(vector &M, vector &Ab,int n, vector&solveval); 106 | // static int solveQuadraticProgramming(arma::mat &M, vector &Ab,int n, Solution_Struct &sol); 107 | 108 | 109 | // static int solveLinearLS(vector &M, vector &b, int n, vector&solveval); 110 | 111 | // static int solveQCQP(arma::mat &M, vector &Ab, vector &Cb, int n, Solution_Struct &sol); 112 | 113 | //int solveQP_multiupdata_main(Solution_Struct &sol, vector &Ab, int n, bool suppressinfo = true); 114 | //int solveQP_multiupdata_init(arma::mat &M, int n); 115 | 116 | 117 | 118 | static int nloptwrapper(vector&lowerbound, 119 | vector&upperbound, 120 | nlopt::vfunc optfunc, 121 | void *funcPara, 122 | vector&nl_constraints, 123 | double tor, 124 | int maxIter, 125 | Solution_Struct &sol 126 | ); 127 | 128 | static int nloptwrapper(vector&lowerbound, 129 | vector&upperbound, 130 | nlopt::vfunc optfunc, 131 | void *funcPara, 132 | double tor, 133 | int maxIter, 134 | Solution_Struct &sol 135 | ); 136 | 137 | }; 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | #endif // SOLVER_H 159 | -------------------------------------------------------------------------------- /ReadMe.md: -------------------------------------------------------------------------------- 1 | VIPSS - Zhiyang Huang (2019) 2 | 3 | ------------------------------------ 4 | 5 | This code implements the algorithm described in 6 | 7 | **Variational Implicit Point Set Surface** 8 | Zhiyang Huang, Nathan Carr, Tao Ju. 9 | *ACM Transactions on Graphics (Proc. ACM Siggraph 2019)* 10 | 11 | The primary function of this program is to predict the normal as well as the underlying surface of a given set of unoriented points. 12 | 13 | Currently, the code is only tested on Mac OS X 10.13 or above, it should work at other platforms with minor modification. 14 | 15 | 16 | BUILDING 17 | ====================================================================================================== 18 | 19 | 20 | The code has only two dependencies: 1)Armadillo, 2)NLOPT 21 | 22 | 1) http://arma.sourceforge.net/ 23 | 24 | 2) https://nlopt.readthedocs.io/en/latest/ 25 | 26 | You can download & install them by yourself, or run the env.sh script which will install homebrew first, and then install the two dependencies via homebrew. 27 | 28 | $source env.sh 29 | 30 | Then go to the vipss folder, build the Cmake file and make: 31 | $cd vipss 32 | $cmake . 33 | $make 34 | 35 | In the vipss directory, there should be an executable called "vipss" (or "vipss.exe" on Windows if it is successfully built). 36 | 37 | 38 | RUNNING 39 | ====================================================================================================== 40 | 41 | To run the code from the command line, type: 42 | 43 | $./vipss -i input_file_name [-l user_lambda] [-s number_voxel_per_line] [-o output_file_path] 44 | 45 | where: 46 | 1. -i: followed by the path of the input file. input_file_name is a path to the input file. currently, support file format includes ".xyz". The format of .xyz is: 47 | x1, y1, z1 48 | x2, y2, z2 49 | ..... 50 | xn, yn, zn 51 | 52 | 2. -l: optional argument. Followed by a float number indicating the lambda which balances the energy (see the paper for details). Default 0 (exact interpolation), you should set and tune this number according to your inputs. 53 | 54 | 3. -s: optional argument. Followed by a unsigned integer number indicating the number of voxels in each dimension for the implicit surfacing. Only If -s is included in the command line, the program would output the surface ([input file name]_surface.ply). We recomment using 100 for a default value, and you should set this according to your inputs and the precision of the output. Notices that the surfacing algorithm takes quite a long time for surfacing the zero-level set, and it depends on the resolution and the shape of the zero-level set. 55 | 56 | 4. -o: optional argument. Followed by the path of the output path. output_file_path is a path to the folder for generating output files. Default the folder of the input file. 57 | 58 | 5. -t: optional argument. when it is activated, the program will create a txt file ([input file name]_time.txt) which records the timing information in this run. 59 | 60 | Some examples have been placed at data folder for testing: 61 | 1. $./vipss -i ../data/hand_ok/input.xyz -l 0 -s 200 62 | 2. $./vipss -i ../data/walrus/input.xyz -l 0.003 -s 100 63 | 64 | The program will generate the predicted normal in [input file name]_normal.ply. 65 | If -s is included in the command line, the program will generate the surface as the zero-level set of the solved implicit function ([input file name]_surface.ply). 66 | 67 | :bell: To generate all the example in the paper, please run the makefigure.sh script in the vipss folder: 68 | $source makefigure.sh 69 | The result will be generated into the data folder respectively. 70 | 71 | :bell: Notice: The current surface tracker does NOT producing multi-component surface. We refer the user to use CGAL implicit mesher if needed. We will update the program to it soon. 72 | 73 | :mega: For further questions about the code and the paper, please contact Zhiyang Huang at adshhzy@gmail.com or zhiyang.huang@wustl.edu (might be invalid after he graduated). You can also contact Prof. Tao Ju at taoju@wustl.edu. 74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /vipss/src/surfacer/utils/Rn_Unary4_i.H: -------------------------------------------------------------------------------- 1 | // ========================================================= 2 | // 3 | // Unary operators on affine4 classes 4 | // 5 | // ========================================================= 6 | 7 | /** \ingroup SimpleGeometryUnary */ 8 | //@{ 9 | 10 | /// Returns non-negative number 11 | template 12 | inline Coord 13 | Length( const R4VectorTC& v ) 14 | { 15 | return (Coord) sqrt( v[0]*v[0] + v[1]*v[1] + v[2]*v[2] + v[3] * v[3] ); 16 | } 17 | 18 | /// Length squared 19 | template 20 | inline Coord 21 | LengthSq( const R4VectorTC& v ) 22 | { 23 | return v[0]*v[0] + v[1]*v[1] + v[2]*v[2] + v[3] * v[3]; 24 | } 25 | 26 | /// Return a unit length vector. Will fail if length zero 27 | template 28 | inline R4VectorTC 29 | Unit( const R4VectorTC& v ) 30 | { 31 | return v / Length(v); 32 | } 33 | 34 | 35 | /** \brief "Safe" version of Unit 36 | 37 | @param v input vector 38 | @param out_vIfBad vector to return if v is small 39 | @returns Unit length vector 40 | Returns unit length vector, or out_vIfBad if length is small (1e-12) 41 | */ 42 | template 43 | inline R4VectorTC 44 | UnitSafe( const R4VectorTC& v, const R4VectorTC& out_vIfBad ) 45 | { 46 | Coord dLength = Length( v ); 47 | 48 | if ( fabs( dLength ) < (Coord) 1e-12 ) 49 | return out_vIfBad; 50 | 51 | return v / dLength; 52 | } 53 | 54 | /// Return unit length vector, or vector if length is small (1e-12) 55 | template 56 | inline R4VectorTC 57 | UnitSafe( const R4VectorTC& v ) 58 | { 59 | Coord dLength = Length( v ); 60 | 61 | if ( fabs( dLength ) < (Coord) 1e-12 ) 62 | return v; 63 | 64 | return v / dLength; 65 | } 66 | 67 | /// Maximum of any coordinate 68 | template 69 | inline Coord 70 | MaximumNorm( const R4VectorTC& v ) 71 | { 72 | // L-infinity norm 73 | Coord max = (Coord) fabs(v[0]); 74 | if ((Coord) fabs(v[1]) > max) 75 | max = (Coord) fabs(v[1]); 76 | if ((Coord) fabs(v[2]) > max) 77 | max = (Coord) fabs(v[2]); 78 | if ((Coord) fabs(v[3]) > max) 79 | max = (Coord) fabs(v[3]); 80 | return max; 81 | } 82 | 83 | // ------------------------------------- 84 | // friend functions 85 | // ------------------------------------- 86 | 87 | /// Returns non-negative number 88 | template 89 | tinline Coord 90 | Length( const R4CoVectorTC& v ) 91 | { 92 | return (Coord) sqrt( v[0]*v[0] + v[1]*v[1] + v[2]*v[2] + v[3]*v[3] ); 93 | } 94 | 95 | /// Length Squared 96 | template 97 | inline Coord 98 | LengthSq( const R4CoVectorTC& v ) 99 | { 100 | return v[0]*v[0] + v[1]*v[1] + v[2]*v[2] + v[3]*v[3]; 101 | } 102 | 103 | /// Return a unit length vector. Will fail if length zero 104 | template 105 | inline R4CoVectorTC 106 | Unit( const R4CoVectorTC& v ) 107 | { 108 | return v / Length(v); 109 | } 110 | 111 | /// Maximum of any coordinate 112 | template 113 | inline Coord 114 | MaximumNorm( const R4CoVectorTC& v ) 115 | { 116 | // L-infinity norm 117 | Coord max = (Coord) fabs(v[0]); 118 | if ((Coord) fabs(v[1]) > max) 119 | max = (Coord) fabs(v[1]); 120 | if ((Coord) fabs(v[2]) > max) 121 | max = (Coord) fabs(v[2]); 122 | if ((Coord) fabs(v[3]) > max) 123 | max = (Coord) fabs(v[3]); 124 | return max; 125 | } 126 | //@} 127 | 128 | /** \ingroup SimpleGeometryConversion*/ 129 | //@{ 130 | 131 | /// Safe conversion 132 | template 133 | inline R4CoVectorTC 134 | VecToCov( const R4VectorTC& v ) 135 | { 136 | return R4CoVectorTC( v[0], v[1], v[2], v[3] ); 137 | } 138 | 139 | /// Safe conversion 140 | template 141 | inline R4VectorTC 142 | CovToVec( const R4CoVectorTC& cv ) 143 | { 144 | return R4VectorTC( cv[0], cv[1], cv[2], cv[3] ); 145 | } 146 | 147 | 148 | //@} 149 | 150 | -------------------------------------------------------------------------------- /vipss/src/readers.h: -------------------------------------------------------------------------------- 1 | #ifndef READERS_H 2 | #define READERS_H 3 | 4 | 5 | #include 6 | #include 7 | using namespace std; 8 | 9 | bool readOffFile(string filename,vector&vertices,vector&faces2vertices); 10 | 11 | 12 | bool writeOffFile(string filename,const vector&vertices,const vector&faces2vertices); 13 | 14 | bool writePLYFile(string filename, const vector&vertices, const vector&faces2vertices, 15 | const vector &vertices_normal, const vector&vertices_color); 16 | 17 | bool writePLYFile_VF(string filename,const vector&vertices,const vector&faces2vertices); 18 | bool writePLYFile_VN(string filename,const vector&vertices, const vector&vertices_normal); 19 | 20 | bool readPLYFile(string filename, vector&vertices, vector &vertices_normal); 21 | 22 | bool readObjFile(string filename, vector&vertices, vector&faces2vertices, vector &vertices_normal); 23 | bool readObjFile_Line(string filename,vector&vertices,vector&edges2vertices); 24 | 25 | bool writeObjFile(string filename,const vector&vertices,const vector&faces2vertices); 26 | bool writeObjFile_line(string filename,const vector&vertices,const vector&edge2vertices); 27 | bool writeObjFile_vn(string filename,const vector&vertices,const vector&vn); 28 | 29 | 30 | bool readSurfFile(string filename,vector&vertices,vector&faces2vertices,vector&vertices_field); 31 | 32 | bool writeSurfFile(string filename,const vector&vertices,const vector&faces2vertices,const vector&vertices_field); 33 | 34 | 35 | bool readCurfFile(string filename, vector&vertices, vector&edges2vertices, vector&vertices_field, vector &vertices_tangent); 36 | 37 | 38 | bool writeCurfFile(string filename, const vector&vertices, const vector&edges2vertices, vector&vertices_field , vector &vertices_tangent); 39 | 40 | 41 | bool readVolfFile(string filename, vector&vertices, vector&tets2vertices, vector &vertices_normal, vector &vertices_field); 42 | 43 | 44 | bool writeVolfFile(string filename, const vector&vertices, const vector&tets2vertices, vector &vertices_normal, vector &vertices_field); 45 | 46 | bool readContourEdgeTxtFile(string filename, vector&edges2vertices); 47 | bool writeContourEdgeTxtFile(string filename, const vector&edges2vertices); 48 | 49 | 50 | 51 | bool writeVecFile(string filename, const vector&vec); 52 | bool readVecFile(string filename,vector&vec); 53 | 54 | 55 | 56 | bool readVVecFile(string filename, vector> &vvec); 57 | bool writeVVecFile(string filename, const vector> &vvec); 58 | 59 | bool writeVecFile(string filename, const vector&vec); 60 | bool readVecFile(string filename,vector&vec); 61 | 62 | 63 | bool readVecFile(string filename,vector&vec); 64 | 65 | bool readVVecFile(string filename, vector> &vvec); 66 | bool writeVVecFile(string filename, const vector> &vvec); 67 | 68 | bool writeSufFile(string filename, const vector&vertices, const vector&faces2vertices, const vector&facesMat, const vector &CtrEdges); 69 | bool writeCtrGraphFile(string filename, const vector &vertices, const vector>&edge2vertices, const vector>&edgeMat, const vector>&planepara); 70 | 71 | bool writeCurNetFile(string filename, const vector &vertices, const vector>&edge2vertices, const vector>&edgeMat, const vector>&planepara, const vector&verticesNor); 72 | 73 | bool readXYZ(string filename, vector&v); 74 | bool readXYZnormal(string filename, vector&v, vector&vn); 75 | bool writeXYZ(string filename, vector&v); 76 | bool writeXYZnormal(string filename, vector&v, vector&vn); 77 | 78 | #endif // READERS_H 79 | -------------------------------------------------------------------------------- /vipss/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "src/rbfcore.h" 4 | #include "src/readers.h" 5 | using namespace std; 6 | 7 | 8 | 9 | void SplitPath(const std::string& fullfilename,std::string &filepath); 10 | void SplitFileName (const std::string& fullfilename,std::string &filepath,std::string &filename,std::string &extname); 11 | RBF_Paras Set_RBF_PARA(); 12 | int main(int argc, char** argv) 13 | { 14 | cout << argc << endl; 15 | 16 | 17 | 18 | string infilename; 19 | string outpath, pcname, ext, inpath; 20 | 21 | int n_voxel_line = 100; 22 | 23 | double user_lambda = 0; 24 | 25 | bool is_surfacing = false; 26 | bool is_outputtime = false; 27 | 28 | int c; 29 | optind=1; 30 | while ((c = getopt(argc, argv, "i:o:l:s:t")) != -1) { 31 | switch (c) { 32 | case 'i': 33 | infilename = optarg; 34 | break; 35 | case 'o': 36 | outpath = string(optarg); 37 | break; 38 | case 'l': 39 | user_lambda = atof(optarg); 40 | break; 41 | case 's': 42 | is_surfacing = true; 43 | n_voxel_line = atoi(optarg); 44 | break; 45 | case 't': 46 | is_outputtime = true; 47 | break; 48 | case '?': 49 | cout << "Bad argument setting!" << endl; 50 | break; 51 | } 52 | } 53 | 54 | if(outpath.empty())SplitFileName(infilename,outpath,pcname,ext); 55 | else SplitFileName(infilename,inpath,pcname,ext); 56 | cout<<"input file: "<Vs; 66 | RBF_Core rbf_core; 67 | RBF_Paras para = Set_RBF_PARA(); 68 | para.user_lamnbda = user_lambda; 69 | 70 | readXYZ(infilename,Vs); 71 | rbf_core.InjectData(Vs,para); 72 | rbf_core.BuildK(para); 73 | rbf_core.InitNormal(para); 74 | rbf_core.OptNormal(0); 75 | 76 | rbf_core.Write_Hermite_NormalPrediction(outpath+pcname+"_normal", 1); 77 | 78 | if(is_surfacing){ 79 | rbf_core.Surfacing(0,n_voxel_line); 80 | rbf_core.Write_Surface(outpath+pcname+"_surface"); 81 | } 82 | 83 | if(is_outputtime){ 84 | rbf_core.Print_TimerRecord_Single(outpath+pcname+"_time.txt"); 85 | } 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | return 0; 95 | } 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | RBF_Paras Set_RBF_PARA(){ 104 | 105 | RBF_Paras para; 106 | RBF_InitMethod initmethod = Lamnbda_Search; 107 | 108 | RBF_Kernal Kernal = XCube; 109 | int polyDeg = 1; 110 | double sigma = 0.9; 111 | double rangevalue = 0.001; 112 | 113 | para.Kernal = Kernal;para.polyDeg = polyDeg;para.sigma = sigma;para.rangevalue = rangevalue; 114 | para.Hermite_weight_smoothness = 0.0; 115 | para.Hermite_ls_weight = 0; 116 | para.Hermite_designcurve_weight = 00.0; 117 | para.Method = RBF_METHOD::Hermite_UnitNormal; 118 | 119 | 120 | para.InitMethod = initmethod; 121 | 122 | para.user_lamnbda = 0; 123 | 124 | para.isusesparse = false; 125 | 126 | 127 | return para; 128 | } 129 | 130 | 131 | inline void SplitFileName (const std::string& fullfilename,std::string &filepath,std::string &filename,std::string &extname) { 132 | int pos; 133 | pos = fullfilename.find_last_of('.'); 134 | filepath = fullfilename.substr(0,pos); 135 | extname = fullfilename.substr(pos); 136 | pos = filepath.find_last_of("\\/"); 137 | filename = filepath.substr(pos+1); 138 | pos = fullfilename.find_last_of("\\/"); 139 | filepath = fullfilename.substr(0,pos+1); 140 | //cout< inline 13 | geom GEOMMin( const Array &in_a ) 14 | { 15 | geom g; 16 | 17 | for (int iD = 0; iD < g.Dim(); iD++ ) 18 | g[iD] = 1e30; 19 | 20 | for ( int i = 0; i < in_a.num(); i++ ) { 21 | for (int iD = 0; iD < g.Dim(); iD++ ) 22 | g[iD] = WINmin( g[iD], in_a[i][iD] ); 23 | } 24 | 25 | return g; 26 | } 27 | 28 | /// Find the max of each of the elemnets of the array. Assumes WINmin can sort the elements of geom. 29 | template inline 30 | geom GEOMMax( const Array &in_a ) 31 | { 32 | geom g; 33 | 34 | for (int iD = 0; iD < g.Dim(); iD++ ) 35 | g[iD] = -1e30; 36 | 37 | for ( int i = 0; i < in_a.num(); i++ ) { 38 | for (int iD = 0; iD < g.Dim(); iD++ ) 39 | g[iD] = WINmax( g[iD], in_a[i][iD] ); 40 | } 41 | 42 | return g; 43 | } 44 | 45 | /// Find the average of the elemnets of the array. 46 | template inline 47 | geom GEOMAvg( const Array &in_a ) 48 | { 49 | geom g; 50 | 51 | for (int iD = 0; iD < g.Dim(); iD++ ) 52 | g[iD] = 0.0; 53 | 54 | for ( int i = 0; i < in_a.num(); i++ ) { 55 | for (int iD = 0; iD < g.Dim(); iD++ ) 56 | g[iD] += in_a[i][iD]; 57 | } 58 | 59 | if ( in_a.num() == 0 ) 60 | return g; 61 | 62 | const double dDiv = 1.0 / (double) in_a.num(); 63 | for (int iD = 0; iD < g.Dim(); iD++ ) 64 | g[iD] *= dDiv; 65 | 66 | return g; 67 | } 68 | 69 | 70 | /// Find the average and the standard deviation of the array elements 71 | template inline 72 | geom GEOMAvgSD( const Array &in_a, geom &out_geomSD ) 73 | { 74 | const geom geomAvg = GEOMAvg( in_a ); 75 | 76 | for (int iD = 0; iD < out_geomSD.Dim(); iD++ ) 77 | out_geomSD[iD] = 0.0; 78 | 79 | for ( FORINT i = 0; i < in_a.num(); i++ ) { 80 | for (int iD = 0; iD < out_geomSD.Dim(); iD++ ) 81 | out_geomSD[iD] += ( in_a[i][iD] - geomAvg[iD] ) * ( in_a[i][iD] - geomAvg[iD] ); 82 | } 83 | 84 | if ( in_a.num() < 2 ) 85 | return geomAvg; 86 | 87 | const double dDiv = 1.0 / (double) ( in_a.num() - 1.0 ); 88 | for (int iD = 0; iD < out_geomSD.Dim(); iD++ ) 89 | out_geomSD[iD] *= dDiv; 90 | 91 | return geomAvg; 92 | } 93 | 94 | 95 | /// Find the average, min, max and the standard deviation of the array elements 96 | template inline 97 | void GEOMAvgSDMinMax( const Array &in_a, 98 | geom & out_geomAvg, 99 | geom & out_geomSD, 100 | geom & out_geomMin, 101 | geom & out_geomMax ) 102 | { 103 | const geom geomAvg = GEOMAvg( in_a ); 104 | 105 | for (int iD = 0; iD < out_geomMin.Dim(); iD++ ) { 106 | out_geomMin[iD] = 1e30; 107 | out_geomMax[iD] = -1e30; 108 | out_geomSD[iD] = 0.0; 109 | } 110 | 111 | for ( FORINT i = 0; i < in_a.num(); i++ ) { 112 | for (int iD = 0; iD < out_geomSD.Dim(); iD++ ) { 113 | out_geomSD[iD] += ( in_a[i][iD] - geomAvg[iD] ) * ( in_a[i][iD] - geomAvg[iD] ); 114 | out_geomMin[iD] = WINmin( out_geomMin[iD], in_a[i][iD] ); 115 | out_geomMax[iD] = WINmax( out_geomMax[iD], in_a[i][iD] ); 116 | } 117 | } 118 | 119 | if ( in_a.num() < 2 ) 120 | return geomAvg; 121 | 122 | const double dDiv = 1.0 / (double) ( in_a.num() - 1.0 ); 123 | for (int iD = 0; iD < out_geomSD.Dim(); iD++ ) 124 | out_geomSD[iD] *= dDiv; 125 | 126 | return geomAvg; 127 | } 128 | 129 | //@} 130 | #endif 131 | 132 | -------------------------------------------------------------------------------- /vipss/src/surfacer/utils/Rn_BBox.H: -------------------------------------------------------------------------------- 1 | #ifndef _RN_DEFS_BBOX_H 2 | #define _RN_DEFS_BBOX_H 3 | 4 | #include 5 | #include 6 | 7 | 8 | /** \class RNBBoxTC RN_BBox.H utils/RN_BBox.H 9 | \ingroup LinearGeometry 10 | \brief An ND bouinding box. 11 | 12 | Defined by center, extent.
13 | Files:
14 | - include/utils/Rn_BBox.H
15 | - include/utils/Rn_BBox_i.H
16 | - src/utils/geometry/Rn_BBox.cpp
17 | */ 18 | template 19 | class RNBBoxTC { 20 | protected: 21 | /// Center of bounding box 22 | Point m_ptCenter; 23 | /// Size/width of box in each direction 24 | SArray m_adExtent; 25 | /// Matrix to take unit cube, centered at origin, to bbox 26 | Matrix m_mat, m_matInv; 27 | 28 | /// Location of corners in space (derived) 29 | SArray m_aptCorners; 30 | 31 | public: 32 | /**@name Access to data */ 33 | //@{ 34 | /** Dimension.(Depends on template type) */ 35 | inline int Dim() const ; 36 | /// 1D: two corners, 2D: four corners, etc. 37 | inline int NCorners() const { return m_aptCorners.num(); } 38 | /// Get corner 39 | inline const Point & Corner ( const int in_i ) const ; 40 | /// Get Center of bounding box 41 | inline const Point & Center ( ) const ; 42 | /// Get width/height etc. (x,y,z...) 43 | inline double Extent ( const int in_i ) const ; 44 | /// Matrix that transforms cube at origin to bounding box 45 | inline Matrix Transform() const { return m_mat; } 46 | /// Matrix that transforms bbox to cube at origin 47 | inline Matrix InvTransform() const { return m_matInv; } 48 | /// Extents in all dimensions 49 | inline Point Scale() const; 50 | //@} 51 | 52 | /**@name Changing data */ 53 | //@{ 54 | /// Move the bounding box 55 | inline void ApplyTransform( const Matrix & ); 56 | /// width/height of box 57 | inline void SetExtents( const Point & in_ptExtents ); 58 | /// Reset the matrix to the identity 59 | inline void ResetMatrix( ); 60 | //@} 61 | 62 | /**@name Inside/outside/closest routines */ 63 | //@{ 64 | /// Is it on or inside the boundary? 65 | inline WINbool Inside( const Point & ) const; 66 | /// Is it within epsilon of the boundary? 67 | inline WINbool IsBoundary( const Point & ) const; 68 | /// Project onto cube 69 | inline Point Project( const Point & ) const; 70 | /// Intersect ray with cube 71 | inline WINbool IntersectRay( const Point &, const Vector &, Array &out_apt ) const; 72 | //@} 73 | 74 | /**@name Comparisons with other bboxes */ 75 | //@{ 76 | /// Does an approximate (RNEpsilon_d) comparison 77 | inline WINbool operator==( const RNBBoxTC & ) const; 78 | //@} 79 | 80 | 81 | /**@name Construction and assignment routines */ 82 | //@{ 83 | /// 84 | inline RNBBoxTC &operator=(const RNBBoxTC &p); 85 | /// 86 | inline RNBBoxTC( const RNBBoxTC &in_bbox ) ; 87 | /// Default constructor is unit square/cube 88 | inline RNBBoxTC( ); 89 | /// 90 | inline RNBBoxTC( const Point &in_ptCenter, const Point &in_ptScl ); 91 | //@} 92 | 93 | /// 94 | virtual inline ~RNBBoxTC() {} 95 | 96 | /**@name Read, write, print */ 97 | //@{ 98 | /// Debugging print. 99 | inline void Print() const ; 100 | /// Writes points to file. 101 | inline void Write ( ofstream &out ) const ; 102 | /// Reads points from file. 103 | inline WINbool Read ( ifstream &in ); 104 | //@} 105 | 106 | /// Check closest point and intersection routines 107 | static WINbool Test(); 108 | }; 109 | 110 | 111 | #include "Rn_BBox_i.H" 112 | 113 | 114 | /** \addtogroup LinearGeometry */ 115 | //@{ 116 | /// 1D bbox (line) 117 | typedef RNBBoxTC R1BBox; 118 | /// 2D bbox (square) 119 | typedef RNBBoxTC R2BBox; 120 | /// 3D bbox (cube) 121 | typedef RNBBoxTC R3BBox; 122 | //@} 123 | #endif 124 | 125 | -------------------------------------------------------------------------------- /vipss/src/surfacer/utils/Rn_Polynomial.H: -------------------------------------------------------------------------------- 1 | #ifndef _RN_DEFS_POLYNOMIAL_H 2 | #define _RN_DEFS_POLYNOMIAL_H 3 | 4 | #include 5 | #include 6 | 7 | /** \class RNPolynomial Rn_Polynomial.H utils/Rn_Polynomial.H 8 | \ingroup Polynomials 9 | \brief A polynomial in one or two variables. 10 | 11 | Defined by the dimension (number of variables) and the coefficients (degree + 1).
12 | Files:
13 | - include/utils/Rn_Polynomial.H
14 | - include/utils/R2_Polynomial_i.H
15 | - src/utils/geometry/RNPolynomial.cpp
16 | */ 17 | class RNPolynomial : private Array { 18 | private: 19 | /// number or variables (x,y, etc) 20 | int m_iDim; 21 | /// Degree of polynomial 22 | int m_iDegree; 23 | 24 | void Compress(); // remove excess degrees 25 | 26 | public: 27 | /**@name Access to data */ 28 | //@{ 29 | /// Number of variables. 30 | inline int Dim() const { return m_iDim; } 31 | /// Degree of polynomial +1 raised to dimension. 32 | inline int Num_coefs() const { return num(); } 33 | /// Highest power of polynomial 34 | inline int Degree() const { return m_iDegree; } 35 | /// Assumes polynomial in one variable 36 | inline double operator[](int i) const ; 37 | /// Assumes polynomial in one variable 38 | inline double &operator[](int i) ; 39 | 40 | /// Assumes polynomial in one variable 41 | inline double Coef(int which) const; 42 | /// Assumes polynomial in one variable 43 | inline double &Coef(int which) ; 44 | /// Assumes polynomial in two variables 45 | inline double Coef(int which_s, int which_t) const; 46 | /// Assumes polynomial in two variables 47 | inline double &Coef(int which_s, int which_t) ; 48 | //@} 49 | 50 | /**@name Evaluations on polynomial */ 51 | //@{ 52 | /// Evaluate one variable polynomial 53 | double operator()(double in_t) const; 54 | /// Evaluate two variable polynomial 55 | double operator()(double in_s, double in_t) const; 56 | //@} 57 | 58 | /**@name Operations on polynomials 59 | Polynomials must have same dimension */ 60 | //@{ 61 | /// 62 | RNPolynomial operator+(const RNPolynomial &) const ; 63 | /// 64 | RNPolynomial operator-(const RNPolynomial &) const ; 65 | /// 66 | RNPolynomial operator-() const ; 67 | /// 68 | RNPolynomial operator*(const RNPolynomial &) const ; 69 | /// 70 | RNPolynomial Divide(const RNPolynomial &, RNPolynomial &out_polyRemainder ) const ; 71 | /// 72 | RNPolynomial Integrate( double in_dConstant ) const ; 73 | /// Integrate from t0 to t1 74 | double Integrate( double t0, double t1 ) const ; 75 | /// 76 | RNPolynomial Differentiate() const ; 77 | /// Composition 78 | RNPolynomial operator() ( const RNPolynomial & ) const ; 79 | /// 80 | RNPolynomial operator* ( double in_dScale ) const ; 81 | //@} 82 | 83 | /**@name Comparison routine */ 84 | //@{ 85 | /// 86 | WINbool operator==(const RNPolynomial & ) const ; 87 | //@} 88 | 89 | /**@name Constructors and assignments */ 90 | //@{ 91 | /// 92 | RNPolynomial &operator=( const RNPolynomial & ) ; 93 | /// 94 | RNPolynomial( const RNPolynomial & ); 95 | /// 96 | RNPolynomial( const Array &in_adCoefs ); 97 | /// Polynomial with in_iDim variables, highest power in_iDegree 98 | RNPolynomial(int in_iDim, int in_iDegree); 99 | /// Polynomial of dimension 1, degree in_iNumCoefs - 1 100 | RNPolynomial(int in_iNumCoefs); 101 | /// Default polynomial, evaluates to 0 102 | RNPolynomial(); 103 | //@} 104 | 105 | /// 106 | virtual ~RNPolynomial(); 107 | 108 | /**@name Read, write, print */ 109 | //@{ 110 | /// Debugging print. 111 | void Print() const ; 112 | /// Writes dimension, degree, and coefficients 113 | void Write ( ofstream &out ) const ; 114 | /// Reads dimension, degree, and coefficients 115 | WINbool Read ( ifstream &in ); 116 | //@} 117 | 118 | /// 119 | static WINbool Test(); 120 | }; 121 | 122 | #include "Rn_Polynomial_i.H" 123 | #endif 124 | -------------------------------------------------------------------------------- /vipss/src/surfacer/utils/R2_Line_i.H: -------------------------------------------------------------------------------- 1 | /* ------------------------------------------------------------------------- 2 | * DESCR : Is the point on the line? 3 | * ------------------------------------------------------------------------- */ 4 | inline WINbool R2Line::IsPtOnLine(const R2Pt &in_pt) const 5 | { 6 | double dA, dB, dC; 7 | Implicit( dA, dB, dC ); 8 | 9 | const double dSum = dA * in_pt[0] + dB * in_pt[1] + dC; 10 | 11 | return RNIsZero( dSum ); 12 | } 13 | 14 | /* ------------------------------------------------------------------------- 15 | * DESCR : Variations on FindPtOnLine 16 | * ------------------------------------------------------------------------- */ 17 | inline double R2Line::Dist_to_line(const R2Pt &in_pt) const 18 | { 19 | R2Pt out_pt; 20 | double out_t, out_d; 21 | FindPtOnLine(in_pt, out_pt, out_t, out_d); 22 | 23 | return out_d; 24 | } 25 | 26 | inline R2Pt R2Line::Project(const R2Pt &in_pt) const 27 | { 28 | R2Pt out_pt; 29 | double out_t, out_d; 30 | FindPtOnLine(in_pt, out_pt, out_t, out_d); 31 | 32 | return out_pt; 33 | } 34 | 35 | inline 36 | double R2Line::Projected_dist_on_line(const R2Pt &in_pt) const 37 | { 38 | R2Pt out_pt; 39 | double out_t, out_d; 40 | FindPtOnLine(in_pt, out_pt, out_t, out_d); 41 | 42 | return out_t; 43 | } 44 | 45 | 46 | /* ------------------------------------------------------------------------- 47 | * DESCR : Determine if the two lines are parallel 48 | * ------------------------------------------------------------------------- */ 49 | inline 50 | WINbool IsParallel(const R2Line &in_l1, const R2Line &in_l2) 51 | { 52 | double res = 1.0f - (double) fabs( Dot(in_l1.Vec(), in_l2.Vec()) ); 53 | if ( RNIsZero( res ) ) 54 | return TRUE; 55 | 56 | return FALSE; 57 | } 58 | 59 | /* ------------------------------------------------------------------------- 60 | * DESCR : Determine if the two lines are perpendicular 61 | * ------------------------------------------------------------------------- */ 62 | inline 63 | WINbool IsPerpendicular(const R2Line &in_l1, const R2Line &in_l2) 64 | { 65 | if ( RNIsZero( Dot( in_l1.Vec(), in_l2.Vec() ) ) ) 66 | return TRUE; 67 | 68 | return FALSE; 69 | } 70 | 71 | 72 | /* ------------------------------------------------------------------------- 73 | * DESCR : Comparison 74 | * ------------------------------------------------------------------------- */ 75 | inline WINbool R2Line::operator==(const R2Line &in_l) const 76 | { 77 | if (ApproxEqual(Vec(), in_l.Vec()) == FALSE) return FALSE; 78 | 79 | if (ApproxEqual(Pt(), in_l.Pt()) == TRUE) return TRUE; 80 | 81 | return FALSE; 82 | } 83 | 84 | 85 | inline double R2Line::Slope() const 86 | { 87 | const R2Pt pt = m_pt + m_vec; 88 | if ( RNIsZero( m_pt[0] - pt[0] ) ) 89 | return 1e30; 90 | 91 | return (m_pt[1] - pt[1]) / (m_pt[0] - pt[0]); 92 | } 93 | 94 | /* ------------------------------------------------------------------------- 95 | * DESCR : Return a perpendicular line 96 | * ------------------------------------------------------------------------- */ 97 | double R2Line::Intercept() const 98 | { 99 | if ( Vertical() ) 100 | return m_pt[0]; 101 | 102 | return m_pt[1] - Slope() * m_pt[0]; 103 | } 104 | 105 | 106 | 107 | /* ------------------------------------------------------------------------- 108 | * DESCR : Copy a line 109 | * ------------------------------------------------------------------------- */ 110 | inline R2Line::R2Line() : m_pt(0,0), m_vec(0,1) 111 | { 112 | } 113 | 114 | inline void R2Line::SetVec(const R2Vec &in_vec) 115 | { 116 | ASSERT( ! RNIsZero( Length( m_vec ) ) ); 117 | m_vec = UnitSafe(in_vec); 118 | } 119 | 120 | inline R2Line::R2Line(const R2Line &in_l) 121 | { 122 | (*this) = in_l; 123 | } 124 | 125 | inline 126 | R2Line::R2Line(const R2Pt &in_pt, const R2Vec &in_vec) 127 | : m_pt( in_pt ), m_vec( UnitSafe(in_vec) ) 128 | { 129 | ASSERT( ! RNIsZero( Length( m_vec ) ) ); 130 | } 131 | 132 | 133 | 134 | inline 135 | R2Line::R2Line(const R2Pt &in_pt1, const R2Pt &in_pt2) 136 | : m_pt( in_pt1 ), m_vec( UnitSafe( in_pt2 - in_pt1 ) ) 137 | { 138 | ASSERT( ! RNIsZero( Length( m_vec ) ) ); 139 | } 140 | 141 | -------------------------------------------------------------------------------- /vipss/src/surfacer/utils/Mesh_Spatial.H: -------------------------------------------------------------------------------- 1 | // This may look like C code, but it is really -*- C++ -*- 2 | // Copyright (c) 1992 Hugues H. Hoppe; All rights reserved. 3 | 4 | #ifndef Spatial_h 5 | #define Spatial_h 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | 14 | class Bbox; 15 | 16 | class Spatial { // abstract class 17 | public: 18 | Spatial(int pgn); 19 | virtual ~Spatial(); 20 | protected: 21 | friend class SpatialSearch; 22 | int gn; // grid size 23 | double gni; // 1/gn 24 | int indexinbounds(int i) const; 25 | int indicesinbounds(int ci[3]) const; 26 | int double2index(double fd) const; 27 | double index2double(int i) const; 28 | void point2indices(const R3Pt& p, int ci[3]) const; 29 | void indices2point(int ci[3], R3Pt& p) const; 30 | void indices2bbox(int ci[3], Bbox& bb) const; 31 | int encode(int ci[3]) const; 32 | void decode(int en, int ci[3]) const; 33 | // for SpatialSearch: 34 | // Add elements from cell ci[3] to priority queue with priority equal 35 | // to distance from pcenter squared. May use set to avoid duplication. 36 | virtual void addcell(int ci[3], Pqueue& pq, const R3Pt& pcenter, 37 | Set& set) const=0; 38 | // Refine distance estimate of first entry in pq (optional) 39 | virtual void pqrefine(Pqueue& pq, const R3Pt& pcenter) const; 40 | virtual Univ pqid(Univ pqe) const=0; // given pq entry, return id 41 | private: 42 | DISABLECOPY(Spatial); 43 | }; 44 | 45 | class PointSpatial : public Spatial { 46 | public: 47 | PointSpatial(int pgn); 48 | ~PointSpatial(); 49 | void clear(); 50 | // id!=0 51 | void enter(Univ id, const R3Pt* pp); // note: pp not copied! 52 | void remove(Univ id, const R3Pt* pp); // must exist, else die 53 | protected: 54 | void addcell(int ci[3], Pqueue& pq, const R3Pt& pcenter, 55 | Set& set) const; 56 | Univ pqid(Univ pqe) const; 57 | private: 58 | struct Node { 59 | Node(Univ pid, const R3Pt* pp) : id(pid), p(pp) { } 60 | Univ id; 61 | const R3Pt* p; 62 | }; 63 | MMap*> map; // encoded cube index -> Stack 64 | }; 65 | 66 | class ObjectSpatial : public Spatial { 67 | public: 68 | typedef double (*DISTF)(const R3Pt& p, Univ id); 69 | ObjectSpatial(int pgn, DISTF papproxf2, DISTF pexactf2); 70 | ~ObjectSpatial(); 71 | void clear(); 72 | // id!=0 73 | // Enter an object that comes with a containment function: the 74 | // function returns true if the object lies within a given bounding 75 | // box. A starting point is also given. 76 | void enter(Univ id, const R3Pt& startp, 77 | WINbool (*fcontains)(const Bbox& bb)); 78 | // Find the objects that could possibly intersect the segment (p1,p2). 79 | // The objects are not returned in the exact order of intersection! 80 | // However, once should_stop is set (ftest's return), the procedure 81 | // will keep calling ftest with all objects that could be closer. 82 | void searchsegment(const R3Pt& p1, const R3Pt& p2, 83 | int (*ftest)(Univ id)) const; 84 | protected: 85 | void addcell(int ci[3], Pqueue& pq, const R3Pt& pcenter, 86 | Set& set) const; 87 | void pqrefine(Pqueue& pq, const R3Pt& pcenter) const; 88 | Univ pqid(Univ pqe) const; 89 | private: 90 | MMap*> map; // encoded cube index -> Stack 91 | DISTF approxf2; 92 | DISTF exactf2; 93 | }; 94 | 95 | // Search from a point. 96 | class SpatialSearch { 97 | public: 98 | // pmaxdis is only a request, you may get objects that lie farther 99 | SpatialSearch(const Spatial& psp, const R3Pt& pp, 100 | double pmaxdis=10.); 101 | ~SpatialSearch(); 102 | int done(); 103 | Univ next(double* dis2=0); // ret id 104 | private: 105 | friend class Spatial; 106 | const Spatial& sp; 107 | const R3Pt pcenter; 108 | double maxdis; 109 | Pqueue pq; // pq of entries by distance 110 | int ssi[2][3]; // search space indices (extents) 111 | double disbv2; // distance to search space boundary 112 | int axis; // axis to expand next 113 | int dir; // direction in which to expand next (0,1) 114 | Set setevis; // may be used by addcell() 115 | int ncellsv; 116 | int nelemsv; 117 | void getclosestnextcell(); 118 | void expandsearchspace(); 119 | void consider(int ci[3]); 120 | DISABLECOPY(SpatialSearch); 121 | }; 122 | 123 | #endif 124 | 125 | -------------------------------------------------------------------------------- /vipss/src/surfacer/ImplicitedSurfacing.cpp: -------------------------------------------------------------------------------- 1 | #include "ImplicitedSurfacing.h" 2 | 3 | 4 | typedef std::chrono::high_resolution_clock Clock; 5 | 6 | 7 | static Surfacer *p_ImplicitSurfacer; 8 | 9 | static int TriProc(int in_i1, int in_i2, int in_i3, VERTICES vs) { 10 | const R3Pt pt = vs.ptr[in_i1].position; 11 | p_ImplicitSurfacer->s_afaceSurface.addItem( R3Pt_i( in_i3, in_i2, in_i1 ) ); 12 | return 1; 13 | } 14 | 15 | static void VertProc(VERTICES vs) { 16 | p_ImplicitSurfacer->s_aptSurface.need( vs.count ); 17 | p_ImplicitSurfacer->s_avecSurface.need( vs.count ); 18 | for ( int i = 0; i < vs.count; i++ ) { 19 | p_ImplicitSurfacer->s_aptSurface[i] = vs.ptr[i].position; 20 | p_ImplicitSurfacer->s_avecSurface[i] = vs.ptr[i].normal; 21 | } 22 | } 23 | 24 | 25 | 26 | void Surfacer::CalSurfacingPara(vector&Vs, int nvoxels){ 27 | 28 | vectorleftcorner(3, DBL_MAX); 29 | vectorrightcorner(3, DBL_MIN); 30 | vectormidpoint(3,0); 31 | 32 | int nv = Vs.size()/3; 33 | for(int i=0;i&Vs,int n_voxels, bool ischeckall, 67 | double (*function)(const R3Pt &in_pt)){ 68 | 69 | p_ImplicitSurfacer = this; 70 | ClearBuffer(); 71 | 72 | CalSurfacingPara(Vs, n_voxels); 73 | 74 | 75 | //polygonize(function, size, bounds, st, triproc, vertproc); 76 | double thresDist = 1e-3; 77 | 78 | double re_time; 79 | cout<<"Implicit Surfacing: "< &v, vector&fv){ 109 | 110 | v = all_v; 111 | fv = all_fv; 112 | } 113 | 114 | void Surfacer::WriteSurface(vector **v, vector **fv){ 115 | 116 | *v = &all_v; 117 | *fv = &all_fv; 118 | } 119 | 120 | void Surfacer::ClearBuffer(){ 121 | 122 | ClearSingleComponentBuffer(); 123 | all_v.clear(); 124 | all_fv.clear(); 125 | } 126 | 127 | void Surfacer::ClearSingleComponentBuffer(){ 128 | s_aptSurface.clearcompletely(); 129 | s_avecSurface.clearcompletely(); 130 | s_afaceSurface.clearcompletely(); 131 | } 132 | 133 | void Surfacer::GetCurSurface(vector&v,vector&fv){ 134 | 135 | int beInd = v.size()/3; 136 | for(int i=0;i&v,vector&fv){ 148 | 149 | int beInd = all_v.size()/3; 150 | all_v.insert(all_v.end(),v.begin(),v.end()); 151 | 152 | for(auto a:fv)all_fv.push_back(beInd+a); 153 | 154 | } 155 | -------------------------------------------------------------------------------- /vipss/src/surfacer/utils/Mesh_HashStruct.H: -------------------------------------------------------------------------------- 1 | // This may look like C code, but it is really -*- C++ -*- 2 | // Copyright (c) 1992 Hugues H. Hoppe; All rights reserved. 3 | 4 | #ifndef HashStruct_h 5 | #define HashStruct_h 6 | 7 | #if 0 8 | { 9 | HashStruct hs; 10 | ForHashStruct(hs,segment,s) { do(s); } EndFor; 11 | } 12 | #endif 13 | 14 | #include 15 | 16 | 17 | /** \class BHashStruct Mesh_HashStruct.H utils/Mesh_HashStruct.H 18 | \ingroup MeshesHash 19 | 20 | \brief Basic hash table, user supplied has function 21 | 22 | This should be a templated class, but uses Univ (void *) instead. 23 | 24 | Maintains a set of structures. 25 | The structures are hashed according to a user-provided function hashf. 26 | Note: hashf can return any value including zero. 27 | Also, equality of two structures is determined by user function cmpf. 28 | Note: cmpf should return: does_not_match (as does strcmp)! 29 | Note for hacker: when cmpf is invoked, its first arg is st (below) 30 | Thus, st (structure template) can be fake and cmpf can be asymmetric. 31 | Note: BHashStruct should be empty prior to destruction. 32 | */ 33 | class BHashStruct : public BMap { 34 | public: 35 | /// Hash function 36 | typedef Univ (*HASHF)(Univ); 37 | /// Comparison function 38 | typedef int (*CMPF)(Univ, Univ); 39 | /// Need both a hash function and comparison function 40 | BHashStruct(HASHF phashf, CMPF pcmpf); 41 | /// 42 | ~BHashStruct(); 43 | /// s!=0, s must be new/not in table 44 | void enter(Univ s); 45 | /// return: is_new y/n 46 | int add(Univ s); 47 | /// return s found or 0 48 | Univ retrieve(Univ st) const; 49 | /// return wasfound 50 | int remove(Univ st); 51 | /// die if empty, used for iteration ?? 52 | Univ getone() const; 53 | /// die if empty 54 | Univ removeone(); 55 | private: 56 | HASHF hashf; 57 | CMPF cmpf; 58 | Univ replace(Univ k, Univ v); // disable ?? permitted 59 | }; 60 | 61 | /** \class BHashStructIter Mesh_HashStruct.H utils/Mesh_HashStruct.H 62 | \ingroup MeshesHash 63 | 64 | \brief Basic hash tableiterator 65 | */ 66 | class BHashStructIter : public BMapIter { 67 | public: 68 | inline BHashStructIter(const BHashStruct& s) : BMapIter(s) { } 69 | inline BHashStructIter(const BHashStruct& s, MeshRandom& r) 70 | : BMapIter(s,r) { } 71 | }; 72 | 73 | //---------------------------------------------------------------------------- 74 | 75 | inline Univ BHashStruct::getone() const { 76 | BMapIter si(*this); return si.value(); 77 | } 78 | inline Univ BHashStruct::removeone() { 79 | Univ e=getone(); remove(e); return e; 80 | } 81 | 82 | //---------------------------------------------------------------------------- 83 | 84 | template class HashStructIter; 85 | 86 | /** \class HashStruct Mesh_HashStruct.H utils/Mesh_HashStruct.H 87 | \ingroup MeshesHash 88 | 89 | \brief Hash table. Template wrapper around HashStruct. 90 | 91 | See BHashStruct for method descriptions 92 | GNUG chokes on Conv, so I did it manually here 93 | */ 94 | template 95 | class HashStruct : public BHashStruct { 96 | public: 97 | /// 98 | typedef Univ (*HASHF)(const T*); 99 | /// 100 | typedef int (*CMPF)(const T*, const T*); 101 | /// 102 | HashStruct(HASHF phashf, CMPF pcmpf) : 103 | /// 104 | BHashStruct((BHashStruct::HASHF)phashf,(BHashStruct::CMPF)pcmpf) { } 105 | /// 106 | ~HashStruct() { } 107 | /// 108 | inline void enter(T* e) { BHashStruct::enter(Univ(e)); } 109 | /// 110 | inline T* retrieve(const T* e) const 111 | { return (T*)(void*)(BHashStruct::retrieve(Conv::e((T*)e))); } 112 | /// 113 | inline int add(T* e) { return BHashStruct::add(Univ(e)); } 114 | /// 115 | inline int remove(const T* e) 116 | { return BHashStruct::remove(Conv::e((T*)e)); } 117 | /// 118 | inline T* getone() const { return (T*)(void*)(BHashStruct::getone()); } 119 | /// 120 | inline T* removeone() { return (T*)(void*)(BHashStruct::removeone()); } 121 | // typedef HashStructIter Iter; 122 | }; 123 | 124 | /** \class HashStructIter Mesh_HashStruct.H utils/Mesh_HashStruct.H 125 | \ingroup MeshesHash 126 | 127 | \brief Template wrapper around Basic hash tableiterator 128 | */ 129 | template 130 | class HashStructIter : public BMapIter { 131 | public: 132 | HashStructIter(const HashStruct& s) : BMapIter(s) { } 133 | HashStructIter(const HashStruct& s, MeshRandom& r) : BMapIter(s,r) { } 134 | ~HashStructIter() { } 135 | inline T* operator()() const { return (T*)(void*)(BMapIter::value()); } 136 | private: 137 | void key() const; // disable 138 | void value() const; // disable 139 | }; 140 | 141 | #define ForHashStruct(S,T,V) \ 142 | { for (HashStructIter zz(S);zz;zz.next()) { T* V=zz(); 143 | 144 | #endif 145 | 146 | -------------------------------------------------------------------------------- /vipss/src/surfacer/utils/Rn_Vector3_i.H: -------------------------------------------------------------------------------- 1 | // ========================================================= 2 | // 3 | // Methods for R3VectorTC template class 4 | // 5 | // ========================================================= 6 | 7 | 8 | // ------------------------------------- 9 | // constructors 10 | // ------------------------------------- 11 | 12 | template 13 | inline 14 | R3VectorTC::R3VectorTC( const Coord& _dx, const Coord& _dy, const Coord& _dz ) 15 | { 16 | dx = _dx; dy = _dy; dz = _dz; 17 | } 18 | 19 | 20 | // ------------------------------------- 21 | // assignment operators 22 | // ------------------------------------- 23 | 24 | template 25 | inline R3VectorTC& 26 | R3VectorTC::operator += ( const R3VectorTC& v) 27 | { 28 | dx += v.dx; 29 | dy += v.dy; 30 | dz += v.dz; 31 | return *this; 32 | } 33 | 34 | template 35 | inline R3VectorTC& 36 | R3VectorTC::operator -= ( const R3VectorTC& v ) 37 | { 38 | dx -= v.dx; 39 | dy -= v.dy; 40 | dz -= v.dz; 41 | return *this; 42 | } 43 | 44 | template 45 | inline R3VectorTC& 46 | R3VectorTC::operator *= ( const Coord& s ) 47 | { 48 | dx *= s; 49 | dy *= s; 50 | dz *= s; 51 | return *this; 52 | } 53 | 54 | template 55 | inline R3VectorTC& 56 | R3VectorTC::operator /= ( const Coord& s ) 57 | { 58 | const Coord s1 = (Coord) 1.0 / s; 59 | dx *= s1; 60 | dy *= s1; 61 | dz *= s1; 62 | return *this; 63 | } 64 | 65 | // ------------------------------------- 66 | // unary operators 67 | // ------------------------------------- 68 | 69 | template 70 | inline R3VectorTC 71 | R3VectorTC::operator + () const 72 | { 73 | return *this; 74 | } 75 | 76 | template 77 | inline R3VectorTC 78 | R3VectorTC::operator - () const 79 | { 80 | return R3VectorTC( -dx, -dy, -dz ); 81 | } 82 | 83 | 84 | // ------------------------------------- 85 | // miscellaneous methods 86 | // ------------------------------------- 87 | /// Returns a vector which is perpendicular (not unique) 88 | template 89 | inline R3VectorTC R3VectorTC::Perpendicular() const 90 | { 91 | if ( fabs( (*this)[0] ) >= fabs( (*this)[1] ) && fabs( (*this)[0] ) >= fabs( (*this)[2] ) ) { 92 | if ( fabs( (*this)[1] ) > fabs( (*this)[2] ) ) { 93 | return R3VectorTC( -(*this)[1], (*this)[0], 0 ); 94 | } else { 95 | return R3VectorTC( -(*this)[2], 0, (*this)[0] ); 96 | } 97 | } else if ( fabs( (*this)[1] ) >= fabs( (*this)[2] ) ) { 98 | if ( fabs( (*this)[0] ) > fabs( (*this)[2] ) ) { 99 | return R3VectorTC( -(*this)[1], (*this)[0], 0 ); 100 | } else { 101 | return R3VectorTC( 0, -(*this)[1], (*this)[2] ); 102 | } 103 | } 104 | if ( fabs( (*this)[1] ) > fabs( (*this)[0] ) ) { 105 | return R3VectorTC( 0, (*this)[2], -(*this)[1] ); 106 | } else { 107 | return R3VectorTC( (*this)[2], 0, -(*this)[0] ); 108 | } 109 | 110 | ASSERT(FALSE); 111 | 112 | return R3VectorTC(0,0,0); 113 | } 114 | 115 | 116 | // ------------------------------------- 117 | // Self-editing functions 118 | // ------------------------------------- 119 | template 120 | inline Coord R3VectorTC::Normalize() 121 | { 122 | const Coord dLen = sqrt(dx * dx + dy * dy + dz * dz); 123 | if ( ! RNIsZero( dLen ) ) { 124 | dx = dx / dLen; 125 | dy = dy / dLen; 126 | dz = dz / dLen; 127 | } 128 | 129 | return dLen; 130 | } 131 | 132 | 133 | // ------------------------------------- 134 | // Read/write/print functions 135 | // ------------------------------------- 136 | template 137 | inline void R3VectorTC::Write(ofstream &out) const 138 | { 139 | out << dx << " " << dy << " " << dz << " "; 140 | } 141 | 142 | template 143 | inline void R3VectorTC::WriteBinary(ofstream &out) const 144 | { 145 | out.write( (const char *) &dx, Dim() * sizeof(Coord) ); 146 | } 147 | 148 | template 149 | inline WINbool R3VectorTC::Read(ifstream &in) 150 | { 151 | 152 | in >> dx >> dy >> dz; 153 | 154 | return in.good() ? TRUE : FALSE; 155 | } 156 | 157 | template 158 | inline WINbool R3VectorTC::ReadBinary(ifstream &in) 159 | { 160 | in.read( (char *) &dx, Dim() * sizeof(Coord) ); 161 | 162 | return in.good() ? TRUE : FALSE; 163 | } 164 | 165 | template 166 | inline void R3VectorTC::Print( const WINbool in_bDoReturn ) const 167 | { 168 | cout << dx << " " << dy << " " << dz; 169 | if ( in_bDoReturn == TRUE ) 170 | cout << "\n"; 171 | else 172 | cout << " "; 173 | } 174 | 175 | 176 | 177 | -------------------------------------------------------------------------------- /vipss/src/surfacer/utils/R2_Contour.H: -------------------------------------------------------------------------------- 1 | #ifndef _RN_DEFS_CONTOUR_H 2 | #define _RN_DEFS_CONTOUR_H 3 | 4 | #include "Rn_Polygon.H" 5 | 6 | /** \class R2Contour R2_Contour.H utils/R2_Contour.H 7 | \ingroup PolyGeometry 8 | \brief A collection of 2D polygons with a thickness and a location in space. 9 | Each plygon is defined by lists of points which make a polygon in a plane. 10 | This class isn't really finished and is a bit schitzoid. 11 | 12 | There are two uses for this class. The first is as a stack of contours. The second is as 13 | a collection of polygons in a plane. In both cases, the plane is defined by a plane normal and a distance (z level) 14 | along that unit normal. For a stack of contours, the plane contains the first contour and the others 15 | are spaced dWidth apart from there. 16 | 17 | Files:
18 | - include/utils/R2_Contour.H
19 | - include/utils/R2_Contour_i.H
20 | - utils/geometry/R2Contour.cpp
21 | */ 22 | class R2Contour { 23 | protected: 24 | /// Planar polygon 25 | Array m_apolygons; 26 | /// Vector at each vertex of each polygon 27 | Array< Array< R3Vec > > m_aavecNorm; 28 | /// Spacing between slices 29 | double m_dWidth; 30 | /// Plane normal of all slices 31 | R3Vec m_vecPlaneNormal; 32 | /// Where plane starts along normal 33 | double m_dZLevel; 34 | public: 35 | /**@name Access to data */ 36 | //@{ 37 | /** Dimension. 38 | This function is constant. 39 | @return 2 40 | */ 41 | int Dim() const { return 2; } 42 | /// Spacing between planes 43 | inline double Width() const { return m_dWidth; } 44 | /// Where along normal planes start 45 | inline double ZLevel() const { return m_dZLevel; } 46 | /// Plane normal of all slices 47 | inline const R3Vec &PlaneNormal() const { return m_vecPlaneNormal; } 48 | /// Number of slices 49 | inline int Num_contours() const { return m_apolygons.num(); } 50 | /// Polygon for slice 51 | inline const R2Polygon & operator[] (int in_iPoly) const; 52 | /// Set normals of slice 53 | inline const Array &Normals( const int in_iPoly ) const { return m_aavecNorm[in_iPoly]; } 54 | /// Do we have slices and are they valid? 55 | inline WINbool Valid() const; 56 | //@} 57 | 58 | /**@name \brief Setting data */ 59 | //@{ 60 | /// Set spacing 61 | inline double & Width() { return m_dWidth; } 62 | /// Set slicing plane direction 63 | inline void SetPlane( const R3Vec &in_vec, double in_dZLevel ); 64 | /// Set point in polygon in slice 65 | inline R2Polygon & operator[] (int in_iPoly) ; 66 | //@} 67 | 68 | /**@name Queries */ 69 | //@{ 70 | /// Total area of all slices 71 | double Area() const ; 72 | /// Average center point of all slices 73 | R2Pt Centroid() const; 74 | //@} 75 | 76 | /**@name Inside/outside/closest routines 77 | Note: These routines assume you have a collection of polygons in the plane. Checks each polygon in turn. 78 | */ 79 | //@{ 80 | /// Is it on or inside the boundary? Checks all; returns true if true for one polygon. 81 | WINbool Inside( const R2Pt & ) const; 82 | /// Is it within epsilon of the boundary? Checks all; returns true if true for one polygon. 83 | WINbool IsBoundary( const R2Pt & ) const; 84 | /// Checks all; returns true if true for all polygons. 85 | WINbool IsConvex() const; 86 | /** Use the winding test to see if the point is inside. 87 | Assumes the polygon is convex. Counts the number of crossings 88 | on a ray from the point to infinity. Checks all; returns true if true for one polygon. */ 89 | WINbool Inside_winding(const R2Pt &) const; 90 | /// Project onto plane 91 | R3Pt Project( const R2Pt & ) const; 92 | /// Closest point on the boundary, if not inside already. Checks all; returns true if true for one polygon. 93 | R2Pt Closest_pt( const R2Pt & ) const; 94 | //@} 95 | 96 | /**@name Comparisons with other contours */ 97 | //@{ 98 | /// Approx equal on the polygons themselves 99 | WINbool operator==( const R2Contour & ) const; 100 | /// This could be very slow. Intersects all polygons of one contour with the polygons of the other. 101 | R2Contour Intersect(const R2Contour &in_contour) const; 102 | //@} 103 | 104 | 105 | /**@name Construction and assignment routines */ 106 | //@{ 107 | /// 108 | inline R2Contour &operator=(const R2Contour &); 109 | /// Add a polygon and normals 110 | inline void Add(const R2Polygon &, const Array &in_avec); 111 | /// 112 | inline R2Contour( const R2Contour &in_poly ); 113 | /// 114 | inline R2Contour( ); 115 | //@} 116 | 117 | /// 118 | virtual inline ~R2Contour() {} 119 | 120 | /**@name Read, write, print */ 121 | //@{ 122 | /// Debugging print. 123 | void Print() const ; 124 | /// Writes points to file. 125 | void Write ( ofstream &out ) const ; 126 | /// Reads points from file. 127 | WINbool Read ( ifstream &in ); 128 | //@} 129 | 130 | /// Check closest point and intersection routines 131 | static WINbool Test(); 132 | }; 133 | 134 | #include "R2_Contour_i.H" 135 | 136 | #endif 137 | 138 | -------------------------------------------------------------------------------- /vipss/src/surfacer/utils/Image_Raw1D.H: -------------------------------------------------------------------------------- 1 | #ifndef __RAW_IMAGES_DEFS_1D_H 2 | #define __RAW_IMAGES_DEFS_1D_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | /** Image manipulation. 9 | 10 | A 1D image 11 | 12 |
Files: 13 |
  • include/utils/Image_Raw1D.H 14 |
  • src/utils/image/IMAGERaw1D.cpp 15 | */ 16 | class IMAGERaw1D { 17 | protected: 18 | 19 | int m_iXSize, m_iYSize; 20 | Array m_aiXIndx; 21 | Array m_afImage; 22 | 23 | public: 24 | /**@name Accessors */ 25 | //@{ 26 | /// 27 | int Width() const { return m_iXSize; } 28 | /// 29 | int Height() const { return m_iYSize; } 30 | /// 31 | int NPixels() const { return m_iXSize * m_iYSize; } 32 | 33 | /// 34 | float operator()( const int in_iX, const int in_iY ) const; 35 | /// 36 | float operator()( const R2Pt & ) const; 37 | /// 38 | float operator()( const int in_iPixel ) const { return m_afImage[in_iPixel]; } 39 | /// 40 | int Index ( const int in_iX, const int in_iY ) const; 41 | /// 42 | int X ( const int in_iIndex ) const; 43 | /// 44 | int Y ( const int in_iIndex ) const; 45 | /// 46 | float Interpolate( const R2Pt &in_pt ) const; 47 | /// 48 | Array InterpolateIndex( const R2Pt &in_pt ) const; 49 | /// 50 | const float * Data() const { return &m_afImage[0]; } 51 | /// 52 | float * Data() { return &m_afImage[0]; } 53 | 54 | /// 55 | WINbool IndexOk( const int in_iX, const int in_iY ) const; 56 | /// Does min/max 57 | float Safe( const int in_iX, const int in_iY ) const; 58 | 59 | //@} 60 | 61 | /**@name Assignements */ 62 | //@{ 63 | /// 64 | void SetSize( const int in_iX, const int in_iY ); 65 | 66 | /// 67 | float &operator()( const int in_iX, const int in_iY ) ; 68 | /// 69 | void Set ( const int in_iPixel, const float &in_pix ); 70 | /// 71 | void Set ( const int in_iX, const int in_iY, const float &in_pix ); 72 | /// 73 | void Set ( const float &in_pix ); 74 | 75 | //@} 76 | 77 | /**@name Resampling */ 78 | //@{ 79 | /// 80 | IMAGERaw1D &operator=( const IMAGERaw1D & ) ; 81 | /// 82 | void Resample( IMAGERaw1D & out_image, 83 | const R2Polygon & in_polyMine, 84 | const R2Polygon & in_polyOut ) const; 85 | /// 86 | void ResampleSimple( IMAGERaw1D & out_image, 87 | const R2Polygon & in_polyMine, 88 | const R2Polygon & in_polyOut, 89 | Array & out_aipt) const; 90 | /// 91 | void ResampleEntire( IMAGERaw1D & out_image, 92 | const R2Polygon & in_polyOut, 93 | Array & out_aipt) const; 94 | /// 95 | void Resample( IMAGERaw1D &out_image, const R3Matrix &in_matMeToOut ) const; 96 | //@} 97 | 98 | /// 99 | IMAGERaw1D(); 100 | /// 101 | IMAGERaw1D( const int in_iX, const int in_iY); 102 | /// 103 | ~IMAGERaw1D(); 104 | 105 | /**@name Read/write */ 106 | //@{ 107 | /// Format determined by filename extension 108 | WINbool Read( const char *in_strFName ); 109 | /// Format determined by filename extension 110 | WINbool Write( const char *in_strFName ) const; 111 | //@} 112 | }; 113 | 114 | inline int IMAGERaw1D::Index( const int in_iX, const int in_iY ) const 115 | { 116 | ASSERT( in_iX >=0 && in_iX < Width() ); 117 | return m_aiXIndx[ in_iY ] + in_iX; 118 | } 119 | 120 | inline float IMAGERaw1D::operator()( const int in_iX, const int in_iY) const 121 | { 122 | return m_afImage[ Index(in_iX, in_iY) ]; 123 | } 124 | 125 | inline float &IMAGERaw1D::operator()( const int in_iX, const int in_iY) 126 | { 127 | return m_afImage[ Index(in_iX, in_iY) ]; 128 | } 129 | 130 | inline float IMAGERaw1D::operator()( const R2Pt &in_pt ) const 131 | { 132 | const int iIndx = Index( WINminmax( (int) (in_pt[0] * m_iXSize + 0.5), 0, m_iXSize - 1 ), 133 | WINminmax( (int) (in_pt[1] * m_iYSize + 0.5), 0, m_iYSize - 1 ) ); 134 | 135 | return m_afImage[iIndx]; 136 | } 137 | 138 | 139 | inline void IMAGERaw1D::Set( const int in_iX, const int in_iY, const float &in_pix ) 140 | { 141 | const int iIndx = Index(in_iX, in_iY); 142 | 143 | m_afImage[ iIndx ] = in_pix; 144 | } 145 | 146 | inline void IMAGERaw1D::Set( const int in_iIndx, const float &in_pix ) 147 | { 148 | m_afImage[ in_iIndx ] = in_pix; 149 | } 150 | 151 | 152 | inline int IMAGERaw1D::X( const int in_iIndex ) const 153 | { 154 | return (in_iIndex) % Width(); 155 | } 156 | 157 | inline int IMAGERaw1D::Y( const int in_iIndex ) const 158 | { 159 | return (in_iIndex) / Width(); 160 | } 161 | 162 | inline WINbool IMAGERaw1D::IndexOk( const int in_iX, const int in_iY ) const 163 | { 164 | if ( in_iX < 0 || in_iY < 0 ) 165 | return FALSE; 166 | 167 | if ( in_iX >= Width() || in_iY >= Height() ) 168 | return FALSE; 169 | 170 | return TRUE; 171 | } 172 | 173 | inline float IMAGERaw1D::Safe( const int in_iX, const int in_iY ) const 174 | { 175 | return (*this)( WINminmax( in_iX, 0, Width() - 1 ), 176 | WINminmax( in_iY, 0, Height() - 1 ) ); 177 | } 178 | 179 | 180 | #endif 181 | 182 | -------------------------------------------------------------------------------- /vipss/src/surfacer/utils/R3_Plane.H: -------------------------------------------------------------------------------- 1 | #ifndef _R3_PLANE_DEFS_H 2 | #define _R3_PLANE_DEFS_H 3 | 4 | 5 | #include 6 | 7 | class R3Line; 8 | class R3Line_seg; 9 | 10 | /** \class R3Plane R3_Plane.H utils/R3_Plane.H 11 | \ingroup LinearGeometry 12 | \brief A plane 13 | 14 | Defined by point, normal or distance, normal or Ax + By + Cz + D = 0.
    15 | The vector formed by dA, dB, dC is of unit length 16 | 17 | Files:
    18 | - include/utils/R3_Plane.H
    19 | - include/utils/R3_Plane_i.H
    20 | - src/utils/geometry/R3Plane.cpp 21 | */ 22 | class R3Plane { 23 | protected: 24 | /// Plane stored as implicit equation, with the vector formed by A,B,C unit length 25 | double m_dA, m_dB, m_dC, m_dD; 26 | 27 | public: 28 | /**@name Access to data */ 29 | //@{ 30 | /// 31 | R3Vec Normal() const { return R3Vec( m_dA, m_dB, m_dC ); } 32 | 33 | /// Return any point on the plane 34 | R3Pt PtOnPlane() const; 35 | 36 | /// How far along the normal is this plane? 37 | double DistOnNormal() const ; 38 | /** \brief Returns the tangent plane 39 | Note that these vectors are not unique. 40 | @param out_vecDs Returned unit length vector, perpendicular to normal and out_vecDt 41 | @param out_vecDt Returned unit length vector, perpendicular to normal and out_vecDs 42 | */ 43 | void TangentPlane( R3Vec &out_vecDs, R3Vec &out_vecDt ) const; 44 | //@} 45 | 46 | /**@name Intersection */ 47 | //@{ 48 | /// Evaluates implicit equation and checks for (approximate) zero 49 | WINbool IsPtOnPlane( const R3Pt &in_pt ) const { return RNIsZero( m_dA * in_pt[0] + m_dB * in_pt[1] + m_dC * in_pt[2] + m_dD ); } 50 | /// Project the point along the normal to the plane 51 | R3Pt ProjectOnPlane( const R3Pt & ) const; 52 | /// How far is the point from the plane? 53 | double DistToPlane( const R3Pt & ) const; 54 | /// Evaluate implicit equation 55 | double Evaluate( const R3Pt &in_pt ) const { return m_dA * in_pt[0] + m_dB * in_pt[1] + m_dC * in_pt[2] + m_dD; } 56 | /** \brief intersect the ray with the plane 57 | @param in_ray The input ray 58 | @param out_dT Distance along the ray to the point of intersection (if any) 59 | @param out_pt Point of intersection (if any) 60 | @returns TRUE if there was an intersection 61 | */ 62 | WINbool IntersectRay( const R3Ray &in_ray, double &out_dT, R3Pt &out_pt ) const; 63 | /// Just return point 64 | R3Pt IntersectRay( const R3Ray &in_ray ) const; 65 | /** \brief Intersect the segment with the plane 66 | If there is an intersection with the line containing the line segment and the plane, 67 | then returns that intersection, even if it isn't in contained in the line segment. Function 68 | will still return false in this case. 69 | @param in_seg The 3D line segment 70 | @param out_dT Distance along the segment of the intersection (if any) 71 | @param out_pt Point of intersection (if any) 72 | @returns TRUE if there was an intersection */ 73 | WINbool Intersect( const R3Line_seg &in_seg, double &out_dT, R3Pt &out_pt ) const; 74 | 75 | /** \brief Intersect the line with the plane 76 | @param in_line The 3D line 77 | @param out_dT Distance along the segment of the intersection (if any) 78 | @param out_pt Point of intersection (if any) 79 | @returns TRUE if there was an intersection */ 80 | WINbool Intersect( const R3Line &in_line, double &out_dT, R3Pt &out_pt ) const; 81 | WINbool IntersectPlane( const R3Plane &in_plane, R3Line &out_line ) const; 82 | //@} 83 | 84 | /**@name Transformation */ 85 | //@{ 86 | /// Rotate and translate the plane, returning a new one 87 | R3Plane Transform( const R4Matrix & ) const; 88 | /// Matrix that takes the plane so that the normal points in the y direction 89 | R3Matrix ToXYZ() const; 90 | //@} 91 | 92 | /**@name Constructors, comparitors */ 93 | //@{ 94 | /// Scale the length of the normal to be unit length 95 | void Normalize(); 96 | /// Flip the normal; 97 | void Flip(); 98 | /// Approximate comparison (RNEpsilon_d) 99 | WINbool operator==( const R3Plane & ) const; 100 | /// Copy plane 101 | R3Plane & operator=( const R3Plane & ); 102 | /// 103 | R3Plane( const R3Plane & ); 104 | /// Construction from a point and a normal 105 | R3Plane( const R3Pt &in_ptOnPlane, const R3Vec &in_vecNormal ); 106 | /// Three non-colinear points form a plane 107 | R3Plane( const R3Pt &in_pt1, const R3Pt &in_pt2, const R3Pt &in_pt3 ); 108 | /// Distance along normal and normal 109 | R3Plane( const double in_dDist, const R3Vec &in_vecNormal ); 110 | /// Implicit equation 111 | R3Plane( const R4Pt &in_ptABCD ); 112 | /// Implicit equation 113 | R3Plane( const double in_dA, const double in_dB, const double in_dC, const double in_dD ) : m_dA(in_dA), m_dB(in_dB), m_dC(in_dC), m_dD(in_dD) { } 114 | /// Default plane is x,z plane 115 | R3Plane( ) : m_dA(0.0), m_dB(1.0), m_dC(0.0), m_dD(0.0) { } 116 | /// 117 | ~R3Plane() {} 118 | //@} 119 | 120 | /**@name Constructors, comparitors */ 121 | //@{ 122 | /// Writes plane as in implicit equation 123 | void Write(ofstream &out); 124 | /// Reads plane as in implicit equation 125 | void Read(ifstream &in); 126 | //@} 127 | 128 | /// 129 | static WINbool Test(); 130 | }; 131 | 132 | #endif 133 | 134 | -------------------------------------------------------------------------------- /vipss/src/surfacer/utils/Mesh_Intersect.H: -------------------------------------------------------------------------------- 1 | #ifndef _MESH_INTERSECT_DEFS_H 2 | #define _MESH_INTERSECT_DEFS_H 3 | 4 | 5 | #include 6 | 7 | /** \class GMeshIntersect Mesh_Intersect.H include/Mesh_Intersect.H 8 | \ingroup MeshesClosest 9 | \brief Intersecting a mesh/closest point 10 | 11 | This class takes as input a GMesh, and builds a spatial partition. This makes 12 | finding the closest point/intersecting rays much faster. However, it takes 13 | a bit of time to set up, so if the mesh is constantly changing, building 14 | the structures is not worth the time. 15 | 16 | Note that if the mesh changes you must call ClearSpatialStructures(). The class 17 | will automatically build a new spatial partition the next time closest point/intersect 18 | is called. 19 | 20 | To get GMesh from PMeshLite, call Mesh(). 21 | */ 22 | class GMeshIntersect { 23 | protected: 24 | 25 | /// This smattering of variables is what's needed to 26 | /// compute intersections/closest points. 27 | PolygonSpatial m_oPsp; 28 | MMap m_oMpf; 29 | MMap m_oTriMap; 30 | MMap m_oSideMap; 31 | GMesh m_meshTrans; 32 | R4Matrix m_frameTrans; 33 | R4Matrix m_frameTransi; 34 | Array m_apoly; 35 | WINbool m_bInitd; 36 | 37 | const GMesh &m_mesh; 38 | 39 | 40 | public: 41 | /**@name Accessor */ 42 | //@{ 43 | const GMesh &GetMesh() const { return m_mesh; } 44 | //@} 45 | 46 | /**@name Create and destroy data */ 47 | //@{ 48 | /// This will get called if structures don't exist 49 | void SetSpatialStructures(); 50 | /// Call when mesh changes 51 | void ClearSpatialStructures(); 52 | //@} 53 | 54 | /**@name Ray intersection */ 55 | //@{ 56 | /** Intersect the ray with the mesh. Mesh may be non-triangular. 57 | @param in_pt Starting point of ray 58 | @param in_vec Direction of ray 59 | @param out_faces For each intersection, the face intersected 60 | @param out_barys For each intersection, the barycentric coords of the intersection point (only 3 terms will be non-zero) 61 | @param out_pts The intersection points 62 | @return TRUE if intersections 63 | */ 64 | WINbool IntersectRay( const R3Pt &in_pt, const R3Vec &in_vec, 65 | Array & out_faces, 66 | Array< Array > & out_barys, 67 | Array< R3Pt > &out_pts ) ; 68 | 69 | /** Intersect the ray with the mesh. Mesh may be non-triangular. 70 | @param in_pt Starting point of ray 71 | @param in_vec Direction of ray 72 | @param out_faces For each intersection, the face intersected 73 | @param out_barys For each intersection, the barycentric coords of the intersection point (only 3 terms will be non-zero) 74 | @return TRUE if intersections 75 | */ 76 | WINbool IntersectRay( const R3Pt &in_pt, const R3Vec &in_vec, 77 | Array & out_faces, 78 | Array< Array > & out_barys ) ; 79 | 80 | /** Intersect the ray with the mesh. 81 | @param in_pt Starting point of ray 82 | @param in_vec Direction of ray 83 | @param out_pts The intersection points 84 | @return TRUE if intersections 85 | */ 86 | WINbool IntersectRay( const R3Pt &in_pt, const R3Vec &in_vec, 87 | Array< R3Pt > &out_pts ) ; 88 | //@} 89 | 90 | /**@name Closest point */ 91 | //@{ 92 | /** Closest point on the mesh. 93 | @param in_pt Point 94 | @param out_face The face containing the closest point 95 | @param out_adBarys The barycentric coords of the closest point 96 | @return The closest point 97 | */ 98 | R3Pt Closest( const R3Pt &in_pt, Face &out_face, Array &out_adBarys ) ; 99 | /** Closest vertex on the mesh. 100 | @param in_pt Point 101 | @return The closest vertex 102 | */ 103 | Vertex ClosestVertex( const R3Pt &in_pt ) ; 104 | /** Closest point on the mesh. 105 | @param in_pt Point 106 | @param out_bIsBdry Was the closest point on the boundary of the mesh? 107 | @return The closest point 108 | */ 109 | R3Pt Closest( const R3Pt &in_pt, WINbool &out_bIsBdry ) ; 110 | /** Closest point on the mesh. 111 | @param in_pt Point 112 | @return The closest point 113 | */ 114 | R3Pt Closest( const R3Pt &in_pt ) ; 115 | 116 | /** Closest point on the mesh. 117 | @param in_pt Point 118 | @param in_face The face to look in 119 | @param out_adBarys The barycentric coords of the closest point 120 | @return The closest point 121 | */ 122 | R3Pt ClosestInFace( const R3Pt &in_pt, const Face in_face, Array &out_adBarys ) const ; 123 | /** Closest point on the boundary mesh. Mesh better have a boundary. 124 | @param in_pt Point 125 | @param out_edge The edge the point was lying on 126 | @param out_blend The distance along the edge, [0,1] 127 | @return The closest point lying on the boundary 128 | */ 129 | R3Pt ClosestOnBoundary( const R3Pt &in_pt, Edge &out_edge, R2Pt &out_blend ) ; 130 | //@} 131 | 132 | /// 133 | GMeshIntersect( const GMesh &in_mesh); 134 | /// 135 | virtual ~GMeshIntersect(); 136 | }; 137 | #endif 138 | 139 | -------------------------------------------------------------------------------- /vipss/src/surfacer/utils/C2_PointTC_i.H: -------------------------------------------------------------------------------- 1 | 2 | template 3 | inline 4 | void C2PointTC::Set( const T in_dRe, const T in_dIm ) 5 | { 6 | m_dRe = in_dRe; 7 | m_dIm = in_dIm; 8 | } 9 | 10 | template 11 | inline 12 | void C2PointTC::SetRadiusTheta( const T in_dRadius, const T in_dTheta ) 13 | { 14 | m_dRe = in_dRadius * cos( in_dTheta ); 15 | m_dIm = in_dRadius * sin( in_dTheta ); 16 | } 17 | 18 | template 19 | inline 20 | C2PointTC& C2PointTC::operator += ( const C2PointTC &in_pt ) 21 | { 22 | (*this) = (*this) + in_pt; 23 | return *this; 24 | } 25 | /// 26 | template 27 | inline 28 | C2PointTC& C2PointTC::operator -= ( const C2PointTC &in_pt ) 29 | { 30 | (*this) = (*this) - in_pt; 31 | return *this; 32 | } 33 | /// 34 | template 35 | inline 36 | C2PointTC& C2PointTC::operator *= ( const C2PointTC &in_pt ) 37 | { 38 | (*this) = (*this) * in_pt; 39 | return *this; 40 | } 41 | /// 42 | template 43 | inline 44 | C2PointTC& C2PointTC::operator /= ( const C2PointTC &in_pt ) 45 | { 46 | (*this) = (*this) / in_pt; 47 | return *this; 48 | } 49 | 50 | template 51 | inline 52 | C2PointTC C2PointTC::operator+( const C2PointTC &in_pt ) const 53 | { 54 | return C2PointTC( m_dRe + in_pt.m_dRe, m_dIm + in_pt.m_dIm ); 55 | } 56 | 57 | template 58 | inline 59 | C2PointTC C2PointTC::operator+( const T &in_pt ) const 60 | { 61 | return C2PointTC( m_dRe + in_pt, m_dIm ); 62 | } 63 | 64 | template 65 | inline 66 | C2PointTC C2PointTC::operator-( const C2PointTC &in_pt ) const 67 | { 68 | return C2PointTC( m_dRe - in_pt.m_dRe, m_dIm - in_pt.m_dIm ); 69 | } 70 | 71 | template 72 | inline 73 | C2PointTC C2PointTC::operator-( const T &in_pt ) const 74 | { 75 | return C2PointTC( m_dRe - in_pt, m_dIm ); 76 | } 77 | 78 | template 79 | inline 80 | C2PointTC C2PointTC::operator-() const 81 | { 82 | return C2PointTC( -m_dRe, -m_dIm ); 83 | } 84 | 85 | template 86 | inline 87 | C2PointTC C2PointTC::operator*( const C2PointTC &in_pt ) const 88 | { 89 | return C2PointTC( m_dRe * in_pt.m_dRe - m_dIm * in_pt.m_dIm, 90 | m_dRe * in_pt.m_dIm + m_dIm * in_pt.m_dRe ); 91 | } 92 | 93 | template 94 | inline 95 | C2PointTC C2PointTC::operator/( const C2PointTC &in_pt ) const 96 | { 97 | const T dDenom = in_pt.real() * in_pt.real() + in_pt.imag() * in_pt.imag(); 98 | 99 | return C2PointTC( (m_dRe * in_pt.m_dRe + m_dIm * in_pt.m_dIm) / dDenom, 100 | (m_dIm * in_pt.m_dRe - m_dRe * in_pt.m_dIm ) / dDenom ); 101 | } 102 | 103 | template 104 | inline 105 | WINbool C2PointTC::operator==( const C2PointTC &in_pt ) const 106 | { 107 | if ( ( in_pt.real() == real() ) && ( in_pt.imag() == imag() ) ) 108 | return TRUE; 109 | return FALSE; 110 | } 111 | 112 | template 113 | inline 114 | WINbool C2PointTC::operator!=( const C2PointTC &in_pt ) const 115 | { 116 | if ( ( in_pt.real() == real() ) || ( in_pt.imag() == imag() ) ) 117 | return FALSE; 118 | return TRUE; 119 | } 120 | 121 | template 122 | inline C2PointTC conjg( const C2PointTC &in_pt ) 123 | { 124 | return C2PointTC( in_pt.real(), -in_pt.imag() ); 125 | } 126 | 127 | template 128 | inline T norm( const C2PointTC &in_pt ) 129 | { 130 | return in_pt.real() * in_pt.real() + in_pt.imag() * in_pt.imag(); 131 | } 132 | 133 | template 134 | inline C2PointTC pow( const C2PointTC &in_pt, const T in_d ) 135 | { 136 | const T dAng = atan2( in_pt.imag(), in_pt.real() ); 137 | const T dRad = in_pt.Length(); 138 | 139 | const T dRadNew = pow( dRad, in_d ); 140 | const T dAngNew = dAng * in_d; 141 | 142 | return C2PointTC( dRadNew * cos( dAngNew ), dRadNew * sin( dAngNew ) ); 143 | } 144 | 145 | template 146 | inline C2PointTC sqrt( const C2PointTC &in_pt ) 147 | { 148 | return pow(in_pt, (T) 0.5); 149 | } 150 | 151 | 152 | extern double RNEpsilon_d; 153 | extern float RNEpsilon_f; 154 | 155 | template 156 | inline WINbool 157 | ApproxEqual(const C2PointTC& v1, const C2PointTC& v2, const C2PointTC& in_dEps ) 158 | { 159 | return ( fabs( v1.real() - v2.real() ) < in_dEps.real() && 160 | fabs( v1.imag() - v2.imag() ) < in_dEps.imag() ) ? TRUE : FALSE; 161 | } 162 | 163 | inline WINbool 164 | ApproxEqual(const C2PointTC& v1, const C2PointTC& v2, const double dEps = RNEpsilon_d ) 165 | { 166 | return ( fabs( v1.real() - v2.real() ) < dEps && 167 | fabs( v1.imag() - v2.imag() ) < dEps) ? TRUE : FALSE; 168 | } 169 | 170 | inline WINbool 171 | RNIsZero(const C2PointTC& pt, const double dEps = RNEpsilon_d ) 172 | { 173 | return ( fabs( pt.real() ) < dEps && 174 | fabs( pt.imag() ) < dEps) ? TRUE : FALSE; 175 | } 176 | 177 | inline WINbool 178 | ApproxEqual(const C2PointTC& v1, const C2PointTC& v2, const double dEps = RNEpsilon_f ) 179 | { 180 | return ( fabs( v1.real() - v2.real() ) < dEps && 181 | fabs( v1.imag() - v2.imag() ) < dEps) ? TRUE : FALSE; 182 | } 183 | 184 | inline WINbool 185 | RNIsZero(const C2PointTC& pt, const float dEps = RNEpsilon_f ) 186 | { 187 | return ( fabs( pt.real() ) < dEps && 188 | fabs( pt.imag() ) < dEps) ? TRUE : FALSE; 189 | } 190 | 191 | /// 192 | template 193 | inline ostream& operator<<( ostream &out, const C2PointTC &in_pt ) 194 | { 195 | out << in_pt.real() << " " << in_pt.imag() << " "; 196 | return out; 197 | } 198 | 199 | /// 200 | template 201 | inline istream& operator>>( istream &in, C2PointTC &out_pt ) 202 | { 203 | in >> out_pt.real() >> out_pt.imag(); 204 | return in; 205 | } 206 | --------------------------------------------------------------------------------