├── Projects ├── TeethStudio │ ├── cmain.txt │ ├── main.txt │ ├── color.bmp │ ├── stripe.bmp │ ├── stripe2.bmp │ ├── depth_renderer.frag │ ├── depth_renderer.vert │ ├── back_texcoord_render.frag │ ├── front_texcoord_render.frag │ ├── curve_render.frag │ ├── volumeRender.vert │ ├── curve_render.vert │ ├── front_texcoord_render.vert │ ├── back_texcoord_render.vert │ ├── mat.dmat │ ├── mesh_render.vert │ ├── TeethStudio.vcxproj.user │ └── mesh_render.frag ├── TeethRootRecoAlg │ ├── TeethRootRecoAlg.aps │ ├── TeethRootRecoAlg.rc │ ├── x64 │ │ └── Release │ │ │ └── TeethRootRecoAlg.res │ ├── resource.h │ ├── teethProjection.h │ └── TeethRootRecoAlg.vcxproj.filters ├── AlgColle │ └── AlgColle.vcxproj.user ├── DataColle │ └── DataColle.vcxproj.user └── HarmonicSegAlg │ └── HarmonicSegAlg.vcxproj.filters ├── panorama.jpg ├── Data └── NDT │ ├── panorama.jpg │ └── panorama_label.png ├── Src ├── TeethStudio │ ├── color.bmp │ ├── imface.qrc │ ├── stripe.bmp │ ├── stripe2.bmp │ ├── panoramic_simulation_test_action.cpp │ ├── depth_renderer.frag │ ├── depth_renderer.vert │ ├── back_texcoord_render.frag │ ├── front_texcoord_render.frag │ ├── curve_render.frag │ ├── panoramic_simulation.cpp │ ├── volumeRender.vert │ ├── main.cpp │ ├── curve_render.vert │ ├── front_texcoord_render.vert │ ├── back_texcoord_render.vert │ ├── hot_key_action.h │ ├── visual_utils.h │ ├── panoramic_simulation.h │ ├── mesh_render.vert │ ├── camera.h │ ├── edit_feature_edge_action.h │ ├── panoramic_simulation.ui │ ├── camera.cpp │ ├── manipulation_action.h │ ├── texture_wrapper.h │ ├── volume_data_segmentation_action.h │ ├── visual_utils.cpp │ ├── scene.h │ ├── action_manager.h │ ├── texture_wrapper.cpp │ ├── teeth_reconstruction_action.h │ ├── ui_context.h │ ├── mesh_render.frag │ ├── cmodelviewer.h │ ├── scene_curve_object.h │ ├── action_base.h │ ├── panoramic_simulation_test_action.h │ ├── teeth_reconstruction_test_action.h │ ├── harmonic_field_segmentation_action.h │ ├── scene_mesh_object.h │ ├── imface_window.h │ ├── ui_context.cpp │ ├── volume_data_segmentation_action.cpp │ ├── panoramic_image_registration.h │ ├── scene_volume_object.h │ ├── cmodelviewer.cpp │ ├── scene.cpp │ ├── hot_key_action.cpp │ └── cvmatandqimage.h ├── AlgColle │ ├── non_rigid_icp.h │ ├── image_base_alg.cpp │ ├── panoramic_alg.cpp │ ├── shape_deformation.cpp │ ├── prereq.h │ ├── panoramic_alg.h │ ├── linear_algebra_alg.h │ ├── rigid_icp.h │ ├── shape_deformation.h │ ├── linear_algebra_alg.cpp │ ├── image_base_alg.h │ ├── cgal_arap_deform.h │ ├── morphlogic_operation.h │ ├── correspondence_builder.h │ ├── arap_deform.h │ ├── cgal_arap_deform.cpp │ ├── numerical_base_alg.h │ ├── rigid_icp.cpp │ ├── morph_skel_dental_mesh_seg.h │ ├── curve_base_alg.h │ └── arap_deform.cpp ├── TeethRootRecoAlg │ ├── dental_template_fitting.cpp │ ├── prereq.h │ ├── dental_template_fitting.h │ ├── panoramic_fitting.h │ └── ndt_registration.h ├── AdditionalLibs │ ├── XWGeodesic │ │ ├── Parameters.h │ │ ├── ModelWrapper.cpp │ │ ├── ModelWrapper.h │ │ ├── Extremity_Point_Utils.h │ │ ├── xw_geodesic_wrapper.h │ │ ├── ComputeGeodesics.cpp │ │ ├── ICH_WindowFiltering.h │ │ ├── Xin_Wang.h │ │ ├── Extremity_Point_Utils.cpp │ │ ├── FacePoint.h │ │ ├── ExactDGPMethod.h │ │ ├── DistanceApproach.h │ │ ├── EdgePoint.h │ │ ├── Point3D.cpp │ │ ├── BaseModel.h │ │ └── Point3D.h │ ├── prereq.h │ ├── libicp │ │ ├── libicp_wrapper.h │ │ ├── libicp_wrapper.cpp │ │ ├── icpPointToPoint.h │ │ ├── icpPointToPlane.h │ │ ├── demo.cpp │ │ ├── icp.cpp │ │ └── icp.h │ ├── obb │ │ ├── cpqp_obb_wrapper.h │ │ ├── Build.h │ │ ├── Tri.h │ │ ├── GetTime.h │ │ ├── TriDist.h │ │ ├── BV.h │ │ └── cpqp_obb_wrapper.cpp │ └── lbfgs │ │ ├── Non_Linear_Optimization.h │ │ ├── Non_Linear_Optimization.cpp │ │ └── arithmetic_ansi.h ├── DataColle │ ├── custom_itk_type.h │ ├── prereq.h │ ├── geodesic_type.h │ ├── obb_type.h │ ├── base_object.h │ ├── geo_primit.cpp │ ├── aux_geo_utils.h │ ├── geo_primit.h │ ├── data_io.h │ ├── curve_object.h │ ├── volume_data_object.h │ ├── teeth_template_object.h │ ├── geodesic_type.cpp │ ├── curve_object.cpp │ ├── base_object.cpp │ ├── cgal_igl_converter.h │ ├── volume_data_object.cpp │ ├── custom_openmesh_type.h │ ├── data_pool.h │ ├── aabb_type.h │ ├── Polyhedron_type.h │ ├── teeth_template_object.cpp │ ├── mesh_object.h │ ├── Polyhedron_type_fwd.h │ └── rplyfile.h └── HarmonicSegAlg │ ├── prereq.h │ └── harmonic_field.h ├── shortcut key.txt ├── .gitignore └── README.md /Projects/TeethStudio/cmain.txt: -------------------------------------------------------------------------------- 1 | 1 -------------------------------------------------------------------------------- /Projects/TeethStudio/main.txt: -------------------------------------------------------------------------------- 1 | 1 -------------------------------------------------------------------------------- /panorama.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chinacui/teethdemo/HEAD/panorama.jpg -------------------------------------------------------------------------------- /Data/NDT/panorama.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chinacui/teethdemo/HEAD/Data/NDT/panorama.jpg -------------------------------------------------------------------------------- /Data/NDT/panorama_label.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chinacui/teethdemo/HEAD/Data/NDT/panorama_label.png -------------------------------------------------------------------------------- /Src/TeethStudio/color.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chinacui/teethdemo/HEAD/Src/TeethStudio/color.bmp -------------------------------------------------------------------------------- /Src/TeethStudio/imface.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /Src/TeethStudio/stripe.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chinacui/teethdemo/HEAD/Src/TeethStudio/stripe.bmp -------------------------------------------------------------------------------- /Src/TeethStudio/stripe2.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chinacui/teethdemo/HEAD/Src/TeethStudio/stripe2.bmp -------------------------------------------------------------------------------- /Src/AlgColle/non_rigid_icp.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chinacui/teethdemo/HEAD/Src/AlgColle/non_rigid_icp.h -------------------------------------------------------------------------------- /Projects/TeethStudio/color.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chinacui/teethdemo/HEAD/Projects/TeethStudio/color.bmp -------------------------------------------------------------------------------- /Projects/TeethStudio/stripe.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chinacui/teethdemo/HEAD/Projects/TeethStudio/stripe.bmp -------------------------------------------------------------------------------- /Projects/TeethStudio/stripe2.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chinacui/teethdemo/HEAD/Projects/TeethStudio/stripe2.bmp -------------------------------------------------------------------------------- /Src/AlgColle/image_base_alg.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chinacui/teethdemo/HEAD/Src/AlgColle/image_base_alg.cpp -------------------------------------------------------------------------------- /Projects/TeethRootRecoAlg/TeethRootRecoAlg.aps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chinacui/teethdemo/HEAD/Projects/TeethRootRecoAlg/TeethRootRecoAlg.aps -------------------------------------------------------------------------------- /Projects/TeethRootRecoAlg/TeethRootRecoAlg.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chinacui/teethdemo/HEAD/Projects/TeethRootRecoAlg/TeethRootRecoAlg.rc -------------------------------------------------------------------------------- /Src/TeethRootRecoAlg/dental_template_fitting.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chinacui/teethdemo/HEAD/Src/TeethRootRecoAlg/dental_template_fitting.cpp -------------------------------------------------------------------------------- /Src/TeethStudio/panoramic_simulation_test_action.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chinacui/teethdemo/HEAD/Src/TeethStudio/panoramic_simulation_test_action.cpp -------------------------------------------------------------------------------- /Src/TeethStudio/depth_renderer.frag: -------------------------------------------------------------------------------- 1 | #version 120 2 | varying vec4 v_pos; 3 | void main() 4 | { 5 | 6 | 7 | gl_FragColor.r=gl_FragCoord.z/gl_FragCoord.w; 8 | 9 | } -------------------------------------------------------------------------------- /Projects/TeethRootRecoAlg/x64/Release/TeethRootRecoAlg.res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chinacui/teethdemo/HEAD/Projects/TeethRootRecoAlg/x64/Release/TeethRootRecoAlg.res -------------------------------------------------------------------------------- /Projects/TeethStudio/depth_renderer.frag: -------------------------------------------------------------------------------- 1 | #version 120 2 | varying vec4 v_pos; 3 | void main() 4 | { 5 | 6 | 7 | gl_FragColor.r=gl_FragCoord.z/gl_FragCoord.w; 8 | 9 | } -------------------------------------------------------------------------------- /Src/AdditionalLibs/XWGeodesic/Parameters.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | const double RateOfNormalShift = 2e-3; 3 | const double AngleTolerance = 8e-3; 4 | const double LengthTolerance = 1.2e-6; -------------------------------------------------------------------------------- /Src/AlgColle/panoramic_alg.cpp: -------------------------------------------------------------------------------- 1 | #include"panoramic_alg.h" 2 | bool CPanoramicAlg::ComputePanoramicImageOfToothMesh(COpenMeshT&tooth_mesh, cv::Mat &res_img) 3 | { 4 | return true; 5 | } -------------------------------------------------------------------------------- /Src/AlgColle/shape_deformation.cpp: -------------------------------------------------------------------------------- 1 | #include"shape_deformation.h" 2 | 3 | CArapShapeDeformation::CArapShapeDeformation(CMeshObject *meshobj) 4 | { 5 | //igl::arap_precomputation() 6 | } -------------------------------------------------------------------------------- /Src/TeethStudio/depth_renderer.vert: -------------------------------------------------------------------------------- 1 | #version 120 2 | varying vec4 v_pos; 3 | void main() { 4 | gl_Position = projectionMatrix *modelViewMatrix*vec4(position,1.0); 5 | v_pos=gl_Position; 6 | 7 | } -------------------------------------------------------------------------------- /Projects/TeethStudio/depth_renderer.vert: -------------------------------------------------------------------------------- 1 | #version 120 2 | varying vec4 v_pos; 3 | void main() { 4 | gl_Position = projectionMatrix *modelViewMatrix*vec4(position,1.0); 5 | v_pos=gl_Position; 6 | 7 | } -------------------------------------------------------------------------------- /Projects/AlgColle/AlgColle.vcxproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Projects/DataColle/DataColle.vcxproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Src/TeethStudio/back_texcoord_render.frag: -------------------------------------------------------------------------------- 1 | #version 120 2 | varying vec3 v_texCoord; 3 | 4 | void main() 5 | { 6 | 7 | gl_FragColor.rgb=v_texCoord; 8 | gl_FragColor.a=gl_FragCoord.z/gl_FragCoord.w; 9 | 10 | } -------------------------------------------------------------------------------- /Src/TeethStudio/front_texcoord_render.frag: -------------------------------------------------------------------------------- 1 | #version 120 2 | varying vec3 v_texCoord; 3 | 4 | void main() 5 | { 6 | 7 | gl_FragColor.rgb=v_texCoord; 8 | gl_FragColor.a=gl_FragCoord.z/gl_FragCoord.w; 9 | 10 | } -------------------------------------------------------------------------------- /Projects/TeethStudio/back_texcoord_render.frag: -------------------------------------------------------------------------------- 1 | #version 120 2 | varying vec3 v_texCoord; 3 | 4 | void main() 5 | { 6 | 7 | gl_FragColor.rgb=v_texCoord; 8 | gl_FragColor.a=gl_FragCoord.z/gl_FragCoord.w; 9 | 10 | } -------------------------------------------------------------------------------- /Projects/TeethStudio/front_texcoord_render.frag: -------------------------------------------------------------------------------- 1 | #version 120 2 | varying vec3 v_texCoord; 3 | 4 | void main() 5 | { 6 | 7 | gl_FragColor.rgb=v_texCoord; 8 | gl_FragColor.a=gl_FragCoord.z/gl_FragCoord.w; 9 | 10 | } -------------------------------------------------------------------------------- /Src/AdditionalLibs/XWGeodesic/ModelWrapper.cpp: -------------------------------------------------------------------------------- 1 | #include"ModelWrapper.h" 2 | 3 | void ModelWrapper::setMesh(std::vector& vertexs, std::vector&faces) 4 | { 5 | m_Verts = vertexs; 6 | m_Faces = faces; 7 | 8 | } -------------------------------------------------------------------------------- /Src/DataColle/custom_itk_type.h: -------------------------------------------------------------------------------- 1 | #ifndef CCUSTOM_ITK_TYPE_H 2 | #define CCUSTOM_ITK_TYPE_H 3 | #include "prereq.h" 4 | #include "itkImage.h" 5 | #include"itkRGBPixel.h" 6 | typedef itk::Image ItkVolumeDataType; 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /Src/TeethStudio/curve_render.frag: -------------------------------------------------------------------------------- 1 | #version 120 2 | 3 | varying vec3 v_color; 4 | 5 | 6 | 7 | void main(void) 8 | { 9 | 10 | 11 | vec4 vcolor=vec4(v_color.x,v_color.y,v_color.z,1.0);; 12 | gl_FragColor = vcolor; 13 | 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Projects/TeethStudio/curve_render.frag: -------------------------------------------------------------------------------- 1 | #version 120 2 | 3 | varying vec3 v_color; 4 | 5 | 6 | 7 | void main(void) 8 | { 9 | 10 | 11 | vec4 vcolor=vec4(v_color.x,v_color.y,v_color.z,1.0);; 12 | gl_FragColor = vcolor; 13 | 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Src/AdditionalLibs/XWGeodesic/ModelWrapper.h: -------------------------------------------------------------------------------- 1 | #ifndef MODEL_WRAPPER_H 2 | #define MODEL_WRAPPER_H 3 | #include"BaseModel.h" 4 | class ModelWrapper:public CBaseModel 5 | { 6 | public: 7 | void setMesh(std::vector& vertexs, std::vector&faces); 8 | }; 9 | #endif -------------------------------------------------------------------------------- /Src/TeethStudio/panoramic_simulation.cpp: -------------------------------------------------------------------------------- 1 | #include "panoramic_simulation.h" 2 | 3 | PanoramicSimulation::PanoramicSimulation(QWidget *parent) 4 | : QWidget(parent) 5 | { 6 | ui.setupUi(this); 7 | } 8 | 9 | PanoramicSimulation::~PanoramicSimulation() 10 | { 11 | 12 | } 13 | -------------------------------------------------------------------------------- /Src/TeethStudio/volumeRender.vert: -------------------------------------------------------------------------------- 1 | #version 120 2 | 3 | attribute highp vec4 a_pos; 4 | varying vec4 v_pos; 5 | 6 | uniform highp mat4 mvp_matrix; 7 | uniform highp mat4 mv_matrix; 8 | 9 | 10 | void main() { 11 | 12 | gl_Position = mvp_matrix*a_pos; 13 | v_pos=gl_Position; 14 | 15 | } -------------------------------------------------------------------------------- /Projects/TeethStudio/volumeRender.vert: -------------------------------------------------------------------------------- 1 | #version 120 2 | 3 | attribute highp vec4 a_pos; 4 | varying vec4 v_pos; 5 | 6 | uniform highp mat4 mvp_matrix; 7 | uniform highp mat4 mv_matrix; 8 | 9 | 10 | void main() { 11 | 12 | gl_Position = mvp_matrix*a_pos; 13 | v_pos=gl_Position; 14 | 15 | } -------------------------------------------------------------------------------- /Src/TeethStudio/main.cpp: -------------------------------------------------------------------------------- 1 | #include "imface_window.h" 2 | #include 3 | #include"ui_context.h" 4 | int main(int argc, char *argv[]) 5 | { 6 | QApplication a(argc, argv); 7 | a.setAttribute(Qt::AA_X11InitThreads); 8 | 9 | CUIContext::Init(); 10 | 11 | return a.exec(); 12 | } 13 | -------------------------------------------------------------------------------- /Src/TeethStudio/curve_render.vert: -------------------------------------------------------------------------------- 1 | #version 120 2 | attribute highp vec4 a_pos; 3 | attribute highp vec3 a_color; 4 | varying vec3 v_color; 5 | 6 | uniform highp mat4 mvp_matrix; 7 | uniform highp mat4 mv_matrix; 8 | 9 | void main(void) 10 | { 11 | 12 | gl_Position = mvp_matrix * a_pos; 13 | v_color=a_color; 14 | } -------------------------------------------------------------------------------- /Projects/TeethStudio/curve_render.vert: -------------------------------------------------------------------------------- 1 | #version 120 2 | attribute highp vec4 a_pos; 3 | attribute highp vec3 a_color; 4 | varying vec3 v_color; 5 | 6 | uniform highp mat4 mvp_matrix; 7 | uniform highp mat4 mv_matrix; 8 | 9 | void main(void) 10 | { 11 | 12 | gl_Position = mvp_matrix * a_pos; 13 | v_color=a_color; 14 | } -------------------------------------------------------------------------------- /Src/DataColle/prereq.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #pragma warning(disable: 4251) 3 | #ifdef DATACOLLE_EXPORTS 4 | #define DATACOLLE_API extern "C" __declspec(dllexport) 5 | #define DATACOLLE_CLASS __declspec(dllexport) 6 | #else 7 | #define DATACOLLE_API extern "C" __declspec(dllimport) 8 | #define DATACOLLE_CLASS __declspec(dllimport) 9 | #endif -------------------------------------------------------------------------------- /Src/TeethStudio/front_texcoord_render.vert: -------------------------------------------------------------------------------- 1 | #version 120 2 | attribute highp vec4 a_pos; 3 | attribute vec3 a_texcoords; 4 | varying vec3 v_texCoord; 5 | 6 | uniform highp mat4 mvp_matrix; 7 | uniform highp mat4 mv_matrix; 8 | void main() { 9 | gl_Position = mvp_matrix*a_pos; 10 | v_texCoord=a_texcoords; 11 | 12 | 13 | } -------------------------------------------------------------------------------- /shortcut key.txt: -------------------------------------------------------------------------------- 1 | Key_V:switch to volume segmentation action 2 | 3 | Key_T:switch to volume CPanoramicSimulationTest action 4 | 5 | Key_H:switch to harmonic action 6 | 7 | Key_P:switch to panoramia registration test action 8 | 9 | Key_K:switch to panoramia registration action 10 | 11 | Key_S;panoramic image registration -------------------------------------------------------------------------------- /Projects/TeethStudio/front_texcoord_render.vert: -------------------------------------------------------------------------------- 1 | #version 120 2 | attribute highp vec4 a_pos; 3 | attribute vec3 a_texcoords; 4 | varying vec3 v_texCoord; 5 | 6 | uniform highp mat4 mvp_matrix; 7 | uniform highp mat4 mv_matrix; 8 | void main() { 9 | gl_Position = mvp_matrix*a_pos; 10 | v_texCoord=a_texcoords; 11 | 12 | 13 | } -------------------------------------------------------------------------------- /Src/AlgColle/prereq.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #pragma warning(disable: 4251) 3 | 4 | #ifdef ALGCOLLE_EXPORTS 5 | #define ALGCOLLE_API extern "C" __declspec(dllexport) 6 | #define ALGCOLLE_CLASS __declspec(dllexport) 7 | #else 8 | #define ALGCOLLE_API extern "C" __declspec(dllimport) 9 | #define ALGCOLLE_CLASS __declspec(dllimport) 10 | #endif -------------------------------------------------------------------------------- /Src/TeethStudio/back_texcoord_render.vert: -------------------------------------------------------------------------------- 1 | #version 120 2 | attribute highp vec4 a_pos; 3 | attribute vec3 a_texcoords; 4 | varying vec3 v_texCoord; 5 | 6 | uniform highp mat4 mvp_matrix; 7 | uniform highp mat4 mv_matrix; 8 | void main() { 9 | gl_Position = mvp_matrix*a_pos; 10 | v_texCoord=a_texcoords; 11 | 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Projects/TeethStudio/back_texcoord_render.vert: -------------------------------------------------------------------------------- 1 | #version 120 2 | attribute highp vec4 a_pos; 3 | attribute vec3 a_texcoords; 4 | varying vec3 v_texCoord; 5 | 6 | uniform highp mat4 mvp_matrix; 7 | uniform highp mat4 mv_matrix; 8 | void main() { 9 | gl_Position = mvp_matrix*a_pos; 10 | v_texCoord=a_texcoords; 11 | 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Projects/TeethStudio/mat.dmat: -------------------------------------------------------------------------------- 1 | 4 4 2 | -0.21101855664691951 3 | 0.97664535413207543 4 | -0.040435392948313664 5 | 0 6 | 0.16505351740393778 7 | -0.0051716854533970817 8 | -0.9862710530387474 9 | -0 10 | -0.96344616099875524 11 | -0.21479549790860336 12 | -0.16010742935590574 13 | 0 14 | -4.353768911564126 15 | 2.9674216261449859 16 | 5.4991831978632568 17 | 1 18 | -------------------------------------------------------------------------------- /Src/AdditionalLibs/prereq.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #pragma warning(disable: 4251) 3 | 4 | #ifdef ADDITIONALLIBS_EXPORTS 5 | #define ADDITIONALLIBS_API extern "C" __declspec(dllexport) 6 | #define ADDITIONALLIBS_CLASS __declspec(dllexport) 7 | #else 8 | #define ADDITIONALLIBS_API extern "C" __declspec(dllimport) 9 | #define ADDITIONALLIBS_CLASS __declspec(dllimport) 10 | #endif -------------------------------------------------------------------------------- /Src/HarmonicSegAlg/prereq.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #pragma warning(disable: 4251) 3 | 4 | #ifdef HARMONICSEGALG_EXPORTS 5 | #define HARMONICSEGALG_API extern "C" __declspec(dllexport) 6 | #define HARMONICSEGALG_CLASS __declspec(dllexport) 7 | #else 8 | #define HARMONICSEGALG_API extern "C" __declspec(dllimport) 9 | #define HARMONICSEGALG_CLASS __declspec(dllimport) 10 | #endif -------------------------------------------------------------------------------- /Src/TeethStudio/hot_key_action.h: -------------------------------------------------------------------------------- 1 | #ifndef CHOT_KEY_ACTION_H 2 | #define CHOT_KEY_ACTION_H 3 | #include"action_base.h" 4 | class CModelViewer; 5 | class CHotKeyAction:public CActionBase 6 | { 7 | 8 | protected: 9 | 10 | void KeyPressEvent(QKeyEvent *e); 11 | void KeyReleaseEvent(QKeyEvent *e); 12 | public: 13 | CHotKeyAction() { type_ = Common; } 14 | }; 15 | #endif -------------------------------------------------------------------------------- /Src/TeethRootRecoAlg/prereq.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #pragma warning(disable: 4251) 3 | 4 | #ifdef TEETHROOTRECOALG_EXPORTS 5 | #define TEETHROOTRECOALG_API extern "C" __declspec(dllexport) 6 | #define TEETHROOTRECOALG_CLASS __declspec(dllexport) 7 | #else 8 | #define TEETHROOTRECOALG_API extern "C" __declspec(dllimport) 9 | #define TEETHROOTRECOALG_CLASS __declspec(dllimport) 10 | #endif -------------------------------------------------------------------------------- /Src/AlgColle/panoramic_alg.h: -------------------------------------------------------------------------------- 1 | #ifndef CPANORAMIC_ALG_H 2 | #define CPANORAMIC_ALG_H 3 | #include"../DataColle/custom_openmesh_type.h" 4 | #include"../DataColle/mesh_object.h" 5 | #include"../DataColle/data_pool.h" 6 | #include 7 | class CPanoramicAlg 8 | { 9 | public: 10 | static bool ComputePanoramicImageOfToothMesh(COpenMeshT&tooth_mesh, cv::Mat &res_img); 11 | }; 12 | #endif -------------------------------------------------------------------------------- /Src/AlgColle/linear_algebra_alg.h: -------------------------------------------------------------------------------- 1 | #ifndef CLINEAR_ALGEBRA_ALG_H 2 | #define CLINEAR_ALGEBRA_ALG_H 3 | #include"prereq.h" 4 | #include 5 | #include 6 | #include 7 | class ClinearAlgebraAlg 8 | { 9 | public: 10 | static Eigen::VectorXd SolveLdlt(const Eigen::SparseMatrix& CoeffMat, const Eigen::VectorXd& right, double pinvtoler); 11 | 12 | }; 13 | #endif -------------------------------------------------------------------------------- /Src/DataColle/geodesic_type.h: -------------------------------------------------------------------------------- 1 | #ifndef CGEODESIC_TYPE_H 2 | #define CGEODESIC_TYPE_H 3 | #include"../AdditionalLibs/XWGeodesic/xw_geodesic_wrapper.h" 4 | #include"custom_openmesh_type.h" 5 | class CGeodesicModel /*:public CRichModel*/ 6 | { 7 | protected: 8 | COpenMeshT *mesh_=NULL; 9 | public: 10 | CGeodesicModel(COpenMeshT *mesh); 11 | void Update(); 12 | ~CGeodesicModel() {} 13 | }; 14 | #endif -------------------------------------------------------------------------------- /Src/AlgColle/rigid_icp.h: -------------------------------------------------------------------------------- 1 | #ifndef CRIGID_ICP_H 2 | #define CRIGID_ICP_H 3 | #include"prereq.h" 4 | #include 5 | #include 6 | #include"../DataColle/mesh_object.h" 7 | class ALGCOLLE_CLASS CRigidIcp 8 | { 9 | protected: 10 | COpenMeshT* src_mesh_, *tgt_mesh_; 11 | public: 12 | CRigidIcp(COpenMeshT* src_mesh); 13 | void FitTarget(COpenMeshT *target_mesh); 14 | }; 15 | 16 | #endif -------------------------------------------------------------------------------- /Src/TeethStudio/visual_utils.h: -------------------------------------------------------------------------------- 1 | #ifndef CVISUAL_UTILS_H 2 | #define CVISUAL_UTILS_H 3 | #include"../DataColle/mesh_object.h" 4 | #include 5 | #include 6 | #include 7 | 8 | class CVisualUtils 9 | { 10 | protected: 11 | 12 | static std::maprand_color_map_; 13 | public: 14 | static OpenMesh::Vec3d GetRandColor(); 15 | static OpenMesh::Vec3d GetRandColorByTag(int id); 16 | }; 17 | #endif -------------------------------------------------------------------------------- /Src/TeethStudio/panoramic_simulation.h: -------------------------------------------------------------------------------- 1 | #ifndef PANORAMIC_SIMULATION_H 2 | #define PANORAMIC_SIMULATION_H 3 | 4 | #include 5 | #include "ui_panoramic_simulation.h" 6 | 7 | class PanoramicSimulation : public QWidget 8 | { 9 | Q_OBJECT 10 | 11 | public: 12 | PanoramicSimulation(QWidget *parent = 0); 13 | ~PanoramicSimulation(); 14 | 15 | private: 16 | Ui::PanoramicSimulation ui; 17 | }; 18 | 19 | #endif // PANORAMIC_SIMULATION_H 20 | -------------------------------------------------------------------------------- /Src/AdditionalLibs/XWGeodesic/Extremity_Point_Utils.h: -------------------------------------------------------------------------------- 1 | #ifndef EXTREMITY_POINT_UTILS_H 2 | #define EXTREMITY_POINT_UTILS_H 3 | #include "Xin_Wang.h" 4 | class ExtremityPointUtils 5 | { 6 | protected: 7 | CRichModel &m_model; 8 | public: 9 | ExtremityPointUtils(CRichModel &model); 10 | double ComputeMeanDistanceAtSourcePoint(int source, double radius); 11 | void ComputeMeanDistances(double radius, std::vector& meanDis, int num_thread = 4); 12 | }; 13 | #endif -------------------------------------------------------------------------------- /Src/AlgColle/shape_deformation.h: -------------------------------------------------------------------------------- 1 | #ifndef CSHAPE_DEFORMATION_H 2 | #define CSHAPE_DEFORMATION_H 3 | #include"prereq.h" 4 | #include 5 | #include 6 | #include 7 | #include"../DataColle/custom_openmesh_type.h" 8 | #include"../DataColle/mesh_object.h" 9 | #include"../DataColle/cgal_igl_converter.h" 10 | class CArapShapeDeformation 11 | { 12 | protected: 13 | public: 14 | CArapShapeDeformation(CMeshObject *meshobj); 15 | }; 16 | #endif -------------------------------------------------------------------------------- /Projects/TeethRootRecoAlg/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by TeethRootRecoAlg.rc 4 | 5 | // Next default values for new objects 6 | // 7 | #ifdef APSTUDIO_INVOKED 8 | #ifndef APSTUDIO_READONLY_SYMBOLS 9 | #define _APS_NEXT_RESOURCE_VALUE 101 10 | #define _APS_NEXT_COMMAND_VALUE 40001 11 | #define _APS_NEXT_CONTROL_VALUE 1001 12 | #define _APS_NEXT_SYMED_VALUE 101 13 | #endif 14 | #endif 15 | -------------------------------------------------------------------------------- /Src/DataColle/obb_type.h: -------------------------------------------------------------------------------- 1 | #include"mesh_object.h" 2 | #ifndef COBB_TYPE_H 3 | #define COBB_TYPE_H 4 | class CPqpObb; 5 | class CObbWrapper 6 | { 7 | public: 8 | CPqpObb*obb_tree_; 9 | std::vectorid_vh_map_; 10 | std::vectorid_fh_map_; 11 | CObbWrapper() 12 | { 13 | obb_tree_ = NULL; 14 | id_vh_map_.clear(); 15 | id_fh_map_.clear(); 16 | } 17 | ~CObbWrapper() 18 | { 19 | if (obb_tree_ != NULL) 20 | { 21 | delete obb_tree_; 22 | } 23 | } 24 | }; 25 | #endif -------------------------------------------------------------------------------- /Src/TeethStudio/mesh_render.vert: -------------------------------------------------------------------------------- 1 | #version 120 2 | attribute highp vec4 a_pos; 3 | attribute highp vec3 a_normal; 4 | attribute highp vec3 a_color; 5 | varying vec3 v_color; 6 | varying vec2 v_texcoords; 7 | attribute vec2 a_texcoords; 8 | uniform highp mat4 mvp_matrix; 9 | uniform highp mat4 mv_matrix; 10 | varying highp vec4 fp; 11 | varying highp vec3 fn; 12 | void main(void) 13 | { 14 | fp = mv_matrix * a_pos; 15 | fn = mat3(mv_matrix)* a_normal; 16 | gl_Position = mvp_matrix * a_pos; 17 | v_texcoords=a_texcoords; 18 | v_color=a_color; 19 | } -------------------------------------------------------------------------------- /Projects/TeethStudio/mesh_render.vert: -------------------------------------------------------------------------------- 1 | #version 120 2 | attribute highp vec4 a_pos; 3 | attribute highp vec3 a_normal; 4 | attribute highp vec3 a_color; 5 | varying vec3 v_color; 6 | varying vec2 v_texcoords; 7 | attribute vec2 a_texcoords; 8 | uniform highp mat4 mvp_matrix; 9 | uniform highp mat4 mv_matrix; 10 | varying highp vec4 fp; 11 | varying highp vec3 fn; 12 | void main(void) 13 | { 14 | fp = mv_matrix * a_pos; 15 | fn = mat3(mv_matrix)* a_normal; 16 | gl_Position = mvp_matrix * a_pos; 17 | v_texcoords=a_texcoords; 18 | v_color=a_color; 19 | } -------------------------------------------------------------------------------- /Src/AdditionalLibs/libicp/libicp_wrapper.h: -------------------------------------------------------------------------------- 1 | #ifndef CLIB_ICP_WRAPPER_H 2 | #define CLIB_ICP_WRAPPER_H 3 | #include"../prereq.h" 4 | #include 5 | 6 | class IcpPointToPoint; 7 | class ADDITIONALLIBS_CLASS CIcpPoint2Point 8 | { 9 | protected: 10 | IcpPointToPoint *icp_p2p_=NULL; 11 | std::vectortarget_pts_, src_pts_; 12 | public: 13 | CIcpPoint2Point(Eigen::MatrixXd target_pts); 14 | void Fit(Eigen::MatrixXd src_pts,Eigen::Matrix3d& res_rot,Eigen::Vector3d& trans); 15 | 16 | ~CIcpPoint2Point(); 17 | 18 | }; 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files 2 | *.slo 3 | *.lo 4 | *.o 5 | *.obj 6 | *.suo 7 | *.idb 8 | *.pdb 9 | *.db 10 | *.exp 11 | *.ipdb 12 | *.opendb 13 | *.iobj 14 | 15 | # Precompiled Headers 16 | *.gch 17 | *.pch 18 | 19 | # Compiled Dynamic libraries 20 | *.so 21 | *.dylib 22 | *.dll 23 | *.log 24 | *.tlog 25 | 26 | # Fortran module files 27 | *.mod 28 | *.smod 29 | /Projects/x64/ 30 | /Projects/TeethStudio/GeneratedFiles/ 31 | 32 | # Compiled Static libraries 33 | *.lai 34 | *.la 35 | *.a 36 | *.lib 37 | moc*.cpp 38 | 39 | # Executables 40 | *.exe 41 | *.out 42 | *.app -------------------------------------------------------------------------------- /Src/DataColle/base_object.h: -------------------------------------------------------------------------------- 1 | // Copyright 2016_9 by ChenNenglun 2 | #ifndef CBASE_OBJECT_H 3 | #define CBASE_OBJECT_H 4 | #include"prereq.h" 5 | #include 6 | #include"custom_openmesh_type.h" 7 | class DATACOLLE_CLASS CBaseObject 8 | { 9 | protected: 10 | Eigen::Matrix4d mat_;//transform and rotate of the local coordinate 11 | public: 12 | CBaseObject(); 13 | ~CBaseObject(); 14 | Eigen::Matrix4d & GetMatrix(); 15 | void SetMatrix(Eigen::Matrix4d &mat); 16 | void Transform(OpenMesh::Vec3d trans); 17 | void Rotate(OpenMesh::Vec3d axis,double angle,OpenMesh::Vec3d center=OpenMesh::Vec3d(0,0,0)); 18 | }; 19 | #endif -------------------------------------------------------------------------------- /Src/DataColle/geo_primit.cpp: -------------------------------------------------------------------------------- 1 | #include"geo_primit.h" 2 | 3 | CPlane::CPlane(OpenMesh::Vec3d p, OpenMesh::Vec3d dir) 4 | { 5 | p_ = p; 6 | dir_ = dir; 7 | dir_.normalize(); 8 | ComputePlaneParamFromMeanAndDir(); 9 | } 10 | void CPlane::ComputePlaneParamFromMeanAndDir() 11 | { 12 | a_ = p_[0]; 13 | b_ = p_[1]; 14 | c_ = p_[2]; 15 | d_ = -dir_[0]*p_[0] - dir_[1]*p_[1] - dir_[2]*p_[2]; 16 | 17 | } 18 | void CPlane::SetP(OpenMesh::Vec3d p) 19 | { 20 | p_ = p; 21 | ComputePlaneParamFromMeanAndDir(); 22 | } 23 | void CPlane::SetDir(OpenMesh::Vec3d dir) 24 | { 25 | dir_ = dir; 26 | dir_=dir_.normalize(); 27 | ComputePlaneParamFromMeanAndDir(); 28 | } -------------------------------------------------------------------------------- /Src/DataColle/aux_geo_utils.h: -------------------------------------------------------------------------------- 1 | #ifndef AUX_GEO_H 2 | #define AUX_GEO_H 3 | #include"prereq.h" 4 | #include 5 | #include"custom_openmesh_type.h" 6 | class DATACOLLE_CLASS CAuxGeoUtils 7 | { 8 | public: 9 | static void GetPlainMeshFromPointAndAxis(OpenMesh::Vec3d p, OpenMesh::Vec3d axis_a, OpenMesh::Vec3d axis_b, OpenMesh::Vec3d axis_dir, double scale, COpenMeshT &mesh); 10 | static void GenVolumeRenderAuxCubeAndCuttingPlane(double x_len, double y_len, double z_len,OpenMesh::Vec3d view_point,OpenMesh::Vec3d view_dir, OpenMesh::Vec3d view_up_dir, OpenMesh::Vec3d view_right_dir, COpenMeshT& res_cube,COpenMeshT& res_plane); 11 | 12 | }; 13 | #endif -------------------------------------------------------------------------------- /Src/TeethStudio/camera.h: -------------------------------------------------------------------------------- 1 | // Copyright 2016_9 by ChenNenglun 2 | #ifndef CCAMERA_H 3 | #define CCAMERA_H 4 | #include"QGLViewer/camera.h" 5 | #include 6 | #include"../DataColle/mesh_object.h" 7 | class CCamera :public qglviewer::Camera 8 | { 9 | private: 10 | CCamera(const qglviewer::Camera &b) { qglviewer::Camera::Camera(b); }; 11 | public: 12 | CCamera(); 13 | CCamera(const CCamera& c); 14 | CCamera & CCamera::operator=(const CCamera &b); 15 | void ConvertClickToLine(QPoint p, OpenMesh::Vec3d &orig, OpenMesh::Vec3d &dir); 16 | qreal zNear() const { return 0.001; }; 17 | qreal zFar() const { return 100.0; }; 18 | 19 | 20 | }; 21 | 22 | #endif -------------------------------------------------------------------------------- /Src/TeethStudio/edit_feature_edge_action.h: -------------------------------------------------------------------------------- 1 | #ifndef EDIT_FEATURE_EDGE_TOOL_H 2 | #define EDIT_FEATURE_EDGE_TOOL_H 3 | #include"action_base.h" 4 | #include "../DataColle/custom_openmesh_type.h" 5 | class CEditFeatureEdgeAction:public CActionBase 6 | { 7 | protected: 8 | std::vectorpicked_vhs_; 9 | bool is_pick_ = false; 10 | protected: 11 | 12 | void MousePressEvent(QMouseEvent *e); 13 | void MouseMoveEvent(QMouseEvent *e); 14 | void MouseReleaseEvent(QMouseEvent *e); 15 | void KeyPressEvent(QKeyEvent *e); 16 | void KeyReleaseEvent(QKeyEvent *e); 17 | public: 18 | CEditFeatureEdgeAction() { type_ = EditFeatureEdge; } 19 | }; 20 | #endif -------------------------------------------------------------------------------- /Src/TeethStudio/panoramic_simulation.ui: -------------------------------------------------------------------------------- 1 | 2 | PanoramicSimulation 3 | 4 | 5 | PanoramicSimulation 6 | 7 | 8 | 9 | 0 10 | 0 11 | 400 12 | 300 13 | 14 | 15 | 16 | PanoramicSimulation 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /Projects/TeethStudio/TeethStudio.vcxproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | C:\Qt\Qt5.7.1\5.7\msvc2015_64 6 | PATH=$(QTDIR)\bin%3b$(PATH) 7 | 8 | 9 | C:\Qt\Qt5.7.1\5.7\msvc2015_64 10 | PATH=$(QTDIR)\bin%3b$(PATH) 11 | 12 | -------------------------------------------------------------------------------- /Src/AlgColle/linear_algebra_alg.cpp: -------------------------------------------------------------------------------- 1 | #include"linear_algebra_alg.h" 2 | 3 | 4 | 5 | Eigen::VectorXd ClinearAlgebraAlg::SolveLdlt(const Eigen::SparseMatrix& CoeffMat, const Eigen::VectorXd& right, double pinvtoler) 6 | { 7 | Eigen::SimplicialLDLT> ldlt(CoeffMat); 8 | Eigen::VectorXd X_0 = ldlt.permutationP() * right; 9 | Eigen::VectorXd X_1 = ldlt.matrixL().solve(X_0); 10 | Eigen::VectorXd X_2(ldlt.vectorD().size()); 11 | X_2.setZero(); 12 | for (int i = 0; i < ldlt.vectorD().size(); ++i) 13 | if (abs(ldlt.vectorD()(i)) > pinvtoler) 14 | X_2[i] = X_1[i] / ldlt.vectorD()(i); 15 | Eigen::VectorXd X_3 = ldlt.matrixU().solve(X_2); 16 | return ldlt.permutationPinv() * X_3; 17 | } -------------------------------------------------------------------------------- /Src/TeethStudio/camera.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2016_9 by ChenNenglun 2 | #include"camera.h" 3 | #include"QGLViewer/quaternion.h" 4 | #include"qquaternion.h" 5 | #include"qvector3d.h" 6 | CCamera::CCamera() :Camera() 7 | { 8 | 9 | } 10 | 11 | 12 | CCamera::CCamera(const CCamera& c) :Camera(c) 13 | { 14 | 15 | 16 | } 17 | 18 | CCamera & CCamera::operator=(const CCamera &b) 19 | { 20 | 21 | *((Camera*)this) = (Camera)b; 22 | 23 | return *this; 24 | } 25 | void CCamera::ConvertClickToLine(QPoint p, OpenMesh::Vec3d &orig, OpenMesh::Vec3d &dir) 26 | { 27 | qglviewer::Vec torig, tdir; 28 | convertClickToLine(p, torig, tdir); 29 | orig = OpenMesh::Vec3d(torig.x, torig.y, torig.z); 30 | dir = OpenMesh::Vec3d(tdir.x, tdir.y, tdir.z); 31 | } 32 | -------------------------------------------------------------------------------- /Src/TeethStudio/manipulation_action.h: -------------------------------------------------------------------------------- 1 | #ifndef MANIPULATION_ACTION_H 2 | #define MANIPULATION_ACTION_H 3 | #include"action_base.h" 4 | #include "../DataColle/custom_openmesh_type.h" 5 | class CManipulationAction : public CActionBase 6 | { 7 | protected: 8 | std::vectorsel_mesh_ids_; 9 | bool is_moving_mesh_ = false; 10 | OpenMesh::Vec3d pre_move_pos_; 11 | OpenMesh::Vec3d sel_mesh_center_; 12 | protected: 13 | 14 | void MousePressEvent(QMouseEvent *e); 15 | void MouseMoveEvent(QMouseEvent *e); 16 | void MouseReleaseEvent(QMouseEvent *e); 17 | void KeyPressEvent(QKeyEvent *e); 18 | void KeyReleaseEvent(QKeyEvent *e); 19 | void WheelEvent(QWheelEvent *); 20 | public: 21 | CManipulationAction() { type_ = Common; } 22 | }; 23 | #endif -------------------------------------------------------------------------------- /Src/TeethStudio/texture_wrapper.h: -------------------------------------------------------------------------------- 1 | #ifndef CTEXTURE_WRAPPER_H 2 | #define CTEXTURE_WRAPPER_H 3 | #include 4 | #include 5 | class TextureWraper :public QOpenGLFunctions_2_1 6 | { 7 | QImage img_; 8 | QOpenGLTexture* texture_ = NULL; 9 | bool is_updated_ = false; 10 | int texture_id_ = 0; 11 | static int max_texture_id_; 12 | public: 13 | 14 | QImage & GetImage() { return img_; }; 15 | QOpenGLTexture *GetTexture() { return texture_; }; 16 | void ReleaseTexture(); 17 | TextureWraper(QImage &img) :img_(img) { is_updated_ = false; texture_id_ = max_texture_id_++; }; 18 | void SetImage(QImage* img); 19 | void UpdateTexture(); 20 | int GetTextureId(); 21 | bool IsUpdated() { return is_updated_; } 22 | }; 23 | #endif 24 | -------------------------------------------------------------------------------- /Src/TeethStudio/volume_data_segmentation_action.h: -------------------------------------------------------------------------------- 1 | #ifndef CVOLUME_DATA_SEGMENTATION_ACTION_H 2 | #define CVOLUME_DATA_SEGMENTATION_ACTION_H 3 | #include"action_base.h" 4 | #include "../DataColle/custom_openmesh_type.h" 5 | #include"../DataColle/mesh_object.h" 6 | #include"../DataColle/curve_object.h" 7 | #include"../DataColle/volume_data_object.h" 8 | class CVolumeDataSegmentationAction :public CActionBase 9 | { 10 | protected: 11 | 12 | protected: 13 | void Init(); 14 | void MousePressEvent(QMouseEvent *e); 15 | void MouseMoveEvent(QMouseEvent *e); 16 | void MouseReleaseEvent(QMouseEvent *e); 17 | void KeyPressEvent(QKeyEvent *e); 18 | void KeyReleaseEvent(QKeyEvent *e); 19 | 20 | 21 | public: 22 | CVolumeDataSegmentationAction(); 23 | }; 24 | 25 | #endif -------------------------------------------------------------------------------- /Src/TeethStudio/visual_utils.cpp: -------------------------------------------------------------------------------- 1 | #include"visual_utils.h" 2 | std::mapCVisualUtils::rand_color_map_; 3 | OpenMesh::Vec3d CVisualUtils::GetRandColor() 4 | { 5 | static bool flag = true; 6 | if (flag) 7 | { 8 | srand((unsigned)time(NULL)); 9 | } 10 | flag = false; 11 | double r = (rand() % 10000) / 11000.0; 12 | double g = (rand() % 10000) / 11000.0; 13 | double b = (rand() % 10000) / 11000.0; 14 | OpenMesh::Vec3d color(r, g, b); 15 | return color; 16 | } 17 | 18 | OpenMesh::Vec3d CVisualUtils::GetRandColorByTag(int id) 19 | { 20 | /*if (id != -1) 21 | std::cerr << id << std::endl;*/ 22 | if (rand_color_map_.find(id)==rand_color_map_.end()) 23 | { 24 | 25 | OpenMesh::Vec3d color= GetRandColor(); 26 | rand_color_map_[id] = color; 27 | } 28 | return rand_color_map_[id]; 29 | } -------------------------------------------------------------------------------- /Src/DataColle/geo_primit.h: -------------------------------------------------------------------------------- 1 | #ifndef GEO_PRIMIT_H 2 | #define GEO_PRIMIT_H 3 | #include"prereq.h" 4 | #include"base_object.h" 5 | #include 6 | #include"custom_openmesh_type.h" 7 | class DATACOLLE_CLASS CPlane:public CBaseObject 8 | { 9 | protected: 10 | double a_; 11 | double b_; 12 | double c_; 13 | double d_; 14 | OpenMesh::Vec3d p_; 15 | OpenMesh::Vec3d dir_; 16 | protected: 17 | void ComputePlaneParamFromMeanAndDir(); 18 | public: 19 | 20 | CPlane(OpenMesh::Vec3d p, OpenMesh::Vec3d dir); 21 | CPlane() {}; 22 | double a() { return a_; } 23 | double b() { return b_; } 24 | double c() { return c_; } 25 | double d() { return d_; } 26 | OpenMesh::Vec3d p() { return p_; } 27 | OpenMesh::Vec3d dir() { return dir_; } 28 | void SetP(OpenMesh::Vec3d p); 29 | void SetDir(OpenMesh::Vec3d dir); 30 | }; 31 | #endif -------------------------------------------------------------------------------- /Src/AlgColle/image_base_alg.h: -------------------------------------------------------------------------------- 1 | #ifndef CIMAGE_BASE_ALG_H 2 | #define CIMAGE_BASE_ALG_H 3 | #include"prereq.h" 4 | #include"../DataColle/custom_openmesh_type.h" 5 | #include 6 | class ALGCOLLE_CLASS CImageBaseAlg 7 | { 8 | public: 9 | static void Curve2dToGrayImage(std::vector&curve,int dim_lens0,int dim_len01,unsigned char background_color, unsigned char foreground_color, cv::Mat &res_gray_image);//dim_lens0 :width,dim_lens1 :height 10 | static void MorphSkeleton(cv::Mat& img);//morph skeleton of the uchar binary image with black background 11 | static void ShortestDis(cv::Mat &img, cv::Point src, std::vector dst, std::vector&dis);//img must CV_8UC1, and color of dst,src as well as path must be the same 12 | static void GetExtremePoints(cv::Mat&img, uchar fore_color, std::vector&res_points); 13 | }; 14 | #endif -------------------------------------------------------------------------------- /Src/AlgColle/cgal_arap_deform.h: -------------------------------------------------------------------------------- 1 | #ifndef CGAL_ARAP_DEFORM_H 2 | #define CGAL_ARAP_DEFORM_H 3 | #include"prereq.h" 4 | #include 5 | #include "../DataColle/Polyhedron_type.h" 6 | class CgalArapDeform 7 | { 8 | public: 9 | //CARAPDeformation() : CMeshDeformation() {} 10 | CgalArapDeform(Polyhedron& mesh); 11 | virtual ~CgalArapDeform(); 12 | bool SetRoiVertices();//Set all of vertices on polyhedron as ROI 13 | bool SetRoiVertices(const std::vector& vertices_handle_vec);//Set specified vertices as ROI 14 | bool SetDeformMap(std::map& deform_handle_map); 15 | 16 | 17 | bool Deform(); 18 | private: 19 | typedef CGAL::Surface_mesh_deformation Surface_mesh_deformation; 20 | Surface_mesh_deformation* p_deform_mesh_; 21 | Polyhedron& mesh_; 22 | }; 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /Src/TeethStudio/scene.h: -------------------------------------------------------------------------------- 1 | // Copyright 2016_9 by ChenNenglun 2 | #ifndef SCENE_H 3 | #define SCENE_H 4 | #include 5 | #include 6 | #include"scene_mesh_object.h" 7 | #include"scene_curve_object.h" 8 | #include"scene_volume_object.h" 9 | #include"../DataColle/data_pool.h" 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include"camera.h" 15 | class CScene 16 | { 17 | protected: 18 | std::map scene_mesh_;//mesh object in scene 19 | std::mapscene_curve_; 20 | std::mapscene_volumedata_; 21 | void UpdateScene();//called each frame, check and update the scene when datapool is updated 22 | public: 23 | CScene(); 24 | ~CScene(); 25 | 26 | 27 | 28 | void Render( CCamera camera);//render the scene 29 | }; 30 | #endif 31 | -------------------------------------------------------------------------------- /Src/TeethStudio/action_manager.h: -------------------------------------------------------------------------------- 1 | #ifndef CACTION_MANAGER_H 2 | #define CACTION_MANAGER_H 3 | #include 4 | #include"action_base.h" 5 | class CActionManager 6 | { 7 | protected: 8 | 9 | std::vectoractions_; 10 | 11 | CActionType current_action_type_ = Common; 12 | CModelViewer* viewer_=NULL; 13 | 14 | 15 | 16 | public: 17 | 18 | virtual void MousePressEvent(QMouseEvent *e); 19 | virtual void MouseMoveEvent(QMouseEvent *e); 20 | virtual void MouseReleaseEvent(QMouseEvent *e); 21 | virtual void KeyPressEvent(QKeyEvent *e); 22 | virtual void KeyReleaseEvent(QKeyEvent *e); 23 | virtual void WheelEvent(QWheelEvent *); 24 | 25 | virtual void MouseDoubleClickEvent(QMouseEvent * e); 26 | 27 | CActionType GetCurrentActionType() { return current_action_type_; } 28 | void SetCurrentActionType(CActionType t); 29 | void Init(CModelViewer* viewer); 30 | CActionManager() {}; 31 | 32 | 33 | 34 | }; 35 | #endif -------------------------------------------------------------------------------- /Src/DataColle/data_io.h: -------------------------------------------------------------------------------- 1 | // Copyright 2016_9 by ChenNenglun 2 | #ifndef DATA_IO_H 3 | #define DATA_IO_H 4 | #include"prereq.h" 5 | #include 6 | #include 7 | #include"mesh_object.h" 8 | #include"volume_data_object.h" 9 | class DATACOLLE_CLASS CDataIO 10 | { 11 | protected: 12 | 13 | public: 14 | 15 | static bool LoadCurveFromObj(std::string fname, std::vector &curve); 16 | static void SaveCurveToObj(std::string fname, std::vector&curve); 17 | static bool ReadMesh(std::string fname, CMeshObject & res_mesh_obj, OpenMesh::IO::Options io_options= OpenMesh::IO::Options::Default); 18 | static bool WriteMesh(std::string fname, CMeshObject & res_mesh_obj); 19 | static ItkVolumeDataType::Pointer ReadVolumeDataFromDICOMSeries(std::string dirname);//return null if failed 20 | static bool ReadVolumeDataObjFromDICOMSeries(std::string dirname, CVolumeDataObject& volume_data_obj); 21 | }; 22 | #endif 23 | -------------------------------------------------------------------------------- /Src/DataColle/curve_object.h: -------------------------------------------------------------------------------- 1 | #ifndef CCURVE_OBJECT_H 2 | #define CCURVE_OBJECT_H 3 | #include"prereq.h" 4 | #include"base_object.h" 5 | #include"custom_openmesh_type.h" 6 | class DATACOLLE_CLASS CCurveObject :public CBaseObject 7 | { 8 | public: 9 | enum CurveType { Default, Dots }; 10 | protected: 11 | std::vectorcurve_; 12 | int curve_id_; 13 | bool is_changed_; 14 | OpenMesh::Vec3d color_; 15 | CurveType render_type_; 16 | public: 17 | int GetId();//get id of curve object 18 | void SetId(int id);//set id of curve object 19 | bool IsChanged(); 20 | void SetChanged(bool is_changed = true); 21 | std::vector&GetCurve(); 22 | void SetCurve(std::vector& curve); 23 | OpenMesh::Vec3d GetColor(); 24 | void SetColor(OpenMesh::Vec3d color); 25 | CurveType& RendereType() { return render_type_; } 26 | CCurveObject(); 27 | CCurveObject(CCurveObject&b); 28 | ~CCurveObject(); 29 | 30 | }; 31 | #endif -------------------------------------------------------------------------------- /Src/DataColle/volume_data_object.h: -------------------------------------------------------------------------------- 1 | #ifndef CVOLUME_DATA_OBJECT_H 2 | #define CVOLUME_DATA_OBJECT_H 3 | #include"prereq.h" 4 | #include"base_object.h" 5 | #include 6 | #include 7 | #include"custom_openmesh_type.h" 8 | #include"custom_itk_type.h" 9 | 10 | class DATACOLLE_CLASS CVolumeDataObject:public CBaseObject 11 | { 12 | protected: 13 | int id_; 14 | bool is_changed_; 15 | 16 | ItkVolumeDataType::Pointer volume_data_; 17 | 18 | //test 19 | void GenTestData(); 20 | public: 21 | int data_width_, data_height_, data_depth_; 22 | std::vectorvdata_; 23 | CVolumeDataObject(); 24 | ~CVolumeDataObject(); 25 | 26 | void SetChanged(bool is_changed=true); 27 | bool IsChanged() { return is_changed_; } 28 | int GetId(); 29 | void SetId(int id); 30 | 31 | OpenMesh::Vec3d GetDataSize(); 32 | 33 | ItkVolumeDataType::Pointer GetVolumeData(); 34 | void SetVolumeData(ItkVolumeDataType::Pointer pdata); 35 | 36 | 37 | 38 | }; 39 | #endif -------------------------------------------------------------------------------- /Src/TeethStudio/texture_wrapper.cpp: -------------------------------------------------------------------------------- 1 | #include"texture_wrapper.h" 2 | int TextureWraper::max_texture_id_ = 0; 3 | void TextureWraper::UpdateTexture() 4 | { 5 | //if (texture_ != NULL) 6 | // texture_->release(); 7 | //else 8 | if (texture_ == NULL) 9 | texture_ = new QOpenGLTexture(QOpenGLTexture::Target::Target2D); 10 | /*texture_->setda 11 | texture_->destroy();*/ 12 | texture_->setData(img_.mirrored()); 13 | //texture_->setWrapMode(QOpenGLTexture::WrapMode::ClampToEdge); 14 | 15 | is_updated_ = true; 16 | } 17 | void TextureWraper::SetImage(QImage* img) 18 | { 19 | img_ = *img; 20 | // if (texture_ != NULL) 21 | //texture_->release(); 22 | //delete texture_; 23 | //texture_ = NULL; 24 | is_updated_ = false; 25 | }; 26 | 27 | 28 | int TextureWraper::GetTextureId() 29 | { 30 | return texture_id_; 31 | } 32 | void TextureWraper::ReleaseTexture() 33 | { 34 | if (texture_ != NULL) 35 | texture_->release(); 36 | delete texture_; 37 | texture_ = NULL; 38 | } -------------------------------------------------------------------------------- /Src/AdditionalLibs/XWGeodesic/xw_geodesic_wrapper.h: -------------------------------------------------------------------------------- 1 | #ifndef CXW_GEODESIC_WRAPPER_H 2 | #define CXW_GEODESIC_WRAPPER_H 3 | #include 4 | #include 5 | #include"BaseModel.h" 6 | 7 | class CRichModel; 8 | class CGeoFacePoint 9 | { 10 | public: 11 | int fid_; 12 | double ls_[3]; 13 | double pos_[3]; 14 | int vids_[3]; 15 | }; 16 | class ADDITIONALLIBS_CLASS CXWGeodesic 17 | { 18 | protected: 19 | CRichModel* model_=NULL; 20 | 21 | public: 22 | CXWGeodesic() { } 23 | void SetModel(std::vector& vertexs, std::vector&faces); 24 | void GeodesicDis(int svid, std::vector&tvids, std::vector&dis); 25 | void GeodesicDis(std::vector&svids, std::vector&dis); 26 | void GeodesicPath(int svid, int tvid, std::vector&path); 27 | void GeodesicPath(int svid, std::vector&tvids, std::vector&path); 28 | void GeodesicPath(std::vector&svids, std::vector&tvids, std::vector>&path); 29 | ~CXWGeodesic(); 30 | 31 | }; 32 | #endif -------------------------------------------------------------------------------- /Src/DataColle/teeth_template_object.h: -------------------------------------------------------------------------------- 1 | #ifndef CTEETH_TEMPLATE_OBJECT_H 2 | #define CTEETH_TEMPLATE_OBJECT_H 3 | #include"mesh_object.h" 4 | class DATACOLLE_CLASS CTeethTemplateObject :public CMeshObject 5 | { 6 | 7 | public: 8 | CTeethTemplateObject(); 9 | CTeethTemplateObject(CTeethTemplateObject & template_object); 10 | void ComputeCrownMesh(); 11 | COpenMeshT& GetCrownMesh(); 12 | std::map &GetCrown2TempVhsMap(); 13 | OpenMesh::Vec3d & UpDir() { return updir_; } 14 | OpenMesh::Vec3d & FrontDir() { return front_dir_; } 15 | void SetType(std::string type) { type_ = type; } 16 | std::string GetType() { return type_; } 17 | std::vector&CrownFhs() { return crown_fhs_; } 18 | 19 | void SetChanged(bool flag = true); 20 | protected: 21 | std::vectorcrown_fhs_; 22 | OpenMesh::Vec3d updir_, front_dir_; 23 | std::string type_; 24 | 25 | COpenMeshT crown_; 26 | std::map crown2tempvhs_map_; 27 | 28 | }; 29 | #endif -------------------------------------------------------------------------------- /Src/DataColle/geodesic_type.cpp: -------------------------------------------------------------------------------- 1 | #include "geodesic_type.h" 2 | void CGeodesicModel::Update() 3 | { 4 | /*this->m_Verts.resize(mesh_->n_vertices()); 5 | this->m_Faces.resize(mesh_->n_faces()); 6 | for (auto viter = mesh_->vertices_begin(); viter != mesh_->vertices_end(); viter++) 7 | { 8 | m_Verts[viter->idx()] = CPoint3D(mesh_->point(viter)[0], mesh_->point(viter)[1], mesh_->point(viter)[2]); 9 | } 10 | for (auto fiter = mesh_->faces_begin(); fiter != mesh_->faces_end(); fiter++) 11 | { 12 | std::vector fs; 13 | fs.clear(); 14 | COpenMeshT::FaceHalfedgeIter fhi = mesh_->fh_begin(*fiter), fhend = mesh_->fh_end(*fiter); 15 | 16 | while (fhi != fhend) 17 | { 18 | int vid = mesh_->to_vertex_handle(*fhi).idx(); 19 | fs.push_back(vid); 20 | 21 | fhi++; 22 | } 23 | if (fs.size() != 3) 24 | { 25 | std::cerr << "error : num of face vertexs must be 3" << std::endl; 26 | return; 27 | } 28 | m_Faces[fiter->idx()] = CBaseModel::CFace(fs[0], fs[1], fs[2]); 29 | }*/ 30 | 31 | ///// 32 | 33 | } 34 | CGeodesicModel::CGeodesicModel(COpenMeshT *mesh) 35 | { 36 | mesh_ = mesh; 37 | 38 | } -------------------------------------------------------------------------------- /Src/AdditionalLibs/XWGeodesic/ComputeGeodesics.cpp: -------------------------------------------------------------------------------- 1 | #include "Xin_Wang.h" 2 | #include"Extremity_Point_Utils.h" 3 | 4 | int main(int argc, char* argv[]) 5 | { 6 | CRichModel model("camel.obj"); 7 | model.LoadModel(); 8 | //example: compute the geodesic distance for a single source 9 | std::vector meanDis; 10 | ExtremityPointUtils alg(model); 11 | alg.ComputeMeanDistances(0.2, meanDis); 12 | model.SaveScalarFieldObjFile(meanDis, "camel_meanDis.obj"); 13 | getchar(); 14 | //see more examples: 15 | //CXin_Wang(const CRichModel& model, int source); 16 | //CXin_Wang(const CRichModel& model, int source, int destination); 17 | //CXin_Wang(const CRichModel& model, int source, double R); 18 | //CXin_Wang(const CRichModel& model, const map& sources); 19 | //CXin_Wang(const CRichModel& model, const map& sources, const set &destinations); 20 | //CXin_Wang(const CRichModel& model, const set& sources); 21 | //CXin_Wang(const CRichModel& model, const set& sources, double R); 22 | //CXin_Wang(const CRichModel& model, const set& sources, const set& destinations); 23 | } 24 | 25 | -------------------------------------------------------------------------------- /Src/DataColle/curve_object.cpp: -------------------------------------------------------------------------------- 1 | #include"curve_object.h" 2 | int CCurveObject::GetId() 3 | { 4 | return curve_id_; 5 | } 6 | void CCurveObject::SetId(int id) 7 | { 8 | curve_id_ = id; 9 | } 10 | bool CCurveObject::IsChanged() 11 | { 12 | return is_changed_; 13 | } 14 | void CCurveObject::SetChanged(bool is_changed) 15 | { 16 | is_changed_ = is_changed; 17 | } 18 | void CCurveObject::SetCurve(std::vector&curve) 19 | { 20 | curve_ = curve; 21 | } 22 | std::vector& CCurveObject::GetCurve() 23 | { 24 | return curve_; 25 | } 26 | 27 | CCurveObject::CCurveObject() 28 | { 29 | curve_id_ = -1; 30 | color_ = OpenMesh::Vec3d(0, 0, 0); 31 | render_type_ = Default; 32 | is_changed_ = true; 33 | } 34 | CCurveObject::CCurveObject(CCurveObject&b) 35 | { 36 | curve_id_ = b.curve_id_; 37 | curve_ = b.curve_; 38 | is_changed_ = true; 39 | color_ = b.color_; 40 | render_type_ = b.render_type_; 41 | } 42 | OpenMesh::Vec3d CCurveObject::GetColor() 43 | { 44 | return color_; 45 | } 46 | void CCurveObject::SetColor(OpenMesh::Vec3d color) 47 | { 48 | color_ = color; 49 | } 50 | CCurveObject::~CCurveObject() 51 | { 52 | 53 | } -------------------------------------------------------------------------------- /Src/AdditionalLibs/XWGeodesic/ICH_WindowFiltering.h: -------------------------------------------------------------------------------- 1 | // ImprovedCHWithEdgeValve.h: interface for the CICH_WindowFiltering class. 2 | // 3 | ////////////////////////////////////////////////////////////////////// 4 | #pragma once 5 | 6 | #include "Chen_Han.h" 7 | class CICH_WindowFiltering : public CChen_Han 8 | { 9 | protected: 10 | virtual bool CheckValidityWithXinWangFiltering(Window& w) const; 11 | virtual void AddIntoQueueOfWindows(QuoteWindow& quoteW); 12 | public: 13 | CICH_WindowFiltering(const CRichModel& model, int source); 14 | CICH_WindowFiltering(const CRichModel& model, int source, int destination); 15 | CICH_WindowFiltering(const CRichModel& model, int source, double R); 16 | CICH_WindowFiltering(const CRichModel& model, const map& sources); 17 | CICH_WindowFiltering(const CRichModel& model, const map& sources, const set &destinations); 18 | CICH_WindowFiltering(const CRichModel& model, const set& sources); 19 | CICH_WindowFiltering(const CRichModel& model, const set& sources, double R); 20 | CICH_WindowFiltering(const CRichModel& model, const set& sources, const set& destinations); 21 | }; 22 | -------------------------------------------------------------------------------- /Src/TeethStudio/teeth_reconstruction_action.h: -------------------------------------------------------------------------------- 1 | #ifndef CTEETH_RECONSTRUCTION_ACTION_H 2 | #define CTEETH_RECONSTRUCTION_ACTION_H 3 | #include"action_base.h" 4 | #include 5 | #include"../DataColle/mesh_object.h" 6 | #include"../AlgColle/arap_deform.h" 7 | #include"../DataColle/teeth_template_object.h" 8 | #include"../AlgColle/arap_deform.h" 9 | #include"../AlgColle/non_rigid_icp.h" 10 | class CTeethReconstructionAction :public CActionBase 11 | { 12 | protected: 13 | std::vectorcrown_ids_; 14 | std::maptemplate_meshes_; 15 | std::mapcrown2temptype_map_; 16 | std::mapcrown_temp_map_; 17 | std::map crown_temp_arap_ ; 18 | std::map non_rigid_icp_ ; 19 | std::mapis_temp_matching_finished_; 20 | 21 | bool is_selecting_teeth_ = false; 22 | std::setsel_teeth_ids_; 23 | void Init(); 24 | void MousePressEvent(QMouseEvent *e); 25 | void MouseMoveEvent(QMouseEvent *e); 26 | void MouseReleaseEvent(QMouseEvent *e); 27 | void KeyPressEvent(QKeyEvent *e); 28 | void KeyReleaseEvent(QKeyEvent *e); 29 | void QuitAction(); 30 | public: 31 | CTeethReconstructionAction(); 32 | 33 | }; 34 | 35 | #endif -------------------------------------------------------------------------------- /Src/AdditionalLibs/obb/cpqp_obb_wrapper.h: -------------------------------------------------------------------------------- 1 | #ifndef CPQP_OBB_WRAPPER 2 | #define CPQP_OBB_WRAPPER 3 | 4 | 5 | 6 | #include 7 | #include"../prereq.h" 8 | #include "PQP.h" 9 | #include 10 | class ADDITIONALLIBS_CLASS CPqpObb 11 | { 12 | protected: 13 | Eigen::MatrixXd V_; 14 | Eigen::MatrixXi F_; 15 | PQP_Model m_pqp_model; 16 | 17 | public: 18 | struct QueryResult 19 | { 20 | int fid_; 21 | double distance; 22 | Eigen::Vector3d closest_pnt_; 23 | QueryResult(){} 24 | QueryResult(int fid, double distance, const Eigen::Vector3d closest_pnt) 25 | : fid_(fid), distance(distance), closest_pnt_(closest_pnt) 26 | { 27 | } 28 | bool operator<(const QueryResult& other) const 29 | { 30 | if (distance < other.distance) 31 | return true; 32 | if (distance > other.distance) 33 | return false; 34 | if (fid_ < other.fid_) 35 | return true; 36 | if (fid_ > other.fid_) 37 | return false; 38 | return false; 39 | } 40 | }; 41 | public: 42 | CPqpObb(Eigen::MatrixXd& V, Eigen::MatrixXi& F); 43 | 44 | QueryResult QueryClosestPoint(const Eigen::Vector3d& pt); 45 | std::vector QueryRay(const Eigen::Vector3d& pt, const Eigen::Vector3d& dir); 46 | }; 47 | #endif 48 | 49 | -------------------------------------------------------------------------------- /Src/TeethStudio/ui_context.h: -------------------------------------------------------------------------------- 1 | // Copyright 2016_9 by ChenNenglun 2 | #ifndef UI_CONTEXT_H 3 | #define UI_CONTEXT_H 4 | #include"../AlgColle/morph_skel_dental_mesh_seg.h" 5 | class CScene; 6 | class CMainWindow; 7 | class TextureWraper; 8 | class QImage; 9 | class CUIContext 10 | { 11 | protected: 12 | static CScene* scene_; 13 | static CMainWindow* main_window_; 14 | static int selected_mesh_object_id_; 15 | static int color_stripe_texture_id_; 16 | static int color_bar_texture_id_; 17 | public: 18 | static CMainWindow* GetMainWindow() { return main_window_; } 19 | static CScene* GetScene(); 20 | static void Init(); 21 | static int GetSelectedMeshObjectId(); 22 | static void SetSelectedMeshObjectId(int id); 23 | static int &ColorStripeTextureId() { return color_stripe_texture_id_; } 24 | static int &ColorBarTextureId() { return color_bar_texture_id_; } 25 | 26 | 27 | static std::maptextures_; 28 | static int max_textures_id_; 29 | static int AddTexture(QImage *texture); 30 | static bool DeleteTextures(int id); 31 | static TextureWraper* GetTexture(int id); 32 | 33 | /////////////for debug 34 | static CMorphSkelDentalMeshSeg* msdm_seg_; 35 | static std::string cm_current_adjust_param_; 36 | 37 | }; 38 | #endif -------------------------------------------------------------------------------- /Src/TeethStudio/mesh_render.frag: -------------------------------------------------------------------------------- 1 | #version 120 2 | varying highp vec4 fp; 3 | varying highp vec3 fn; 4 | varying vec3 v_color; 5 | 6 | 7 | uniform highp vec4 u_light_pos; 8 | uniform highp vec4 u_light_diff; 9 | uniform highp vec4 u_light_spec; 10 | uniform highp vec4 u_light_amb; 11 | uniform float u_spec_power; 12 | uniform int use_texture; 13 | uniform int is_shinning; 14 | uniform sampler2D u_sampler_exture; 15 | varying vec2 v_texcoords; 16 | 17 | void main(void) 18 | { 19 | 20 | vec3 L = u_light_pos.xyz - fp.xyz; 21 | vec3 V = -fp.xyz; 22 | vec3 N; 23 | if(fn == vec3(0.0,0.0,0.0)) 24 | N = vec3(0.0,0.0,0.0); 25 | else 26 | N = normalize(fn); 27 | 28 | L = normalize(L); 29 | V = normalize(V); 30 | vec4 vcolor; 31 | if (use_texture == 1) 32 | vcolor = texture2D(u_sampler_exture, v_texcoords); 33 | else 34 | vcolor=vec4(v_color.x,v_color.y,v_color.z,1.0); 35 | vec3 R = reflect(-L, N); 36 | vec4 diffuse; 37 | diffuse = max(abs(dot(N,L)),0) * u_light_diff*vcolor; 38 | vec4 specular = pow(max(dot(R,V), 0.0), u_spec_power) * u_light_spec; 39 | 40 | gl_FragColor = vcolor*u_light_amb + diffuse ;//+ specular; 41 | if(is_shinning==1) 42 | gl_FragColor=vec4(gl_FragColor.x*1.3,gl_FragColor.y*1.0,gl_FragColor.z*1.1,gl_FragColor.a); 43 | 44 | 45 | } 46 | -------------------------------------------------------------------------------- /Projects/TeethStudio/mesh_render.frag: -------------------------------------------------------------------------------- 1 | #version 120 2 | varying highp vec4 fp; 3 | varying highp vec3 fn; 4 | varying vec3 v_color; 5 | 6 | 7 | uniform highp vec4 u_light_pos; 8 | uniform highp vec4 u_light_diff; 9 | uniform highp vec4 u_light_spec; 10 | uniform highp vec4 u_light_amb; 11 | uniform float u_spec_power; 12 | uniform int use_texture; 13 | uniform int is_shinning; 14 | uniform sampler2D u_sampler_exture; 15 | varying vec2 v_texcoords; 16 | 17 | void main(void) 18 | { 19 | 20 | vec3 L = u_light_pos.xyz - fp.xyz; 21 | vec3 V = -fp.xyz; 22 | vec3 N; 23 | if(fn == vec3(0.0,0.0,0.0)) 24 | N = vec3(0.0,0.0,0.0); 25 | else 26 | N = normalize(fn); 27 | 28 | L = normalize(L); 29 | V = normalize(V); 30 | vec4 vcolor; 31 | if (use_texture == 1) 32 | vcolor = texture2D(u_sampler_exture, v_texcoords); 33 | else 34 | vcolor=vec4(v_color.x,v_color.y,v_color.z,1.0); 35 | vec3 R = reflect(-L, N); 36 | vec4 diffuse; 37 | diffuse = max(abs(dot(N,L)),0) * u_light_diff*vcolor; 38 | vec4 specular = pow(max(dot(R,V), 0.0), u_spec_power) * u_light_spec; 39 | 40 | gl_FragColor = vcolor*u_light_amb + diffuse ;//+ specular; 41 | if(is_shinning==1) 42 | gl_FragColor=vec4(gl_FragColor.x*1.3,gl_FragColor.y*1.0,gl_FragColor.z*1.1,gl_FragColor.a); 43 | 44 | 45 | } 46 | -------------------------------------------------------------------------------- /Src/DataColle/base_object.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2016_9 by ChenNenglun 2 | #include"base_object.h" 3 | Eigen::Matrix4d & CBaseObject::GetMatrix() 4 | { 5 | return mat_; 6 | } 7 | void CBaseObject::SetMatrix(Eigen::Matrix4d &mat) 8 | { 9 | mat_ = mat; 10 | } 11 | CBaseObject::CBaseObject() 12 | { 13 | mat_.setIdentity(); 14 | } 15 | CBaseObject::~CBaseObject() 16 | { 17 | 18 | } 19 | void CBaseObject::Rotate(OpenMesh::Vec3d axis, double angle, OpenMesh::Vec3d center ) 20 | { 21 | 22 | Eigen::Matrix3d m; 23 | m = Eigen::AngleAxisd(angle, Eigen::Vector3d(axis[0], axis[1], axis[2])); 24 | Eigen::Quaternionrot(m); 25 | Eigen::Matrix3d rot_mat = rot.toRotationMatrix(); 26 | Eigen::Matrix4d rot_mat4; 27 | rot_mat4.setIdentity(); 28 | 29 | for (int i = 0; i < 3; i++) 30 | { 31 | for (int j = 0; j < 3; j++) 32 | { 33 | rot_mat4(i, j) = rot_mat(i, j); 34 | } 35 | } 36 | for (int i = 0; i < 3; i++) 37 | { 38 | mat_(i, 3) -= center[i]; 39 | } 40 | mat_ = rot_mat4*mat_; 41 | for (int i = 0; i < 3; i++) 42 | { 43 | mat_(i, 3) += center[i]; 44 | } 45 | 46 | } 47 | void CBaseObject::Transform(OpenMesh::Vec3d trans) 48 | { 49 | Eigen::Matrix4d trans_mat; 50 | trans_mat.setIdentity(); 51 | for (int i = 0; i < 3; i++) 52 | { 53 | trans_mat(i, 3)= trans[i]; 54 | } 55 | mat_ = trans_mat*mat_; 56 | 57 | } -------------------------------------------------------------------------------- /Projects/HarmonicSegAlg/HarmonicSegAlg.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Header Files 20 | 21 | 22 | Header Files 23 | 24 | 25 | 26 | 27 | Source Files 28 | 29 | 30 | -------------------------------------------------------------------------------- /Src/AdditionalLibs/libicp/libicp_wrapper.cpp: -------------------------------------------------------------------------------- 1 | #include"libicp_wrapper.h" 2 | #include "icpPointToPoint.h" 3 | 4 | 5 | CIcpPoint2Point::CIcpPoint2Point(Eigen::MatrixXd target_pts) 6 | { 7 | int dim = target_pts.cols(); 8 | target_pts_.resize(target_pts.rows() * dim); 9 | for (int i = 0; i < target_pts.rows(); i++) 10 | { 11 | for(int j=0;jfit(&src_pts_[0],src_pts.rows(),R,t,-1); 28 | 29 | FLOAT rdata[9]; 30 | R.getData(rdata); 31 | FLOAT tdata[3]; 32 | t.getData(tdata); 33 | 34 | 35 | trans(0)= tdata[0]; 36 | trans(1) = tdata[1]; 37 | trans(2) = tdata[2]; 38 | 39 | for (int i = 0; i < 3; i++) 40 | { 41 | for (int j = 0; j < 3; j++) 42 | { 43 | res_rot(i, j) = rdata[i * 3 + j]; 44 | } 45 | } 46 | 47 | 48 | } 49 | CIcpPoint2Point::~CIcpPoint2Point() 50 | { 51 | if(icp_p2p_!=NULL) 52 | delete icp_p2p_; 53 | } -------------------------------------------------------------------------------- /Src/AlgColle/morphlogic_operation.h: -------------------------------------------------------------------------------- 1 | #ifndef CMORPHLOGIC_OPERATION_H 2 | #define CMORPHLOGIC_OPERATION_H 3 | #include"prereq.h" 4 | #include 5 | #include 6 | #include 7 | #include"../DataColle/mesh_object.h" 8 | #include"prereq.h" 9 | class ALGCOLLE_CLASS CMorphlogicOperation 10 | { 11 | public: 12 | enum CMOVertexTag{Complex,Disk,Center,NonFeature}; 13 | static bool IsComplexVertex(COpenMeshT & mesh, std::vector&label, COpenMeshT::VertexHandle vh); 14 | static bool IsCenterVertex(COpenMeshT & mesh, std::vector&label, COpenMeshT::VertexHandle vh); 15 | static int ComputeDegree(COpenMeshT &mesh, std::vector&label,COpenMeshT::VertexHandle vh); 16 | static void TagAllVertexs(COpenMeshT &mesh, std::vector&labels, std::vector&tags, std::vector®ion_ids);//tags:complex,disk,center,nonfeature region_ids:id of non feature(or the boundary of the feature region) region start from 0, -1 mean inner feature region 17 | public: 18 | static void Dilate(COpenMeshT &mesh, std::vector&labels); 19 | static void Erode(COpenMeshT &mesh, std::vector&labels); 20 | 21 | static void FloodFill(COpenMeshT &mesh, std::vector&label, bool roi_label, COpenMeshT::VertexHandle start_vh, int target_tag, std::vector&res_region_tag); 22 | static void Skeletonization(COpenMeshT& mesh, std::vector&labels); 23 | }; 24 | #endif -------------------------------------------------------------------------------- /Src/TeethStudio/cmodelviewer.h: -------------------------------------------------------------------------------- 1 | // Copyright 2016_9 by ChenNenglun 2 | #ifndef MODEL_VIEWER_H 3 | #define MODEL_VIEWER_H 4 | 5 | #include 6 | #include 7 | #include"../DataColle/mesh_object.h" 8 | #include 9 | #include"camera.h" 10 | #include"scene.h" 11 | #include"action_manager.h" 12 | class CModelViewer : public QGLViewer, public QOpenGLFunctions_2_1 13 | { 14 | protected: 15 | CCamera camera_; 16 | CScene *scene_; 17 | Eigen::Vector3d background_color_; 18 | CActionManager *action_manager_; 19 | protected: 20 | virtual void draw(); 21 | virtual void init();//called automatically when the viewer is initialized 22 | virtual void initializeGL();//called automatically when the opengl context is initialized 23 | 24 | 25 | void keyPressEvent(QKeyEvent *e); 26 | void keyReleaseEvent(QKeyEvent*e); 27 | void mousePressEvent(QMouseEvent *); 28 | void mouseMoveEvent(QMouseEvent *); 29 | void mouseReleaseEvent(QMouseEvent *); 30 | void mouseDoubleClickEvent(QMouseEvent *); 31 | void wheelEvent(QWheelEvent *); 32 | public: 33 | void InitCamera();// init parameters of the camera_ 34 | CModelViewer(QWidget *parent); 35 | ~CModelViewer(); 36 | void SetScene(CScene* scene); 37 | void SetBackgroundColor(Eigen::Vector3d background_color); 38 | CCamera GetCamera() { return camera_; } 39 | 40 | 41 | }; 42 | 43 | #endif // MODEL_VIEWER_H 44 | -------------------------------------------------------------------------------- /Src/AdditionalLibs/XWGeodesic/Xin_Wang.h: -------------------------------------------------------------------------------- 1 | // ICHWithFurtherPriorityQueue.h: interface for the CXin_Wang class. 2 | // 3 | ////////////////////////////////////////////////////////////////////// 4 | 5 | #pragma once 6 | #include "ICH_WindowFiltering.h" 7 | class CXin_Wang : public CICH_WindowFiltering 8 | { 9 | protected: 10 | vector m_fixedSequence; 11 | priority_queue m_QueueForWindows; 12 | priority_queue m_QueueForPseudoSources; 13 | protected: 14 | virtual void Dispose(); 15 | virtual void Propagate(); 16 | protected: 17 | void AddIntoQueueOfPseudoSources(const QuoteInfoAtVertex& quoteOfPseudoSource); 18 | void AddIntoQueueOfWindows(QuoteWindow& quoteW); 19 | bool UpdateTreeDepthBackWithChoice(); 20 | double GetMinDisOfWindow(const Window& w) const; 21 | public: 22 | CXin_Wang(const CRichModel& model, int source); 23 | CXin_Wang(const CRichModel& model, int source, int destination); 24 | CXin_Wang(const CRichModel& model, int source, double R); 25 | CXin_Wang(const CRichModel& model, const map& sources); 26 | CXin_Wang(const CRichModel& model, const map& sources, const set &destinations); 27 | CXin_Wang(const CRichModel& model, const set& sources); 28 | CXin_Wang(const CRichModel& model, const set& sources, double R); 29 | CXin_Wang(const CRichModel& model, const set& sources, const set& destinations); 30 | vector GetFixedVertSequence() const; 31 | }; 32 | -------------------------------------------------------------------------------- /Src/DataColle/cgal_igl_converter.h: -------------------------------------------------------------------------------- 1 | #ifndef FACEMODE_DATACOLLE_CGAL_IGL_CONVERTER_H 2 | #define FACEMODE_DATACOLLE_CGAL_IGL_CONVERTER_H 3 | #include "prereq.h" 4 | #include "Polyhedron_type.h" 5 | #include 6 | #include"custom_openmesh_type.h" 7 | 8 | class DATACOLLE_CLASS CConverter 9 | { 10 | public: 11 | static bool ConvertFromCGALToIGL(Polyhedron& mesh, Eigen::MatrixXd& v, Eigen::MatrixXi& f); 12 | static bool ConvertFromCGALRoiToIGL(Polyhedron& poly, std::vector&fhs, Eigen::MatrixXd& v, Eigen::MatrixXi&f); 13 | static bool ConvertFromIGLToCGAL(Eigen::MatrixXd& v, Eigen::MatrixXi& f, Polyhedron &mesh, std::vector&fid_fh_map, std::vector&vid_vhs_map); 14 | static bool ConvertFromOpenMeshToIGL(COpenMeshT &mesh, Eigen::MatrixXd& v, Eigen::MatrixXi& f,std::vector*id_fh_map=NULL, std::vector*id_vh_map=NULL); 15 | static bool ConvertFromCGALToOpenMesh(Polyhedron& mesh, COpenMeshT& openmesh, std::map& vh_map, std::map& fh_map); 16 | static bool ConvertFromOpenMeshToCGAL(COpenMeshT& openmesh, Polyhedron &mesh, std::map& vh_map, std::map& fh_map); 17 | static bool ConvertFromIGLToOpenMesh(Eigen::MatrixXd& v, Eigen::MatrixXi& f, COpenMeshT& openmesh); 18 | 19 | 20 | }; 21 | #endif -------------------------------------------------------------------------------- /Src/TeethStudio/scene_curve_object.h: -------------------------------------------------------------------------------- 1 | // Copyright 2016_9 by ChenNenglun 2 | #ifndef SCENE_CURVE_OBJECT_H 3 | #define SCENE_CURVE_OBJECT_H 4 | #include"../DataColle/curve_object.h" 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include"camera.h" 15 | #include"qopengltexture.h" 16 | //wraper of CMeshObject, CSceneMeshObject can be drawed in opengl context 17 | class CSceneCurveObject :public QOpenGLFunctions_2_1 18 | { 19 | protected: 20 | std::weak_ptr curve_; 21 | std::vector vertexs_pos_;//data of opengl buffer,size:n x 3,n is the vertex number in curve_ 22 | std::vectorvertex_colors_;//data of opengl buffer,size:n x 3,n is the vertex number in curve_ 23 | 24 | 25 | mutable QOpenGLBuffer vertex_pos_buffer_, vertex_colors_buffer_; 26 | mutable QOpenGLVertexArrayObject vao_; 27 | mutable QOpenGLShaderProgram rendering_program_; 28 | 29 | protected: 30 | 31 | void ComputeRenderingElements(); 32 | void SetGLBufferDataFromElements(); 33 | void InitShader(); 34 | public: 35 | CSceneCurveObject(std::weak_ptr curve); 36 | ~CSceneCurveObject(); 37 | void UpdateRenderInfo();// if the is_changed_ of mesh is seted, the opengl buffer will be updated 38 | 39 | void Render(CCamera camera); 40 | }; 41 | #endif -------------------------------------------------------------------------------- /Src/DataColle/volume_data_object.cpp: -------------------------------------------------------------------------------- 1 | #include"volume_data_object.h" 2 | int CVolumeDataObject::GetId() 3 | { 4 | return id_; 5 | } 6 | ItkVolumeDataType::Pointer CVolumeDataObject::GetVolumeData() 7 | { 8 | return volume_data_; 9 | } 10 | void CVolumeDataObject::SetVolumeData(ItkVolumeDataType::Pointer pdata) 11 | { 12 | volume_data_ = pdata; 13 | } 14 | 15 | OpenMesh::Vec3d CVolumeDataObject::GetDataSize() 16 | { 17 | auto region = volume_data_->GetLargestPossibleRegion(); 18 | auto size = region.GetSize(); 19 | return OpenMesh::Vec3d(size[0], size[1], size[2]); 20 | } 21 | void CVolumeDataObject::GenTestData() 22 | { 23 | data_height_ = 400; 24 | data_depth_ = 400; 25 | data_width_ = 400; 26 | vdata_.resize(data_height_*data_width_*data_depth_ ,OpenMesh::Vec4d(0.2,0.2,0.2,0.01)); 27 | for (int d = 100; d < 200; d++) 28 | { 29 | for (int w = 100; w < 200; w++) 30 | { 31 | for (int h = 100; h < 200; h++) 32 | { 33 | vdata_[(d*data_height_*data_width_ + w*data_height_ + h)] = OpenMesh::Vec4d(1,0,0,0.9); 34 | 35 | } 36 | } 37 | } 38 | } 39 | CVolumeDataObject::CVolumeDataObject() 40 | { 41 | id_ = -1; 42 | is_changed_ = true; 43 | //GenTestData(); 44 | //volume_data_ = NULL; 45 | } 46 | void CVolumeDataObject::SetChanged(bool is_changed) 47 | { 48 | is_changed_ = is_changed; 49 | } 50 | CVolumeDataObject::~CVolumeDataObject() 51 | { 52 | 53 | //volume_data_->ReleaseData(); 54 | 55 | } 56 | void CVolumeDataObject::SetId(int id) 57 | { 58 | id_ = id; 59 | } -------------------------------------------------------------------------------- /Src/TeethStudio/action_base.h: -------------------------------------------------------------------------------- 1 | #ifndef CACTION_BASE_H 2 | #define CACTION_BASE_H 3 | #include 4 | 5 | #include 6 | 7 | #include"qobject.h" 8 | #include"qmetaobject.h" 9 | #include"qwidget.h" 10 | class CModelViewer; 11 | class CActionManager; 12 | enum CActionType { Common,EditFeatureEdge,HarmonicFieldSegmentation,VolumeDataSegmentation, CTeethReconstructionTest, CTeethReconstruction,CPanoramicSimulationTest,CSingleTeethProjection}; 13 | class CActionBase :public QWidget 14 | { 15 | Q_OBJECT 16 | protected: 17 | bool is_done_ = true; 18 | CModelViewer *viewer_; 19 | CActionManager*manager_; 20 | CActionType type_; 21 | bool shielding_key_modifiers_ = true; 22 | bool coexist_with_common_tool_ = false; 23 | public: 24 | virtual void SetViewer(CModelViewer * v) 25 | { 26 | viewer_ = v; 27 | } 28 | virtual void SetManager(CActionManager *m) 29 | { 30 | manager_ = m; 31 | } 32 | virtual CActionType GetType() { return type_; } 33 | 34 | 35 | 36 | virtual void MousePressEvent(QMouseEvent *e) { return; } 37 | virtual void MouseMoveEvent(QMouseEvent *e) { return; } 38 | virtual void MouseReleaseEvent(QMouseEvent *e) { return; } 39 | virtual void KeyPressEvent(QKeyEvent *e) { return; } 40 | virtual void KeyReleaseEvent(QKeyEvent *e) { return; } 41 | virtual void WheelEvent(QWheelEvent *) { return; } 42 | 43 | virtual void MouseDoubleClickEvent(QMouseEvent * e) { return ; } 44 | virtual void Init() { } 45 | 46 | 47 | 48 | 49 | 50 | }; 51 | #endif 52 | 53 | -------------------------------------------------------------------------------- /Src/AdditionalLibs/libicp/icpPointToPoint.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2011. All rights reserved. 3 | Institute of Measurement and Control Systems 4 | Karlsruhe Institute of Technology, Germany 5 | 6 | Authors: Andreas Geiger 7 | 8 | libicp is free software; you can redistribute it and/or modify it under the 9 | terms of the GNU General Public License as published by the Free Software 10 | Foundation; either version 2 of the License, or any later version. 11 | 12 | libicp is distributed in the hope that it will be useful, but WITHOUT ANY 13 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 14 | PARTICULAR PURPOSE. See the GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along with 17 | libicp; if not, write to the Free Software Foundation, Inc., 51 Franklin 18 | Street, Fifth Floor, Boston, MA 02110-1301, USA 19 | */ 20 | 21 | #ifndef ICP_POINT_TO_POINT_H 22 | #define ICP_POINT_TO_POINT_H 23 | 24 | #include "icp.h" 25 | 26 | class IcpPointToPoint : public Icp { 27 | 28 | public: 29 | 30 | IcpPointToPoint (double *M,const int32_t M_num,const int32_t dim) : Icp(M,M_num,dim) {} 31 | virtual ~IcpPointToPoint () {} 32 | 33 | private: 34 | 35 | double fitStep (double *T,const int32_t T_num,ICPMatrix &R,ICPMatrix &t,const std::vector &active); 36 | std::vector getInliers (double *T,const int32_t T_num,const ICPMatrix &R,const ICPMatrix &t,const double indist); 37 | }; 38 | 39 | #endif // ICP_POINT_TO_POINT_H 40 | -------------------------------------------------------------------------------- /Src/AdditionalLibs/lbfgs/Non_Linear_Optimization.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "lbfgs.h" 3 | #include"../prereq.h" 4 | #include 5 | #include 6 | #include 7 | #include"lbfgspre.h" 8 | class ADDITIONALLIBS_CLASS Non_Linear_Optimization 9 | { 10 | protected: 11 | std::vector m_variables; 12 | lbfgs_parameter_t m_parameters; 13 | bool m_printprogress; 14 | public: 15 | Non_Linear_Optimization(); 16 | bool& GetPrintProgress(); 17 | //return the number of iterations 18 | lbfgs_parameter_t& GetParameters(); 19 | 20 | int run(); 21 | 22 | protected: 23 | int progress( 24 | const lbfgsfloatval_t *x, 25 | const lbfgsfloatval_t *g, 26 | const lbfgsfloatval_t fx, 27 | const lbfgsfloatval_t xnorm, 28 | const lbfgsfloatval_t gnorm, 29 | const lbfgsfloatval_t step, 30 | int n, 31 | int k, 32 | int ls 33 | ); 34 | virtual lbfgsfloatval_t evaluate( 35 | const lbfgsfloatval_t *x, 36 | lbfgsfloatval_t *g, 37 | const int n, 38 | const lbfgsfloatval_t step 39 | ) = 0; 40 | 41 | static lbfgsfloatval_t _evaluate( 42 | void *instance, 43 | const lbfgsfloatval_t *x, 44 | lbfgsfloatval_t *g, 45 | const int n, 46 | const lbfgsfloatval_t step 47 | ); 48 | 49 | static int _progress( 50 | void *instance, 51 | const lbfgsfloatval_t *x, 52 | const lbfgsfloatval_t *g, 53 | const lbfgsfloatval_t fx, 54 | const lbfgsfloatval_t xnorm, 55 | const lbfgsfloatval_t gnorm, 56 | const lbfgsfloatval_t step, 57 | int n, 58 | int k, 59 | int ls 60 | ); 61 | }; -------------------------------------------------------------------------------- /Src/AdditionalLibs/XWGeodesic/Extremity_Point_Utils.cpp: -------------------------------------------------------------------------------- 1 | #include"Extremity_Point_Utils.h" 2 | #include 3 | 4 | 5 | 6 | ExtremityPointUtils::ExtremityPointUtils(CRichModel &model) :m_model(model) 7 | { 8 | 9 | } 10 | void ExtremityPointUtils::ComputeMeanDistances(double radius, std::vector& meanDis,int num_thread) 11 | { 12 | meanDis.resize(m_model.GetNumOfVerts()); 13 | #pragma omp parallel for num_threads(num_thread) 14 | for (int i = 0; i < m_model.GetNumOfVerts(); i++) 15 | { 16 | cerr << "compute mean dis at vert: " << i << endl; 17 | ExtremityPointUtils alg(m_model); 18 | meanDis[i] = alg.ComputeMeanDistanceAtSourcePoint(i, radius); 19 | } 20 | } 21 | double ExtremityPointUtils::ComputeMeanDistanceAtSourcePoint(int source, double radius) 22 | { 23 | CXin_Wang alg(m_model, source,radius); 24 | alg.Execute(); 25 | set vIDs; 26 | queuevQue; 27 | vQue.push(source); 28 | while (!vQue.empty()) 29 | { 30 | int p = vQue.front(); 31 | vQue.pop(); 32 | for (int i = 0; i < m_model.Neigh(p).size(); i++) 33 | { 34 | 35 | int id = m_model.Edge(m_model.Neigh(p)[i].first).indexOfRightVert; 36 | if (alg.m_InfoAtVertices[id].disUptodate <= radius&&vIDs.find(id) == vIDs.end()) 37 | { 38 | vIDs.insert(id); 39 | vQue.push(id); 40 | } 41 | 42 | } 43 | } 44 | 45 | double mean_dis = 0; 46 | for (auto iter = vIDs.begin(); iter != vIDs.end(); iter++) 47 | { 48 | mean_dis += alg.m_InfoAtVertices[*iter].disUptodate; 49 | } 50 | mean_dis /= vIDs.size(); 51 | return mean_dis; 52 | } -------------------------------------------------------------------------------- /Src/AlgColle/correspondence_builder.h: -------------------------------------------------------------------------------- 1 | #ifndef FACEMOD_ALGCOLLE_CORRESPONDENCE_BUILDER_H 2 | #define FACEMOD_ALGCOLLE_CORRESPONDENCE_BUILDER_H 3 | #include "prereq.h" 4 | #include"../DataColle/mesh_object.h" 5 | 6 | class ALGCOLLE_CLASS CCorrespondenceBuilder 7 | { 8 | public: 9 | CCorrespondenceBuilder(); 10 | 11 | // 12 | void SetParameters(double sigma_p=0.03, double sigma_n= 0.1, double sigma_c= 1) 13 | { 14 | 15 | sigma_p_ = sigma_p; 16 | sigma_n_ = sigma_n; 17 | sigma_c_ = sigma_c; 18 | }; 19 | 20 | std::map FindCorrespondenceMap(CMeshObject* p_polyobj, std::vector p_curveobj, std::vector roi_region = std::vector()); 21 | std::map FindCorrespondenceMapNormal(CMeshObject* p_polyobj, std::vector& p_curveobj, std::vector roi_region); 22 | 23 | private: 24 | void ComputeEmissionProbabilities(); 25 | void ComputeTransitionProbabilities(); 26 | bool HMMMatching(); 27 | CMeshObject* p_polyobj_ = NULL; 28 | std::vector p_curveobj_ ; 29 | std::map roi_vertices_normal_map_; 30 | std::vector > ep_matrix_; 31 | std::vector > vdist_matrix_; 32 | std::vector pdist_vec_; 33 | std::vector curve_normal_vec_; 34 | std::map deform_handle_map_; 35 | double sigma_p_; 36 | double sigma_n_; 37 | double sigma_c_; 38 | }; 39 | #endif -------------------------------------------------------------------------------- /Src/TeethStudio/panoramic_simulation_test_action.h: -------------------------------------------------------------------------------- 1 | #ifndef CPANORAMIC_SIMULATION_TEST_H 2 | #define CPANORAMIC_SIMULATION_TEST_H 3 | #include"action_base.h" 4 | #include 5 | #include"../DataColle/mesh_object.h" 6 | #include"../AlgColle/arap_deform.h" 7 | #include"../TeethRootRecoAlg/panoramic_fitting.h" 8 | 9 | 10 | 11 | class CPanoramicSimulationTestAction :public CActionBase 12 | { 13 | protected: 14 | std::mapcrowns_; 15 | std::vectorsegmented_jaws_ ; 16 | std::map>jaw_crowns_; 17 | OpenMesh::Vec3d center_; 18 | std::vectorframe_; 19 | std::vectorpick_pts_on_panorama_; 20 | std::vector>pick_vhs_on_crown_; 21 | 22 | std::map>>proj_coords_; 23 | OpenMesh::Vec3d param_rendering_offset_; 24 | 25 | double rot_degree_step_; 26 | double center_move_step_; 27 | double radius_step_; 28 | double radius_; 29 | int panoramic_pic_id_; 30 | bool is_selecting_pair_; 31 | void Init(); 32 | void MousePressEvent(QMouseEvent *e); 33 | void MouseMoveEvent(QMouseEvent *e); 34 | void MouseReleaseEvent(QMouseEvent *e); 35 | void KeyPressEvent(QKeyEvent *e); 36 | void KeyReleaseEvent(QKeyEvent *e); 37 | 38 | //size of frame equal to 3 39 | void RotateFrame(std::vector&frame,OpenMesh::Vec3d axis,double degree); 40 | void RenderAuxilliaryShape(); 41 | void ComputeFrameAndCenter(); 42 | void GenPanorama(); 43 | 44 | void SavePoints(); 45 | public: 46 | CPanoramicSimulationTestAction(); 47 | 48 | }; 49 | #endif 50 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | This is a private project for dental segmentation project. 2 | We use openmesh to represent 3d mesh and use itk to deal with dicom data. 3 | 4 | The main open source libraries we depend on are OpenMesh, CGAL,QGLViewer, Boost, Eigen ,QT , OpenCV ,ann and itk. All the codes should be compiled with MSVC 2015 on Windows. Other platforms and compilers are not guaranteed. 5 | 6 | To compile our project with no trouble, please add some environment variables to your system (you may need replace the paths below to your actual ones): 7 | 8 | TANN_DIR: D:\CodeLibrary\Ann1_1_2 9 | 10 | TCGAL_BUILD: D:\CodeLibrary\CGAL4.9\winbuild64 11 | 12 | TCGAL_DIR: D:\CodeLibrary\CGAL4.9\ When you cmake CGAL and generated Qt5 related solutions, set Qt5_DIR to ../YOURPATH/Qt/Qt5.7.0/5.7/msvc2015_64/lib/cmake/Qt5 13 | 14 | TEIGEN_ROOT: D:\CodeLibrary\eigen3_3 15 | 16 | TITK_BUILD: D:\CodeLibrary\InsightToolkit-4.10.1\Build 17 | 18 | TITK_DIR: D:\CodeLibrary\InsightToolkit-4.10.1 19 | 20 | TLIBIGL_DIR: D:\CodeLibrary\libigl 21 | 22 | TLIBIGL_INCLDUEDIR: D:\CodeLibrary\libigl\include 23 | 24 | TOPEN_MESH_DIR: D:\CodeLibrary\OpenMesh_6_3\ 25 | 26 | TOPENCV_DIR: D:\CodeLibrary\opencv310\build\install 27 | 28 | TQGLVIEWER_DIR: D:\CodeLibrary\libQGLViewer-2.6.4_vs2015 29 | 30 | TQTDIR: D:\CodeLibrary\QT_5_7\5.7\msvc2015_64 31 | 32 | BOOST_INCLUDEDIR: D:\CodeLibrary\boost_1_62_0_vs2015 33 | 34 | BOOST_LIBRARYDIR: D:\CodeLibrary\boost_1_62_0_vs2015\lib64-msvc-14.0 35 | 36 | 37 | 38 | And further you may need to add your third-party dlls paths to your path in system variables. Alternatively, putting them together with the exe file is also a good choice. -------------------------------------------------------------------------------- /Src/TeethStudio/teeth_reconstruction_test_action.h: -------------------------------------------------------------------------------- 1 | #ifndef CTEETH_RECONSTRUCTIONTEST_ACTION_H 2 | #define CTEETH_RECONSTRUCTIONTEST_ACTION_H 3 | #include"action_base.h" 4 | #include 5 | #include"../DataColle/mesh_object.h" 6 | #include"../AlgColle/arap_deform.h" 7 | class CNonRigidICP; 8 | class CTeethReconstructionTestAction:public CActionBase 9 | { 10 | protected: 11 | bool is_picking_; 12 | bool is_picking_fa_point_; 13 | std::mapcrowns_; 14 | std::maptemplate_tooth_; 15 | std::mapcrown_of_template_tooth_; 16 | std::map>crown_to_template_fmap_; 17 | std::map>crown_to_template_vmap_; 18 | CMeshObject *segmented_crown_=NULL; 19 | CMeshObject* orig_tooth_template_=NULL; 20 | int sel_crown_id_, sel_temp_id_,sel_curve_id_,sel_temp_crown_id_; 21 | CARAPDeformation* template_arap_=NULL; 22 | CNonRigidICP* non_rigid_icp_=NULL; 23 | std::vector>test_sel_ps; 24 | std::mapfa_point_map_; 25 | 26 | std::maplong_axis_; 27 | std::mapcrown_centers_; 28 | std::mapcrown_mats_; 29 | bool IsTemplateTeeth(int id); 30 | void Init(); 31 | void MousePressEvent(QMouseEvent *e); 32 | void MouseMoveEvent(QMouseEvent *e); 33 | void MouseReleaseEvent(QMouseEvent *e); 34 | void KeyPressEvent(QKeyEvent *e); 35 | void KeyReleaseEvent(QKeyEvent *e); 36 | public: 37 | CTeethReconstructionTestAction(); 38 | 39 | }; 40 | #endif 41 | -------------------------------------------------------------------------------- /Src/AdditionalLibs/XWGeodesic/FacePoint.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "RichModel.h" 3 | #include 4 | using namespace std; 5 | struct FacePoint 6 | { 7 | int faceID; 8 | double lamda1, lamda2, lamda3; 9 | 10 | FacePoint(){} 11 | FacePoint(int faceID, double lamda1, double lamda2) 12 | : faceID(faceID), lamda1(lamda1), lamda2(lamda2) 13 | { 14 | lamda3 = 1 - lamda1 - lamda2; 15 | } 16 | 17 | CPoint3D Get3DPoint(const CRichModel& model) const 18 | { 19 | return lamda1 * model.GetShiftVertex(model.Face(faceID)[0]) 20 | + lamda2 * model.GetShiftVertex(model.Face(faceID)[1]) 21 | + lamda3 * model.GetShiftVertex(model.Face(faceID)[2]); 22 | } 23 | pair Get2DCoord(const CRichModel& model, int edgeIndex) const 24 | { 25 | double x, y; 26 | if (model.Edge(edgeIndex).indexOfLeftVert == model.Face(faceID)[0]) 27 | { 28 | x = lamda1 * 0 + lamda2 * model.Edge(edgeIndex).length + lamda3 * model.Edge(edgeIndex).coordOfOppositeVert.first; 29 | y = lamda1 * 0 + lamda2 * 0 + lamda3 * model.Edge(edgeIndex).coordOfOppositeVert.second; 30 | } 31 | else if (model.Edge(edgeIndex).indexOfLeftVert == model.Face(faceID)[1]) 32 | { 33 | x = lamda2 * 0 + lamda3 * model.Edge(edgeIndex).length + lamda1 * model.Edge(edgeIndex).coordOfOppositeVert.first; 34 | y = lamda2 * 0 + lamda3 * 0 + lamda1 * model.Edge(edgeIndex).coordOfOppositeVert.second; 35 | } 36 | else 37 | { 38 | x = lamda3 * 0 + lamda1 * model.Edge(edgeIndex).length + lamda2 * model.Edge(edgeIndex).coordOfOppositeVert.first; 39 | y = lamda3 * 0 + lamda1 * 0 + lamda2 * model.Edge(edgeIndex).coordOfOppositeVert.second; 40 | } 41 | return make_pair(x, y); 42 | } 43 | }; -------------------------------------------------------------------------------- /Src/DataColle/custom_openmesh_type.h: -------------------------------------------------------------------------------- 1 | #ifndef CUSTOM_OPENMESH_TYPE_H 2 | #define CUSTOM_OPENMESH_TYPE_H 3 | #include "prereq.h" 4 | #include 5 | #include 6 | #include 7 | struct COMTraits : public OpenMesh::DefaultTraits 8 | { 9 | // store barycenter of neighbors in this member 10 | typedef OpenMesh::Vec3d Point; // use double-values points 11 | typedef OpenMesh::Vec3d Color; 12 | typedef OpenMesh::Vec3d Normal; 13 | HalfedgeTraits 14 | { 15 | private: 16 | TexCoord2D uv_; 17 | TexCoord3D uv3d_; 18 | Color color_; 19 | public: 20 | HalfedgeT() : uv_(TexCoord2D(0.0f, 0.0f)), color_(Color(0,0, 0)) { } 21 | const TexCoord2D& GetUV() const { return uv_; } 22 | const TexCoord3D& GetUV3D() const { return uv3d_; } 23 | const Color& GetColor() const { return color_; } 24 | void SetUV(const TexCoord2D& _p) { uv_ = _p; } 25 | void SetUV3D(const TexCoord3D& _p) { uv3d_ = _p; } 26 | void SetColor(const TexCoord2D& c) { color_ = c; } 27 | }; 28 | 29 | FaceTraits 30 | { 31 | private: 32 | 33 | public: 34 | FaceT() {} 35 | 36 | }; 37 | 38 | }; 39 | 40 | class COpenMeshT :public OpenMesh::TriMesh_ArrayKernelT 41 | { 42 | public: 43 | COpenMeshT() 44 | { 45 | request_vertex_colors(); 46 | request_face_status(); 47 | request_edge_status(); 48 | request_vertex_status(); 49 | request_face_normals(); 50 | request_vertex_normals(); 51 | request_halfedge_texcoords3D(); 52 | request_halfedge_texcoords2D(); 53 | 54 | } 55 | }; 56 | 57 | // --------------------------------------------------------------------------- 58 | #endif -------------------------------------------------------------------------------- /Src/AlgColle/arap_deform.h: -------------------------------------------------------------------------------- 1 | #ifndef CARAP_DEFORM_H 2 | #define CARAP_DEFORM_H 3 | #include"prereq.h" 4 | #include 5 | #include"../DataColle/mesh_object.h" 6 | #include"../DataColle/cgal_igl_converter.h" 7 | #include 8 | //class ALGCOLLE_CLASS CARAPDeformation 9 | //{ 10 | //public: 11 | // //CARAPDeformation() : CMeshDeformation() {} 12 | // CARAPDeformation(COpenMeshT& mesh); 13 | // virtual ~CARAPDeformation(); 14 | // //bool SetRoiVertices();//Set all of vertices on polyhedron as ROI 15 | // //bool SetRoiVertices(const std::vector& vertices_handle_vec);//Set specified vertices as ROI 16 | // bool SetDeformHandle(std::vector& deform_handles); 17 | // bool Deform(std::map&handle_map); 18 | //private: 19 | // COpenMeshT& mesh_; 20 | // Eigen::MatrixXd v_; 21 | // Eigen::MatrixXi f_; 22 | // Eigen::VectorXi handle_id_; 23 | // Eigen::MatrixXd handle_targt_; 24 | // igl::ARAPData arap_data_; 25 | // std::vector deform_handles_; 26 | // 27 | //}; 28 | class CgalArapDeform; 29 | 30 | class ALGCOLLE_CLASS CARAPDeformation 31 | { 32 | protected: 33 | CgalArapDeform* cgal_arap_deform_=NULL; 34 | Polyhedron poly_; 35 | COpenMeshT &mesh_; 36 | std::vectorcgal_id_to_om_vh_map_; 37 | std::vectorom_id_to_cgal_vh_map_; 38 | //std::mapdeform_map_; 39 | public: 40 | CARAPDeformation(COpenMeshT& mesh); 41 | ~CARAPDeformation(); 42 | bool SetDeformMap(std::map& deform_handle_map); 43 | 44 | 45 | bool Deform(); 46 | }; 47 | 48 | 49 | #endif -------------------------------------------------------------------------------- /Src/TeethStudio/harmonic_field_segmentation_action.h: -------------------------------------------------------------------------------- 1 | #ifndef CHARMONIC_FIELD_SEGMENTATION_ACTION_H 2 | #define CHARMONIC_FIELD_SEGMENTATION_ACTION_H 3 | #include"action_base.h" 4 | #include "../DataColle/custom_openmesh_type.h" 5 | #include"../DataColle/mesh_object.h" 6 | #include"../DataColle/curve_object.h" 7 | class CHarmonicFieldSegmentation :public CActionBase 8 | { 9 | protected: 10 | std::vectorpicked_vhs_fore_,picked_vhs_back_; 11 | std::setpicked_vhs_fore_mark_, picked_vhs_back_mark_; 12 | 13 | std::setrand_color_set_; 14 | std::vectorteeth_seg_mark_;//mark of each vertex -1 means gingiva 15 | std::vectorgingiva_seg_mark_; 16 | int teeth_seg_mark_id_; 17 | std::mapteeth_seg_count_; 18 | std::mapteeth_seg_color_;//color of each segmented teeth 19 | bool is_pick_fore_ = true; 20 | CMeshObject *p_mesh_obj_; 21 | CCurveObject *p_curve_obj_=NULL; 22 | bool is_eliminating_feature_ = false; 23 | bool is_seg_teeth_from_gingiva_ = false; 24 | bool is_drawing_ = false; 25 | OpenMesh::Vec3d pca_mean_; 26 | std::vectorpca_frame_; 27 | OpenMesh::Vec3d GetRandColor(); 28 | 29 | 30 | int dental_mesh_id_; 31 | int seg_tooth_mesh_id_; 32 | std::map all_seg_tooth_orig_vhs_map_; 33 | 34 | protected: 35 | void RenderFeature(); 36 | void Init(); 37 | void MousePressEvent(QMouseEvent *e); 38 | void MouseMoveEvent(QMouseEvent *e); 39 | void MouseReleaseEvent(QMouseEvent *e); 40 | void KeyPressEvent(QKeyEvent *e); 41 | void KeyReleaseEvent(QKeyEvent *e); 42 | public: 43 | CHarmonicFieldSegmentation(); 44 | }; 45 | #endif -------------------------------------------------------------------------------- /Src/TeethStudio/scene_mesh_object.h: -------------------------------------------------------------------------------- 1 | // Copyright 2016_9 by ChenNenglun 2 | #ifndef SCENE_MESH_OBJECT_H 3 | #define SCENE_MESH_OBJECT_H 4 | #include"../DataColle/mesh_object.h" 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include"camera.h" 15 | #include"qopengltexture.h" 16 | //wraper of CMeshObject, CSceneMeshObject can be drawed in opengl context 17 | class CSceneMeshObject :public QOpenGLFunctions_2_1 18 | { 19 | protected: 20 | std::weak_ptr mesh_; 21 | std::vector vertexs_pos_;//data of opengl buffer,size:n x 3,n is the vertex number in mesh_ 22 | std::vector vertex_normals_;//data of opengl buffer,size:n x 3,n is the vertex number in mesh_ 23 | std::vectorvertex_colors_;//data of opengl buffer,size:n x 3,n is the vertex number in mesh_ 24 | std::vectortex_coords_; 25 | bool use_texture_ = false;; 26 | QOpenGLTexture* texture_ = NULL; 27 | mutable QOpenGLBuffer vertex_pos_buffer_,vertex_normals_buffer_,vertex_colors_buffer_,tex_coords_buffer_; 28 | mutable QOpenGLVertexArrayObject vao_; 29 | mutable QOpenGLShaderProgram rendering_program_; 30 | 31 | protected: 32 | 33 | void ComputeRenderingElements(); 34 | void SetGLBufferDataFromElements(); 35 | void InitShader(); 36 | public: 37 | CSceneMeshObject(std::weak_ptr mesh); 38 | ~CSceneMeshObject(); 39 | void UpdateRenderInfo();// if the is_changed_ of mesh is seted, the opengl buffer will be updated 40 | 41 | void Render(CCamera camera); 42 | }; 43 | #endif -------------------------------------------------------------------------------- /Src/DataColle/data_pool.h: -------------------------------------------------------------------------------- 1 | // Copyright 2016_9 by ChenNenglun 2 | #ifndef DATA_POOL_H 3 | #define DATA_POOL_H 4 | #include"prereq.h" 5 | #include 6 | #include 7 | #include 8 | #include"mesh_object.h" 9 | #include"curve_object.h" 10 | #include"volume_data_object.h" 11 | #include 12 | class DATACOLLE_CLASS DataPool 13 | { 14 | protected: 15 | static std::map> mesh_object_pool_;//pool of CMeshObject 16 | static int mesh_object_max_id_;// current max id in mesh_object_pool_ 17 | 18 | static std::map>curve_object_pool_; 19 | static int curve_object_max_id_; 20 | 21 | static std::map>volume_data_object_pool_; 22 | static int volume_data_object_max_id_; 23 | public: 24 | static int AddMeshObject(CMeshObject *mesh);// add CMeshObject to mesh_object_pool_ 25 | static bool DeleteMeshObject(int id); 26 | static CMeshObject * GetMeshObject(int id); 27 | static void Init();//initialization 28 | static std::map>& GetMeshObjectPool(); 29 | 30 | 31 | static int AddCurveObject(CCurveObject *curve); 32 | static bool DeleteCurveObject(int id); 33 | static void DeleteAllCurveObjects(); 34 | static CCurveObject *GetCurveObject(int id); 35 | static std::map>& GetCurveObjectPool(); 36 | 37 | 38 | static int AddVolumeDataObject(CVolumeDataObject *volume_data_obj); 39 | static bool DeleteVolumeDataObject(int id); 40 | static void DeleteAllVolumeDataObjects(); 41 | static CVolumeDataObject *GetVolumeDataObject(int id); 42 | static std::map>& GetVolumeDataObjectPool(); 43 | }; 44 | #endif 45 | -------------------------------------------------------------------------------- /Src/AlgColle/cgal_arap_deform.cpp: -------------------------------------------------------------------------------- 1 | #include"cgal_arap_deform.h" 2 | #include "../DataColle/Polyhedron_type.h" 3 | #include 4 | #include 5 | CgalArapDeform::CgalArapDeform(Polyhedron& mesh):mesh_(mesh) 6 | { 7 | 8 | set_halfedgeds_items_id(mesh_); 9 | p_deform_mesh_ = new Surface_mesh_deformation(mesh_); 10 | } 11 | 12 | CgalArapDeform::~CgalArapDeform() 13 | { 14 | delete(p_deform_mesh_); 15 | } 16 | 17 | bool CgalArapDeform::SetRoiVertices(const std::vector& vertices_handle_vec) 18 | { 19 | 20 | Polyhedron::Vertex_iterator vb = mesh_.vertices_begin(); 21 | Polyhedron::Vertex_iterator ve = mesh_.vertices_end(); 22 | for (auto itr = vertices_handle_vec.begin(); itr != vertices_handle_vec.end(); itr++) 23 | { 24 | p_deform_mesh_->insert_roi_vertex(*itr); 25 | } 26 | return true; 27 | } 28 | 29 | bool CgalArapDeform::SetRoiVertices() 30 | { 31 | 32 | for (auto itr = mesh_.vertices_begin(); itr != mesh_.vertices_end(); itr++) 33 | { 34 | p_deform_mesh_->insert_roi_vertex(itr); 35 | } 36 | return true; 37 | } 38 | 39 | bool CgalArapDeform::Deform() 40 | { 41 | p_deform_mesh_->deform(); 42 | return true; 43 | } 44 | 45 | bool CgalArapDeform::SetDeformMap(std::map& deform_handle_map) 46 | { 47 | for (auto itr = deform_handle_map.begin(); itr != deform_handle_map.end(); itr++) 48 | { 49 | p_deform_mesh_->insert_control_vertex(itr->first); 50 | } 51 | p_deform_mesh_->preprocess(); 52 | for (auto itr = deform_handle_map.begin(); itr != deform_handle_map.end(); itr++) 53 | { 54 | p_deform_mesh_->set_target_position(itr->first, itr->second); 55 | } 56 | return true; 57 | } -------------------------------------------------------------------------------- /Src/DataColle/aabb_type.h: -------------------------------------------------------------------------------- 1 | #ifndef CAABB_TYPE_H 2 | #define CAABB_TYPE_H 3 | #include"Polyhedron_type.h" 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include"custom_openmesh_type.h" 15 | namespace CGAL 16 | { 17 | template 18 | class AABB_tree; 19 | 20 | template 21 | class AABB_face_graph_triangle_primitive; 22 | 23 | template 24 | class AABB_traits; 25 | template 26 | class Aff_transformation_3; 27 | 28 | } 29 | typedef CGAL::AABB_face_graph_triangle_primitive Primitive; 30 | typedef CGAL::AABB_traits Traits; 31 | typedef CGAL::AABB_tree AABBTree; 32 | class CAABBTree { 33 | public: 34 | AABBTree *tree_=NULL; 35 | Polyhedron poly; 36 | std::vectorid_vh_map_; 37 | std::vectorid_fh_map_; 38 | CAABBTree() { 39 | tree_ = NULL; 40 | id_fh_map_.clear(); 41 | id_fh_map_.clear(); 42 | }; 43 | ~CAABBTree() { 44 | if (tree_ != NULL) 45 | { 46 | delete tree_; 47 | 48 | } 49 | } 50 | }; 51 | typedef Kernel::Ray_3 Ray; 52 | typedef boost::optional< AABBTree::Intersection_and_primitive_id::Type > Ray_intersection; 53 | typedef AABBTree::Point_and_primitive_id AABB_Point_and_primitive_id; 54 | #endif -------------------------------------------------------------------------------- /Src/TeethRootRecoAlg/dental_template_fitting.h: -------------------------------------------------------------------------------- 1 | #ifndef CDENTAL_TEMPLATE_FITTING_H 2 | #define CDENTAL_TEMPLATE_FITTING_H 3 | 4 | 5 | #include"prereq.h" 6 | #include"../DataColle/mesh_object.h" 7 | #include"../DataColle/teeth_template_object.h" 8 | #include 9 | class TEETHROOTRECOALG_CLASS CDentalTemplateFitting 10 | { 11 | public: 12 | static void RefineFittingTemplate(COpenMeshT &mesh_template, COpenMeshT &mesh_target); 13 | static void RefineCrownBoundaryAfterFitting(CMeshObject &mesh_crown, CMeshObject &teeth_template, std::map&temp_crown_map); 14 | static void ReplaceTemplateCrown(CMeshObject &teeth_template, CMeshObject &mesh_crown); 15 | static void AlignTemplate2Crown(CMeshObject &crown, OpenMesh::Vec3d front_dir,OpenMesh::Vec3d up_dir,CTeethTemplateObject& teeth_template); 16 | static void MergeBoundaryRegisteredMeshes(COpenMeshT &mesh_a, Eigen::Matrix4d mat_a, COpenMeshT&mesh_b, Eigen::Matrix4d mat_b,std::map&bound_map_a2b,COpenMeshT&res_mesh,std::vector&res_seam_vhs=std::vector()); 17 | static void LoadTemplates(std::string dirname, std::map&res_templates); 18 | static void ComputeStretchCrowns2LineMatrix(std::vector&crowns, std::vector&res_mats); 19 | static void ComputeCrownFrontDirs(std::vector&crowns, std::vector&res_front_dirs); 20 | static void OrderCrowns(std::vector&crowns,OpenMesh::Vec3d crown_updir, bool from_left2right); 21 | 22 | static void ComputeCrownsType(std::vectorcrowns,std::map&fixed_id, std::map&res_crown_type); 23 | 24 | 25 | }; 26 | #endif -------------------------------------------------------------------------------- /Src/AlgColle/numerical_base_alg.h: -------------------------------------------------------------------------------- 1 | #ifndef NUMERICAL_BASE_ALG_H 2 | #define NUMERICAL_BASE_ALG_H 3 | #include"prereq.h" 4 | #include 5 | #include 6 | #include 7 | #include"../DataColle/custom_openmesh_type.h" 8 | class ALGCOLLE_CLASS CNumericalBaseAlg 9 | { 10 | protected: 11 | static double PI; 12 | public: 13 | static double ComputeGaussian(double mean, double std_devi, double x); 14 | static double ComputeMean(std::vector&values); 15 | static double ComputeStdDeviation(std::vector&values); 16 | static void GetPlaneFromMeanAndDir(OpenMesh::Vec3d mean, OpenMesh::Vec3d dir,double & res_a,double &res_b,double &res_c,double &res_d); 17 | static void ComputeHistgram(Eigen::VectorXd &data, double bin_size, std::vector>&bins, std::vector>&bin_eles); 18 | static void NormalizeScalarField(Eigen::VectorXd &data); 19 | static void NormalizeScalarField(std::vector&data); 20 | template//T should have < 21 | static void ComputeOrder(std::vector&data, std::vector&res_order) 22 | { 23 | class CT 24 | { 25 | public: 26 | T data_; 27 | int id_; 28 | bool operator<(const CT&b) 29 | { 30 | return data_ < b.data_; 31 | } 32 | }; 33 | std::vector tmp_data; 34 | tmp_data.resize(data.size()); 35 | for (int i = 0; i < data.size(); i++) 36 | { 37 | tmp_data[i].data_ = data[i]; 38 | tmp_data[i].id_ = i; 39 | } 40 | std::sort(tmp_data.begin(), tmp_data.end()); 41 | res_order.resize(data.size()); 42 | for (int i = 0; i < res_order.size(); i++) 43 | { 44 | res_order[tmp_data[i].id_] = i; 45 | } 46 | } 47 | static void GetMaxValue(std::vector&data, int &res_id); 48 | static void GetMinValue(std::vector&data, int &res_id); 49 | static double Sigmoid(double x); 50 | }; 51 | #endif -------------------------------------------------------------------------------- /Src/AlgColle/rigid_icp.cpp: -------------------------------------------------------------------------------- 1 | #include"rigid_icp.h" 2 | #include"../AdditionalLibs/libicp/libicp_wrapper.h" 3 | #include"../DataColle/cgal_igl_converter.h" 4 | CRigidIcp::CRigidIcp(COpenMeshT* src_mesh) 5 | { 6 | src_mesh_ = src_mesh; 7 | } 8 | void CRigidIcp::FitTarget(COpenMeshT *tgt_mesh) 9 | { 10 | Eigen::MatrixXd src_vertexs, tgt_vertexs; 11 | Eigen::MatrixXi src_faces, tgt_faces; 12 | CConverter::ConvertFromOpenMeshToIGL(*src_mesh_, src_vertexs, src_faces); 13 | CConverter::ConvertFromOpenMeshToIGL(*tgt_mesh, tgt_vertexs, tgt_faces); 14 | //perform icp 15 | CIcpPoint2Point icp(tgt_vertexs); 16 | Eigen::Matrix3d rot; 17 | Eigen::Vector3d trans; 18 | Eigen::MatrixXd X;//transform matrix 19 | icp.Fit(src_vertexs, rot, trans); 20 | X.resize(src_vertexs.rows() * 4, 3); 21 | X.setZero(); 22 | rot.transposeInPlace(); 23 | Eigen::SparseMatrixD; 24 | D.resize(src_vertexs.rows(), src_vertexs.rows() * 4); 25 | std::vector < Eigen::Triplet>trip_d(0); 26 | 27 | for (int i = 0; i < src_vertexs.rows(); i++) 28 | { 29 | for (int j = 0; j < 3; j++) 30 | { 31 | trip_d.push_back(Eigen::Triplet(i, i * 4 + j, src_vertexs(i, j))); 32 | } 33 | trip_d.push_back(Eigen::Triplet(i, i * 4 + 3, 1)); 34 | } 35 | for (int i = 0; i < src_vertexs.rows(); i++) 36 | { 37 | for (int j = 0; j < 3; j++) 38 | { 39 | X(i * 4 + j, 0) = rot(j, 0); 40 | X(i * 4 + j, 1) = rot(j, 1); 41 | X(i * 4 + j, 2) = rot(j, 2); 42 | } 43 | X(i * 4 + 3, 0) = trans(0); 44 | X(i * 4 + 3, 1) = trans(1); 45 | X(i * 4 + 3, 2) = trans(2); 46 | } 47 | Eigen::MatrixXd transformed; 48 | transformed = (D*X).eval(); 49 | for (auto viter = src_mesh_->vertices_begin(); viter != src_mesh_->vertices_end(); viter++) 50 | { 51 | int id = viter->idx(); 52 | OpenMesh::Vec3d v(transformed(id, 0), transformed(id, 1), transformed(id, 2)); 53 | src_mesh_->set_point(viter, v); 54 | } 55 | } -------------------------------------------------------------------------------- /Src/AdditionalLibs/obb/Build.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************\ 2 | 3 | Copyright 1999 The University of North Carolina at Chapel Hill. 4 | All Rights Reserved. 5 | 6 | Permission to use, copy, modify and distribute this software and its 7 | documentation for educational, research and non-profit purposes, without 8 | fee, and without a written agreement is hereby granted, provided that the 9 | above copyright notice and the following three paragraphs appear in all 10 | copies. 11 | 12 | IN NO EVENT SHALL THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL BE 13 | LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR 14 | CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE 15 | USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY 16 | OF NORTH CAROLINA HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH 17 | DAMAGES. 18 | 19 | THE UNIVERSITY OF NORTH CAROLINA SPECIFICALLY DISCLAIM ANY 20 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE 22 | PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF 23 | NORTH CAROLINA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, 24 | UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 25 | 26 | The authors may be contacted via: 27 | 28 | US Mail: S. Gottschalk, E. Larsen 29 | Department of Computer Science 30 | Sitterson Hall, CB #3175 31 | University of N. Carolina 32 | Chapel Hill, NC 27599-3175 33 | 34 | Phone: (919)962-1749 35 | 36 | EMail: geom@cs.unc.edu 37 | 38 | 39 | \**************************************************************************/ 40 | 41 | #ifndef PQP_BUILD_H 42 | #define PQP_BUILD_H 43 | 44 | #include "PQP.h" 45 | 46 | int 47 | build_model(PQP_Model *m); 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /Src/AdditionalLibs/libicp/icpPointToPlane.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2011. All rights reserved. 3 | Institute of Measurement and Control Systems 4 | Karlsruhe Institute of Technology, Germany 5 | 6 | Authors: Andreas Geiger 7 | 8 | libicp is free software; you can redistribute it and/or modify it under the 9 | terms of the GNU General Public License as published by the Free Software 10 | Foundation; either version 2 of the License, or any later version. 11 | 12 | libicp is distributed in the hope that it will be useful, but WITHOUT ANY 13 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 14 | PARTICULAR PURPOSE. See the GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along with 17 | libicp; if not, write to the Free Software Foundation, Inc., 51 Franklin 18 | Street, Fifth Floor, Boston, MA 02110-1301, USA 19 | */ 20 | 21 | #ifndef ICP_POINT_TO_PLANE_H 22 | #define ICP_POINT_TO_PLANE_H 23 | 24 | #include "icp.h" 25 | 26 | class IcpPointToPlane : public Icp { 27 | 28 | public: 29 | 30 | IcpPointToPlane (double *M,const int32_t M_num,const int32_t dim,const int32_t num_neighbors=10,const double flatness=5.0) : Icp(M,M_num,dim) { 31 | M_normal = computeNormals(num_neighbors,flatness); 32 | } 33 | 34 | virtual ~IcpPointToPlane () { 35 | free(M_normal); 36 | } 37 | 38 | private: 39 | 40 | double fitStep (double *T,const int32_t T_num,ICPMatrix &R,ICPMatrix &t,const std::vector &active); 41 | std::vector getInliers (double *T,const int32_t T_num,const ICPMatrix &R,const ICPMatrix &t,const double indist); 42 | 43 | // utility functions to compute normals from the model tree 44 | void computeNormal (const kdtree::KDTreeResultVector &neighbors,double *M_normal,const double flatness); 45 | double* computeNormals (const int32_t num_neighbors,const double flatness); 46 | 47 | // normals of model points 48 | double *M_normal; 49 | }; 50 | 51 | #endif // ICP_POINT_TO_PLANE_H 52 | -------------------------------------------------------------------------------- /Src/HarmonicSegAlg/harmonic_field.h: -------------------------------------------------------------------------------- 1 | #ifndef CHARMONIC_FIELD_H 2 | #define CHARMONIC_FIELD_H 3 | #include"Eigen/Core" 4 | #include 5 | #include 6 | #include 7 | #include"../DataColle/custom_openmesh_type.h" 8 | #include"prereq.h" 9 | class HARMONICSEGALG_CLASS CHarmonicFieldSeg 10 | { 11 | protected: 12 | bool IsConcave(COpenMeshT &mesh, COpenMeshT::VertexHandle vh); 13 | void GetConcavityAwareLaplacianMatrix(COpenMeshT &mesh, std::vector>&triplets); 14 | 15 | public: 16 | void ComputeConcavityAwareHarmonicField(COpenMeshT&mesh, std::vector>&cons,Eigen::VectorXd &res_u); 17 | void SegOneTeeth(COpenMeshT&mesh, std::vector&vhs, std::vector&res_teeth); 18 | void SegTwoTooth(COpenMeshT&mesh, std::vector&vhs0, std::vector&vhs1, std::vector&res_teeth0, std::vector&res_teeth1); 19 | void RefineSegTwoTooth(COpenMeshT &mesh, std::vector&vhs0, std::vector&vhs1); 20 | void SegTwoSet(COpenMeshT&mesh, std::vector&vhs0, std::vector&vhs1, std::vector&res_vhs0, std::vector&res_vhs1); 21 | void SegToothGingiva(COpenMeshT&mesh, std::vector&vhs_tooth, std::vector&vhs_gingiva, std::vector&res_tooth, std::vector&res_gingiva); 22 | void RefineToothGingivaSeg(COpenMeshT&mesh, std::vector&tooth_vhs, std::vector&res_tooth); 23 | void RefineTeethGingivaSeg(COpenMeshT&mesh, std::vector&teeth_vhs, std::vector&res_teeth); 24 | void RefineTeethGingivaSeg(COpenMeshT &mesh, std::vector&teeth_mark);//teeth_mark:mark of each teeth, -1 means gingiva 25 | }; 26 | 27 | #endif -------------------------------------------------------------------------------- /Src/TeethStudio/imface_window.h: -------------------------------------------------------------------------------- 1 | // Copyright 2016_9 by ChenNenglun 2 | #ifndef IMFACE_WINDOW_H 3 | #define IMFACE_WINDOW_H 4 | 5 | #include 6 | #include 7 | #include "ui_imface.h" 8 | #include"cmodelviewer.h" 9 | #include 10 | #include 11 | #include 12 | #include "../TeethRootRecoAlg/teethProjection.h" 13 | 14 | class QImage; 15 | class NDTRegistration; 16 | 17 | class CMainWindow : public QMainWindow 18 | { 19 | Q_OBJECT 20 | 21 | public: 22 | CMainWindow(QWidget *parent = 0); 23 | ~CMainWindow(); 24 | 25 | CModelViewer* GetModelViewer(); 26 | void SetConnections(); 27 | void SetComponents(); 28 | void loadCrownData(); 29 | int test(); 30 | 31 | QLineEdit *id_7_; 32 | QLineEdit *id_6_; 33 | QLineEdit *id_5_; 34 | QLineEdit *id_4_; 35 | QLineEdit *id_3_; 36 | QLineEdit *id_2_; 37 | QLineEdit *id_1_; 38 | 39 | double image_crown_minW_, image_crown_maxW_; 40 | double projectiom_crown_minW_, projection_crown_maxW_; 41 | Eigen::Vector2d image_crown_center_; 42 | Eigen::Vector2d projection_crown_center_; 43 | std::map> projection_tooth_crown_; 44 | std::vector projection_teeth_crown_; 45 | std::map teeth_root_tip_; 46 | std::map>> map_toothId_map_meshId_tipLen_; 47 | std::vector> map_3dvertice_2dpoints_; 48 | protected: 49 | Ui::ImfaceWindow ui; 50 | QPushButton *push_template_kind; 51 | QPushButton *push_load_image_; 52 | protected: 53 | void UpdateRequest(); 54 | 55 | private slots: 56 | void pushTemplateKind(); 57 | void loadXImage(); 58 | private: 59 | CSingleTeethProjectionAction * single_teeth_projection_action_; 60 | PanoramicImageRegistration *panoramic_image_registration_; 61 | teethProjection * teeth_projection_; 62 | NDTRegistration *ndt_registration_; 63 | QImage *panoramic_image_; 64 | }; 65 | 66 | #endif // MY3DMM_H 67 | -------------------------------------------------------------------------------- /Src/DataColle/Polyhedron_type.h: -------------------------------------------------------------------------------- 1 | #ifndef POLYHEDRON_TYPE_H 2 | #define POLYHEDRON_TYPE_H 3 | 4 | // CGAL 5 | // kernel 6 | #include 7 | #include 8 | #include 9 | #include 10 | typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel; 11 | typedef CGAL::Exact_predicates_exact_constructions_kernel Exact_Kernel; 12 | // surface mesh 13 | #include 14 | #include 15 | //#include 16 | #include "Polyhedron_type_fwd.h" 17 | 18 | // simple geometric types 19 | typedef Kernel::FT FT; 20 | typedef Kernel::Line_3 Line; 21 | typedef Kernel::Point_3 Point; 22 | typedef Kernel::Plane_3 Plane; 23 | typedef Kernel::Sphere_3 Sphere; 24 | typedef Kernel::Vector_3 Vector; 25 | typedef Kernel::Triangle_3 Triangle; 26 | typedef Kernel::Iso_cuboid_3 Iso_cuboid; 27 | typedef Kernel::Plane_3 Plane_3; 28 | typedef Kernel::Point_2 Point_2; 29 | typedef Kernel::Vector_2 Vector_2; 30 | typedef Kernel::Segment_2 Segment_2; 31 | typedef CGAL::Bbox_3 Bbox_3; 32 | typedef CGAL::Bbox_2 Bbox_2; 33 | typedef Kernel::Line_2 Line_2; 34 | typedef Kernel::Segment_2 Segment_2; 35 | typedef Kernel::Segment_3 Segment_3; 36 | // surface mesh, Patch_id is pair 37 | //typedef CGAL::Mesh_polyhedron_3::type Polyhedron; 38 | 39 | 40 | typedef CGAL::Polyhedron_3 Polyhedron; 41 | 42 | 43 | typedef Polyhedron::Vertex_handle Vertex_handle; 44 | typedef Polyhedron::Halfedge_handle Halfedge_handle; 45 | typedef Polyhedron::Face_handle Face_handle; 46 | 47 | typedef std::vector Curve; 48 | typedef CGAL::Aff_transformation_3 AffTrans; 49 | /// Returns a normalized (unit) vector. 50 | /// @param v input vector. 51 | /// @return v normalized. 52 | inline Vector normalize(const Vector& v) { 53 | double len = sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]); 54 | return Vector(v[0] / len, v[1] / len, v[2] / len); 55 | } 56 | 57 | #endif // POLYHEDRON_TYPE_H 58 | -------------------------------------------------------------------------------- /Src/TeethStudio/ui_context.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2016_9 by ChenNenglun 2 | #include "ui_context.h" 3 | #include "scene.h" 4 | #include "imface_window.h" 5 | #include "texture_wrapper.h" 6 | CScene* CUIContext::scene_ = NULL; 7 | CMainWindow* CUIContext::main_window_ = NULL; 8 | int CUIContext::selected_mesh_object_id_ = -1; 9 | CMorphSkelDentalMeshSeg* CUIContext::msdm_seg_ = NULL; 10 | std::string CUIContext::cm_current_adjust_param_= "Curvature"; 11 | int CUIContext::color_stripe_texture_id_ = -1; 12 | int CUIContext::color_bar_texture_id_ = -1; 13 | std::mapCUIContext::textures_ = std::map(); 14 | int CUIContext::max_textures_id_ = 0; 15 | 16 | CScene* CUIContext::GetScene() 17 | { 18 | return scene_; 19 | } 20 | 21 | void CUIContext::SetSelectedMeshObjectId(int id) 22 | { 23 | selected_mesh_object_id_ = id; 24 | } 25 | 26 | int CUIContext::GetSelectedMeshObjectId() 27 | { 28 | if (DataPool::GetMeshObject(selected_mesh_object_id_) == NULL) 29 | { 30 | selected_mesh_object_id_ = -1; 31 | } 32 | return selected_mesh_object_id_; 33 | } 34 | 35 | void CUIContext::Init() 36 | { 37 | scene_ = new CScene(); 38 | main_window_ = new CMainWindow(); 39 | main_window_->show(); 40 | 41 | /*QImage color_stripe("stripe2.bmp"); 42 | color_stripe_texture_id_ = CUIContext::AddTexture(new QImage(color_stripe)); 43 | 44 | QImage color_bar("color.bmp"); 45 | color_bar_texture_id_ = CUIContext::AddTexture(new QImage(color_bar));*/ 46 | } 47 | 48 | int CUIContext::AddTexture(QImage *img) 49 | { 50 | TextureWraper *tw = new TextureWraper(*img); 51 | 52 | int id = tw->GetTextureId(); 53 | textures_.insert(std::make_pair(id, tw)); 54 | 55 | return id; 56 | } 57 | 58 | bool CUIContext::DeleteTextures(int id) 59 | { 60 | auto iter = textures_.find(id); 61 | if (iter != textures_.end()) 62 | { 63 | iter->second->ReleaseTexture(); 64 | textures_.erase(iter); 65 | return true; 66 | } 67 | return false; 68 | } 69 | 70 | TextureWraper* CUIContext::GetTexture(int id) 71 | { 72 | auto iter = textures_.find(id); 73 | if (iter != textures_.end()) 74 | { 75 | return iter->second; 76 | } 77 | return NULL; 78 | } 79 | -------------------------------------------------------------------------------- /Src/AdditionalLibs/obb/Tri.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************\ 2 | 3 | Copyright 1999 The University of North Carolina at Chapel Hill. 4 | All Rights Reserved. 5 | 6 | Permission to use, copy, modify and distribute this software and its 7 | documentation for educational, research and non-profit purposes, without 8 | fee, and without a written agreement is hereby granted, provided that the 9 | above copyright notice and the following three paragraphs appear in all 10 | copies. 11 | 12 | IN NO EVENT SHALL THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL BE 13 | LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR 14 | CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE 15 | USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY 16 | OF NORTH CAROLINA HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH 17 | DAMAGES. 18 | 19 | THE UNIVERSITY OF NORTH CAROLINA SPECIFICALLY DISCLAIM ANY 20 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE 22 | PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF 23 | NORTH CAROLINA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, 24 | UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 25 | 26 | The authors may be contacted via: 27 | 28 | US Mail: S. Gottschalk 29 | Department of Computer Science 30 | Sitterson Hall, CB #3175 31 | University of N. Carolina 32 | Chapel Hill, NC 27599-3175 33 | 34 | Phone: (919)962-1749 35 | 36 | EMail: geom@cs.unc.edu 37 | 38 | 39 | \**************************************************************************/ 40 | 41 | #ifndef PQP_TRI_H 42 | #define PQP_TRI_H 43 | 44 | #include "PQP_Compile.h" 45 | #define USING_MESH_MODEL1 46 | #ifndef USING_MESH_MODEL 47 | #define USING_POLYGONSOUP 48 | #endif 49 | struct Tri 50 | { 51 | #ifdef USING_POLYGONSOUP 52 | PQP_REAL p1[3]; 53 | PQP_REAL p2[3]; 54 | PQP_REAL p3[3]; 55 | #endif 56 | int id; 57 | }; 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /Src/TeethStudio/volume_data_segmentation_action.cpp: -------------------------------------------------------------------------------- 1 | #include"volume_data_segmentation_action.h" 2 | #include"ui_context.h" 3 | #include "qfiledialog.h" 4 | 5 | #include"cmodelviewer.h" 6 | #include"camera.h" 7 | #include 8 | #include"../DataColle/volume_data_object.h" 9 | #include"../DataColle/data_pool.h" 10 | #include"../DataColle/aux_geo_utils.h" 11 | #include"../DataColle/data_io.h" 12 | void CVolumeDataSegmentationAction::Init() 13 | { 14 | 15 | } 16 | void CVolumeDataSegmentationAction::MousePressEvent(QMouseEvent *e) 17 | { 18 | 19 | } 20 | void CVolumeDataSegmentationAction::MouseMoveEvent(QMouseEvent *e) 21 | { 22 | 23 | } 24 | void CVolumeDataSegmentationAction::MouseReleaseEvent(QMouseEvent *e) 25 | { 26 | 27 | } 28 | void CVolumeDataSegmentationAction::KeyPressEvent(QKeyEvent *e) 29 | { 30 | switch (e->key()) 31 | { 32 | 33 | // case Qt::Key_L: 34 | // { 35 | ///* CMeshObject *mesh_obj = new CMeshObject(); 36 | // 37 | // CAuxGeoUtils::GetVolumeRenderAuxCube(1, 1, 1, mesh_obj->GetMesh()); 38 | // DataPool::AddMeshObject(mesh_obj); 39 | // mesh_obj->SetMeshColor(OpenMesh::Vec3d(1, 0, 0)); 40 | // mesh_obj->SetChanged();*/ 41 | // std::cerr << "load volume data" << std::endl; 42 | // CVolumeDataObject *volume_data_obj = new CVolumeDataObject(); 43 | // DataPool::AddVolumeDataObject(volume_data_obj); 44 | // break; 45 | // } 46 | case Qt::Key_L: 47 | { 48 | QString path = QFileDialog::getExistingDirectory(NULL, "load volume data"); 49 | 50 | if (path.length() == 0) 51 | { 52 | std::cerr << "unable to load volume data\n" << std::endl; 53 | return; 54 | } 55 | CVolumeDataObject *volume_data_obj = new CVolumeDataObject(); 56 | CDataIO::ReadVolumeDataObjFromDICOMSeries(path.toStdString(), *volume_data_obj); 57 | DataPool::AddVolumeDataObject(volume_data_obj); 58 | volume_data_obj->SetChanged(); 59 | break; 60 | } 61 | case Qt::Key_Q: 62 | { 63 | std::cerr << "switch to common action" << std::endl; 64 | manager_->SetCurrentActionType(CActionType::Common); 65 | break; 66 | } 67 | } 68 | } 69 | void CVolumeDataSegmentationAction::KeyReleaseEvent(QKeyEvent *e) 70 | { 71 | 72 | } 73 | 74 | CVolumeDataSegmentationAction::CVolumeDataSegmentationAction() 75 | { 76 | type_ = VolumeDataSegmentation; 77 | } -------------------------------------------------------------------------------- /Src/AdditionalLibs/obb/GetTime.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************\ 2 | 3 | Copyright 1999 The University of North Carolina at Chapel Hill. 4 | All Rights Reserved. 5 | 6 | Permission to use, copy, modify and distribute this software and its 7 | documentation for educational, research and non-profit purposes, without 8 | fee, and without a written agreement is hereby granted, provided that the 9 | above copyright notice and the following three paragraphs appear in all 10 | copies. 11 | 12 | IN NO EVENT SHALL THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL BE 13 | LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR 14 | CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE 15 | USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY 16 | OF NORTH CAROLINA HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH 17 | DAMAGES. 18 | 19 | THE UNIVERSITY OF NORTH CAROLINA SPECIFICALLY DISCLAIM ANY 20 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE 22 | PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF 23 | NORTH CAROLINA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, 24 | UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 25 | 26 | The authors may be contacted via: 27 | 28 | US Mail: S. Gottschalk, E. Larsen 29 | Department of Computer Science 30 | Sitterson Hall, CB #3175 31 | University of N. Carolina 32 | Chapel Hill, NC 27599-3175 33 | 34 | Phone: (919)962-1749 35 | 36 | EMail: geom@cs.unc.edu 37 | 38 | 39 | \**************************************************************************/ 40 | 41 | #ifndef PQP_GETTIME_H 42 | #define PQP_GETTIME_H 43 | 44 | #define WIN32 true 45 | 46 | #ifdef WIN32 47 | 48 | #include 49 | inline 50 | double 51 | GetTime() 52 | { 53 | return (double)(clock()); 54 | } 55 | 56 | #else 57 | 58 | #include 59 | inline 60 | double 61 | GetTime() 62 | { 63 | struct timeval thistime; 64 | gettimeofday(&thistime, 0); 65 | return (thistime.tv_sec + thistime.tv_usec * 1e-6); 66 | } 67 | 68 | #endif 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /Src/TeethStudio/panoramic_image_registration.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #ifndef PANORAMIC_IMAGE_REGISTRATION_H_ 3 | #define PANORAMIC_IMAGE_REGISTRATION_H_ 4 | #include 5 | #include "ui_panoramic_image_registration.h" 6 | #include 7 | class QPushButton; 8 | class QLabel; 9 | class QImage; 10 | class QProgressBar; 11 | class QLineEdit; 12 | class NDTRegistration; 13 | using std::vector; 14 | #include"action_base.h" 15 | #include "../DataColle/mesh_object.h" 16 | #include 17 | #include 18 | #include 19 | 20 | class PanoramicImageRegistration : public QWidget 21 | { 22 | Q_OBJECT 23 | 24 | public: 25 | PanoramicImageRegistration(QWidget *parent = Q_NULLPTR); 26 | ~PanoramicImageRegistration(); 27 | void SetComponents(); 28 | void SetConnections(); 29 | void ShowBoundaryPointsInImage(); 30 | double scalse; 31 | std::vector b1; 32 | std::vector b2; // the boundary segmented from x-ray image 33 | Eigen::Vector2d b_c; // the center of the boundary in x-ray image 34 | Eigen::Vector2d b_c_P; // the center of the boundary in projection plane 35 | vector line_skeleton; //the skelon of the tooth 36 | 37 | public slots: 38 | void OnLoadPrimiticeImage(void); 39 | void OnLoadLabeledImage(void); 40 | void OnLoadOBJPoints(); 41 | void OnTransformAndRotateBoundaries(void); 42 | void OnRegisterWithNDTAlgorithm(void); 43 | void RegionGrow(cv::Mat &src, Eigen::Vector2d pt); 44 | 45 | private: 46 | Ui::PanoramicImageRegistration ui; 47 | 48 | private: 49 | QPushButton* button_load_primitive_image_; 50 | QPushButton* button_labeled_image_; 51 | QPushButton* button_load_obj_points_; 52 | QPushButton* button_boundaries_up_; 53 | QPushButton* button_boundaries_down_; 54 | QPushButton* button_boundaries_left_; 55 | QPushButton* button_boundaries_right_; 56 | QLineEdit* lineedit_cell_num_w_; 57 | QLineEdit* lineedit_cell_num_h_; 58 | QLineEdit* lineedit_cell_num_addition_w_; 59 | QLineEdit* lineedit_cell_num_addition_h_; 60 | QLineEdit* lineedit_cell_num_count_; 61 | QLineEdit* lineedit_max_iterator_times_; 62 | QPushButton* button_registering_with_NDT_algorithm_; 63 | QLabel* label_image_panel1_; 64 | QLabel* label_image_panel2_; 65 | 66 | private: 67 | NDTRegistration* ndt_registration_; 68 | QImage* primitive_image_; 69 | QImage* labeled_image_; 70 | }; 71 | 72 | #endif -------------------------------------------------------------------------------- /Projects/TeethRootRecoAlg/teethProjection.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #ifndef TEETH_PROJECTION 3 | #define TEETH_PROJECTION 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include "..\..\Src\DataColle\mesh_object.h" 10 | #include "..\..\Src\TeethRootRecoAlg\prereq.h" 11 | 12 | class TEETHROOTRECOALG_CLASS teethProjection 13 | { 14 | 15 | public: 16 | teethProjection(); 17 | static teethProjection* GetInstance(); 18 | static void DeleteInstance(); 19 | ~teethProjection(); 20 | public: 21 | void test(); 22 | double computeCurveValue(double y); 23 | double computeDerivateCurve(double y); 24 | double computeNeareastPointOfCurve(double y, OpenMesh::Vec3d & tooth_point); 25 | double computeLenghOfCurve(double min_i_y, double max_i_y, double y); 26 | bool setTeethMesh(std::map&sep_meshes); 27 | bool setCurveCeoffs(std::vector &ceoffs); 28 | bool curveDiscretization(); 29 | bool establishMeshCurveMap(double min_i_y_, double max_i_y_); 30 | bool computeProjectionImage(double min_i_y, double max_i_y); 31 | bool computeProjectionImageContour(); 32 | bool calculateTeethTop(std::map>>& map_toothId_map_meshId_tipLen_); 33 | bool sortTeethTop(); 34 | std::map> getProjectionImage(); 35 | std::map getTest(); 36 | std::vector> gettest1(); 37 | private: 38 | static teethProjection* instance_; 39 | //The mesh of each tooth 40 | std::mapsep_meshes_; 41 | //The ceofficient of the curve function 42 | std::vector curve_ceoffs_; 43 | //the map that connect each tooth mesh with the curve 44 | std::map> mesh_curve_map_; 45 | //the projection image 46 | std::map> projection_teeth_image_; 47 | //the contour of projection image 48 | std::map> projection_teeth_image_contour_; 49 | //the map between the 3D vertices and 2D virsual point 50 | std::vector> map_3dvertice_2dpoints_; 51 | std::map> judge_image_contour_; 52 | std::vector> map_vids_; 53 | std::map> map_toothId_map_meshId_tipLen_; 54 | std::map> map_toothId_map_verticeHandle_tipLen_; 55 | std::map map_toothId_TopPoint_; 56 | }; 57 | 58 | #endif 59 | 60 | -------------------------------------------------------------------------------- /Src/DataColle/teeth_template_object.cpp: -------------------------------------------------------------------------------- 1 | #include"teeth_template_object.h" 2 | 3 | CTeethTemplateObject::CTeethTemplateObject() 4 | { 5 | updir_ = OpenMesh::Vec3d(0, 1, 0); 6 | front_dir_ = OpenMesh::Vec3d(0, 0, 1); 7 | crown_fhs_.clear(); 8 | type_ = ""; 9 | crown_.clear(); 10 | } 11 | CTeethTemplateObject::CTeethTemplateObject(CTeethTemplateObject & template_object):CMeshObject(template_object) 12 | { 13 | 14 | updir_ = template_object.updir_; 15 | front_dir_ = template_object.front_dir_; 16 | crown_fhs_.clear(); 17 | 18 | for (int i = 0; i < template_object.crown_fhs_.size(); i++) 19 | { 20 | crown_fhs_.push_back(mesh_.face_handle(template_object.crown_fhs_[i].idx())); 21 | } 22 | ComputeCrownMesh(); 23 | 24 | } 25 | void CTeethTemplateObject::SetChanged(bool flag ) 26 | { 27 | CMeshObject::SetChanged(flag); 28 | 29 | } 30 | 31 | 32 | COpenMeshT& CTeethTemplateObject::GetCrownMesh() 33 | { 34 | if (crown_.n_vertices() == 0) 35 | { 36 | ComputeCrownMesh(); 37 | } 38 | return crown_; 39 | } 40 | std::map &CTeethTemplateObject::GetCrown2TempVhsMap() 41 | { 42 | if (crown_.n_vertices() == 0) 43 | { 44 | ComputeCrownMesh(); 45 | } 46 | return crown2tempvhs_map_; 47 | } 48 | void CTeethTemplateObject::ComputeCrownMesh() 49 | { 50 | std::cerr << "compute crown mesh" << std::endl; 51 | crown2tempvhs_map_.clear(); 52 | std::mapvhs_old2new_map; 53 | 54 | for (int i = 0; iTransformPointByLocalMatrix(mesh_.point(iter->first)); 70 | COpenMeshT::VertexHandle new_vh = crown_.add_vertex(p); 71 | iter->second= new_vh; 72 | 73 | crown2tempvhs_map_[new_vh] = iter->first; 74 | } 75 | for (int i = 0; i < crown_fhs_.size(); i++) 76 | { 77 | COpenMeshT::FaceHandle fh = crown_fhs_[i]; 78 | std::vectorvhs; 79 | for (auto viter = mesh_.fv_begin(fh); viter != mesh_.fv_end(fh); viter++) 80 | { 81 | vhs.push_back(vhs_old2new_map[viter]); 82 | } 83 | crown_.add_face(vhs); 84 | } 85 | 86 | 87 | 88 | } -------------------------------------------------------------------------------- /Src/DataColle/mesh_object.h: -------------------------------------------------------------------------------- 1 | // Copyright 2016_9 by ChenNenglun 2 | #ifndef MESH_OBJECT_H 3 | #define MESH_OBJECT_H 4 | #include"prereq.h" 5 | #include 6 | #include"base_object.h" 7 | #include 8 | #include 9 | #include"custom_openmesh_type.h" 10 | class CXWGeodesic; 11 | class CAABBTree; 12 | class CObbWrapper; 13 | class DATACOLLE_CLASS CMeshObject:public CBaseObject 14 | { 15 | protected: 16 | int mesh_id_;// id of mesh object 17 | bool is_changed_;//if the geometry of mesh is changed , it should be true, thus the opengl render will re-computeds 18 | double tot_surface_area_; 19 | int texture_id_; 20 | bool use_texture_; 21 | bool is_visiable_; 22 | std::mapvtag_; 23 | bool is_shinning_=false; 24 | bool is_pickable_ = true; 25 | std::maprestore_pos_;//the previous pos can be stored 26 | Eigen::Matrix4d restore_mat_; 27 | protected: 28 | COpenMeshT mesh_; 29 | 30 | 31 | CAABBTree* aabb_tree_=NULL; 32 | CXWGeodesic *geodesic_model_ = NULL; 33 | CObbWrapper *obb_wrapper_; 34 | 35 | public: 36 | void RestoreCurrentVPos(); 37 | void RecoverCurrentVPos(); 38 | std::map&GetVertexTags() { return vtag_; } 39 | bool& IsVisiable() { return is_visiable_; } 40 | bool &IsShinning() { return is_shinning_; } 41 | int GetId();//get id of mesh object 42 | void SetId(int id);//set id of mesh object 43 | bool IsChanged(); 44 | bool& IsPickAble() { return is_pickable_; } 45 | double GetTotSurfaceArea(); 46 | void SetChanged(bool is_changed=true); //if the geometry of mesh is changed, it should be true, and the opengl render will re - computes 47 | void SetAttrChanged(bool is_attrchanged = true); 48 | OpenMesh::Vec3d TransformPointToLocalMatrix(OpenMesh::Vec3d p); 49 | OpenMesh::Vec3d TransformPointByLocalMatrix(OpenMesh::Vec3d p); 50 | void CopyFrom(CMeshObject& b); 51 | bool& UseTexture() { return use_texture_; } 52 | COpenMeshT& GetMesh() { return mesh_; } 53 | void SetMesh(COpenMeshT& mesh); 54 | void SetMeshColor(OpenMesh::Vec3d color); 55 | void ApplyTransform(); 56 | CMeshObject(); 57 | CMeshObject(CMeshObject &b); 58 | ~CMeshObject(); 59 | 60 | 61 | 62 | void NormalizeUV(); 63 | CAABBTree* GetAABBTree() { return aabb_tree_; } 64 | void SetAABBTree(CAABBTree* t) { aabb_tree_ = t; } 65 | CObbWrapper* GetPqpObb() { return obb_wrapper_; } 66 | void SetPqpObb(CObbWrapper* t) { obb_wrapper_ = t; } 67 | 68 | CXWGeodesic*GetGeodesicModel() { return geodesic_model_; } 69 | void SetGeodesicModel(CXWGeodesic *model) { geodesic_model_ = model; } 70 | 71 | 72 | int& TextureId() { return texture_id_; } 73 | }; 74 | 75 | 76 | #endif -------------------------------------------------------------------------------- /Src/AlgColle/morph_skel_dental_mesh_seg.h: -------------------------------------------------------------------------------- 1 | #ifndef MORPH_SKEL_DENTAL_MESH_SEG_H 2 | #define MORPH_SKEL_DENTAL_MESH_SEG_H 3 | #include"prereq.h" 4 | #include"../DataColle/mesh_object.h" 5 | #include 6 | #include"../DataColle/geo_primit.h" 7 | #define DEBUG_MORPH_SKEL_DENTAL_MESH_SEG 8 | 9 | class ALGCOLLE_CLASS CMorphSkelDentalMeshSeg 10 | { 11 | public: 12 | enum CTag{Gingiva,Teeth,Feature,Non,Base}; 13 | protected://variables 14 | CMeshObject &mesh_obj_; 15 | bool verbose_ ; 16 | //Eigen::VectorXd vertex_penalty_weight_; 17 | public://params 18 | double curvature_threshold_; 19 | double small_region_threshold_; 20 | double small_teeth_region_percent_threshold_; 21 | Eigen::MatrixXd mean_curvature_vec_; 22 | Eigen::VectorXd mean_curvature_values_; 23 | CPlane cutting_plane_; 24 | std::vector edge_points_; 25 | std::vector edge_points_id_; 26 | std::vectoris_edge_point_; 27 | std::vector vertex_penalty_weight_; 28 | std::vectortags_; 29 | 30 | protected://functions 31 | void MarkBaseByPlane(CPlane plane, std::vector&v_bases); 32 | void ComputeCuttingPlane(); 33 | void ComputeMorphSkeleton(); 34 | void ComputeEdgePointsFromMeanCurvatureThreshold(double thre); 35 | void FindOptimizePlane(CPlane ini_plane,CPlane &res_plane); 36 | void ComputeVertexPenaltyWeight(); 37 | double ComputePenaltyValue(CPlane plane); 38 | void RemoveSmallFeatureRegions(); 39 | void TagGingiva(); 40 | void RemoveInnerTeethRegionInTeeth(); 41 | void RemoveGingiva2GingivaFeatureEdge(); 42 | 43 | void ResetEdgeVertexMarkFromTags(); 44 | double ComputeRegionArea(COpenMeshT::VertexHandle vh,CTag *glue_tag_=NULL); 45 | void TagRegion(std::vector&tags,COpenMeshT::VertexHandle vh, CTag tag, CTag *glue_tag_ = NULL); 46 | 47 | public: 48 | CMorphSkelDentalMeshSeg(CMeshObject &mesh_obj); 49 | ~CMorphSkelDentalMeshSeg(); 50 | 51 | void ComputeSegmentation(bool verbus=false); 52 | void AdjustBaseCuttingPlane(double l); 53 | void AdjustSmallRegionThreshold(double thre); 54 | void SetVertexTags(std::vector&vhs, std::vector&tags); 55 | void SwitchGingivaAndTeeth(COpenMeshT::VertexHandle vh); 56 | void RemoveSmallIsolateTeethRegion(); 57 | //////////////////////////////// 58 | void TestErode(); 59 | void TestDilate(); 60 | void TestSkeletonize(); 61 | void TestCurvature(); 62 | void TestRemoveSmallFeatureRegions(); 63 | void TestRender(); 64 | void TestTagGingiva(); 65 | double& TestGetCurvatureThreshold() { return curvature_threshold_; } 66 | double &TestGetSmallRegionThreshold() { return small_region_threshold_; } 67 | }; 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /Src/AdditionalLibs/lbfgs/Non_Linear_Optimization.cpp: -------------------------------------------------------------------------------- 1 | #include"Non_Linear_Optimization.h" 2 | #include "lbfgs.h" 3 | #include"Non_Linear_Optimization.h" 4 | 5 | Non_Linear_Optimization::Non_Linear_Optimization() : m_parameters(_defparam) 6 | { 7 | m_printprogress = true; 8 | } 9 | bool& Non_Linear_Optimization::GetPrintProgress() 10 | { 11 | return m_printprogress; 12 | } 13 | //return the number of iterations 14 | lbfgs_parameter_t& Non_Linear_Optimization::GetParameters() 15 | { 16 | return m_parameters; 17 | } 18 | 19 | int Non_Linear_Optimization::run() 20 | { 21 | /* 22 | Start the L-BFGS optimization; this will invoke the callback functions 23 | evaluate() and progress() when necessary. 24 | */ 25 | lbfgsfloatval_t fx = 0; 26 | int numOfIterations = 0; 27 | int ret = lbfgs(m_variables.size(), &m_variables[0], &fx, _evaluate, _progress, this, &m_parameters, &numOfIterations); 28 | 29 | /* Report the result. */ 30 | if (m_printprogress) 31 | std::cerr << "L-BFGS optimization terminated with status code = " << ret << std::endl; 32 | 33 | return numOfIterations; 34 | } 35 | 36 | int Non_Linear_Optimization::progress( 37 | const lbfgsfloatval_t *x, 38 | const lbfgsfloatval_t *g, 39 | const lbfgsfloatval_t fx, 40 | const lbfgsfloatval_t xnorm, 41 | const lbfgsfloatval_t gnorm, 42 | const lbfgsfloatval_t step, 43 | int n, 44 | int k, 45 | int ls 46 | ) 47 | { 48 | if (!m_printprogress) 49 | return 0; 50 | std::cerr << " Iteration #" << k << ": "; 51 | std::cerr << " Energy = " << fx << ", "; 52 | std::cerr << " step = " << step << ", "; 53 | std::cerr << " Error = " << gnorm / std::max(1.0, xnorm) << std::endl; 54 | for (int i = 0; i < n; ++i) 55 | { 56 | std::cerr << "x[" << i << "] = " << x[i] << ", "; 57 | } 58 | std::cerr << std::endl; 59 | std::cerr << "-----------------------------------------\n"; 60 | 61 | return 0; 62 | } 63 | 64 | int Non_Linear_Optimization::_progress( 65 | void *instance, 66 | const lbfgsfloatval_t *x, 67 | const lbfgsfloatval_t *g, 68 | const lbfgsfloatval_t fx, 69 | const lbfgsfloatval_t xnorm, 70 | const lbfgsfloatval_t gnorm, 71 | const lbfgsfloatval_t step, 72 | int n, 73 | int k, 74 | int ls 75 | ) 76 | { 77 | return reinterpret_cast(instance)->progress(x, g, fx, xnorm, gnorm, step, n, k, ls); 78 | } 79 | 80 | lbfgsfloatval_t Non_Linear_Optimization::_evaluate( 81 | void *instance, 82 | const lbfgsfloatval_t *x, 83 | lbfgsfloatval_t *g, 84 | const int n, 85 | const lbfgsfloatval_t step 86 | ) 87 | { 88 | if (reinterpret_cast(instance)->m_printprogress) 89 | std::cerr << "\tCall your evaluation function once..........\n"; 90 | return reinterpret_cast(instance)->evaluate(x, g, n, step); 91 | } -------------------------------------------------------------------------------- /Src/AdditionalLibs/obb/TriDist.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************\ 2 | 3 | Copyright 1999 The University of North Carolina at Chapel Hill. 4 | All Rights Reserved. 5 | 6 | Permission to use, copy, modify and distribute this software and its 7 | documentation for educational, research and non-profit purposes, without 8 | fee, and without a written agreement is hereby granted, provided that the 9 | above copyright notice and the following three paragraphs appear in all 10 | copies. 11 | 12 | IN NO EVENT SHALL THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL BE 13 | LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR 14 | CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE 15 | USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY 16 | OF NORTH CAROLINA HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH 17 | DAMAGES. 18 | 19 | THE UNIVERSITY OF NORTH CAROLINA SPECIFICALLY DISCLAIM ANY 20 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE 22 | PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF 23 | NORTH CAROLINA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, 24 | UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 25 | 26 | The authors may be contacted via: 27 | 28 | US Mail: E. Larsen 29 | Department of Computer Science 30 | Sitterson Hall, CB #3175 31 | University of N. Carolina 32 | Chapel Hill, NC 27599-3175 33 | 34 | Phone: (919)962-1749 35 | 36 | EMail: geom@cs.unc.edu 37 | 38 | 39 | \**************************************************************************/ 40 | 41 | #ifndef PQP_TRIDIST_H 42 | #define PQP_TRIDIST_H 43 | 44 | #include "PQP_Compile.h" 45 | 46 | // TriDist() 47 | // 48 | // computes the closest points on two triangles, and returns the 49 | // distance between them. 50 | // 51 | // s and t are the triangles, stored tri[point][dimension]. 52 | // 53 | // If the triangles are disjoint, p and q give the closest points of 54 | // s and t respectively. However, if the triangles overlap, p and q 55 | // are basically a random pair of points from the triangles, not 56 | // coincident points on the intersection of the triangles, as might 57 | // be expected. 58 | 59 | PQP_REAL 60 | TriDist(PQP_REAL p[3], PQP_REAL q[3], 61 | const PQP_REAL s[3][3], const PQP_REAL t[3][3]); 62 | 63 | //------------------------------------------------------------------ 64 | PQP_REAL 65 | PointTriDist(int *posFlag, PQP_REAL q[3], const PQP_REAL p[3], const PQP_REAL t[3][3]); 66 | 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /Projects/TeethRootRecoAlg/TeethRootRecoAlg.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | Header Files 20 | 21 | 22 | Header Files 23 | 24 | 25 | Header Files 26 | 27 | 28 | Header Files 29 | 30 | 31 | Header Files 32 | 33 | 34 | Header Files 35 | 36 | 37 | Header Files 38 | 39 | 40 | 41 | 42 | Source Files 43 | 44 | 45 | Source Files 46 | 47 | 48 | Source Files 49 | 50 | 51 | Source Files 52 | 53 | 54 | Source Files 55 | 56 | 57 | 58 | 59 | Resource Files 60 | 61 | 62 | -------------------------------------------------------------------------------- /Src/AdditionalLibs/libicp/demo.cpp: -------------------------------------------------------------------------------- 1 | ///* 2 | //Copyright 2011. All rights reserved. 3 | //Institute of Measurement and Control Systems 4 | //Karlsruhe Institute of Technology, Germany 5 | // 6 | //This file is part of libicp. 7 | //Authors: Andreas Geiger 8 | // 9 | //libicp is free software; you can redistribute it and/or modify it under the 10 | //terms of the GNU General Public License as published by the Free Software 11 | //Foundation; either version 3 of the License, or any later version. 12 | // 13 | //libicp is distributed in the hope that it will be useful, but WITHOUT ANY 14 | //WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 15 | //PARTICULAR PURPOSE. See the GNU General Public License for more details. 16 | // 17 | //You should have received a copy of the GNU General Public License along with 18 | //libicp; if not, write to the Free Software Foundation, Inc., 51 Franklin 19 | //Street, Fifth Floor, Boston, MA 02110-1301, USA 20 | //*/ 21 | // 22 | //// Demo program showing how libicp can be used 23 | // 24 | //#include 25 | //#include "icpPointToPlane.h" 26 | // 27 | //using namespace std; 28 | // 29 | //int main (int argc, char** argv) { 30 | // 31 | // // define a 3 dim problem with 10000 model points 32 | // // and 10000 template points: 33 | // int32_t dim = 3; 34 | // int32_t num = 10000; 35 | // 36 | // // allocate model and template memory 37 | // double* M = (double*)calloc(3*num,sizeof(double)); 38 | // double* T = (double*)calloc(3*num,sizeof(double)); 39 | // 40 | // // set model and template points 41 | // cout << endl << "Creating model with 10000 points ..." << endl; 42 | // cout << "Creating template by shifting model by (1,1,1) ..." << endl; 43 | // int32_t k=0; 44 | // for (double x=-2; x<2; x+=0.04) { 45 | // for (double y=-2; y<2; y+=0.04) { 46 | // double z=5*x*exp(-x*x-y*y); 47 | // M[k*3+0] = x; 48 | // M[k*3+1] = y; 49 | // M[k*3+2] = z; 50 | // T[k*3+0] = x-1; 51 | // T[k*3+1] = y-1; 52 | // T[k*3+2] = z-1; 53 | // k++; 54 | // } 55 | // } 56 | // 57 | // // start with identity as initial transformation 58 | // // in practice you might want to use some kind of prediction here 59 | // Matrix R = Matrix::eye(3); 60 | // Matrix t(3,1); 61 | // 62 | // // run point-to-plane ICP (-1 = no outlier threshold) 63 | // cout << endl << "Running ICP (point-to-plane, no outliers)" << endl; 64 | // IcpPointToPlane icp(M,num,dim); 65 | // icp.fit(T,num,R,t,-1); 66 | // 67 | // // results 68 | // cout << endl << "Transformation results:" << endl; 69 | // cout << "R:" << endl << R << endl << endl; 70 | // cout << "t:" << endl << t << endl << endl; 71 | // 72 | // // free memory 73 | // free(M); 74 | // free(T); 75 | // 76 | // // success 77 | // return 0; 78 | //} 79 | // 80 | -------------------------------------------------------------------------------- /Src/AdditionalLibs/XWGeodesic/ExactDGPMethod.h: -------------------------------------------------------------------------------- 1 | // ExactMethodForDGP.h: interface for the CExactDGPMethod class. 2 | // 3 | ////////////////////////////////////////////////////////////////////// 4 | 5 | #pragma once 6 | #include "EdgePoint.h" 7 | #include "RichModel.h" 8 | #include 9 | #include 10 | #include "DistanceApproach.h" 11 | using namespace std; 12 | 13 | 14 | class CExactDGPMethod : public CDistanceApproach 15 | { 16 | protected: 17 | struct InfoAtVertex 18 | { 19 | bool fParentIsPseudoSource; 20 | char birthTimeForCheckingValidity; 21 | int indexOfDirectParent; 22 | int indexOfRootVertOfDirectParent; 23 | int levelOnSequenceTree; 24 | int indexOfAncestor; 25 | double disUptodate; 26 | double entryProp; 27 | 28 | InfoAtVertex() 29 | { 30 | fParentIsPseudoSource = true; 31 | levelOnSequenceTree = -1; 32 | birthTimeForCheckingValidity = -1; 33 | indexOfDirectParent = -1; 34 | indexOfAncestor = -1; 35 | disUptodate = DBL_MAX; 36 | } 37 | EdgePoint GetEntryPoint() 38 | { 39 | EdgePoint ep; 40 | ep.isVertex = fParentIsPseudoSource; 41 | ep.index = indexOfDirectParent; 42 | ep.proportion = entryProp; 43 | return ep; 44 | } 45 | }; 46 | struct QuoteInfoAtVertex 47 | { 48 | char birthTime; 49 | int indexOfVert; 50 | double disUptodate; 51 | bool operator<(const QuoteInfoAtVertex& another) const 52 | { 53 | return disUptodate > another.disUptodate; 54 | } 55 | QuoteInfoAtVertex(){} 56 | QuoteInfoAtVertex(char birthTime, int indexOfVert, double disUptodate) 57 | { 58 | this->birthTime = birthTime; 59 | this->indexOfVert = indexOfVert; 60 | this->disUptodate = disUptodate; 61 | } 62 | }; 63 | 64 | 65 | protected: 66 | virtual void Initialize(); 67 | virtual void Dispose(); 68 | virtual void Propagate() = 0; 69 | virtual void CollectExperimentalResults(); 70 | public: 71 | vector m_InfoAtVertices; 72 | CExactDGPMethod(const CRichModel& inputModel, int source); 73 | CExactDGPMethod(const CRichModel& inputModel, int source, int destination); 74 | CExactDGPMethod(const CRichModel& inputModel, int source, double R); 75 | CExactDGPMethod(const CRichModel& inputModel, const map &indexOfSourceVerts); 76 | CExactDGPMethod(const CRichModel& inputModel, const map &indexOfSourceVerts, const set &destinations); 77 | CExactDGPMethod(const CRichModel& inputModel, const set &indexOfSourceVerts); 78 | CExactDGPMethod(const CRichModel& inputModel, const set &indexOfSourceVerts, double R); 79 | CExactDGPMethod(const CRichModel& inputModel, const set &indexOfSourceVerts, const set &destinations); 80 | virtual vector BacktraceShortestPath(int end) const; 81 | virtual int GetAncestor(int vIndex) const; 82 | }; 83 | 84 | 85 | 86 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /Src/TeethStudio/scene_volume_object.h: -------------------------------------------------------------------------------- 1 | #ifndef CSCENE_VOLUME_OBJECT_H 2 | #define CSCENE_VOLUME_OBJECT_H 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include"camera.h" 14 | #include"qopengltexture.h" 15 | #include"../DataColle/aux_geo_utils.h" 16 | #include"../DataColle/custom_openmesh_type.h" 17 | #include"../DataColle/volume_data_object.h" 18 | #include 19 | class CSceneVolumeObject :public QOpenGLFunctions_2_1 20 | { 21 | protected: 22 | 23 | std::weak_ptr volume_data_; 24 | int number_of_slices_; 25 | int slices_over_x_;//width 26 | int slices_over_y_;//height 27 | GLuint volume_data_texture_id_; 28 | 29 | COpenMeshT aux_cube_,aux_plane_; 30 | std::vector aux_cube_vertexs_pos_, aux_plane_vertexs_pos_;//data of opengl buffer,size:n x 3,n is the vertex number in mesh_ 31 | std::vectoraux_cube_tex_coords_, aux_plane_tex_coords_; 32 | 33 | QSize offscreen_frame_size_; 34 | 35 | mutable QOpenGLBuffer back_texcoord_aux_cube_vertex_pos_buffer_, back_texcoord_aux_cube_tex_coords_buffer_; 36 | mutable QOpenGLBuffer front_texcoord_aux_cube_vertex_pos_buffer_, front_texcoord_aux_cube_tex_coords_buffer_, front_texcoord_aux_plane_vertex_pos_buffer_, front_texcoord_aux_plane_tex_coords_buffer_; 37 | mutable QOpenGLBuffer depth_aux_cube_vertex_pos_buffer_, depth_aux_cube_tex_coords_buffer_; 38 | mutable QOpenGLBuffer volume_aux_cube_vertex_pos_buffer_; 39 | mutable QOpenGLVertexArrayObject back_texcoord_vao_, front_cube_texcoord_vao_, front_plane_texcoord_vao_, depth_vao_, volume_vao_; 40 | mutable QOpenGLShaderProgram back_texcoord_rendering_program_, front_texcoord_rendering_program_,depth_rendering_program_,volume_rendering_program_; 41 | 42 | 43 | QOpenGLFramebufferObject* back_texcoord_fbo_; 44 | QOpenGLFramebufferObject* front_texcoord_fbo_; 45 | 46 | void SetVolumeDataTextureFromVolumeData(); 47 | void SetBackTexcoordBufferFromElements(); 48 | void SetFrontTexcoordBufferFromElements(); 49 | void SetVolumeRenderBufferFromElements(); 50 | void RenderBackTexcoord(CCamera& camera); 51 | void RenderFrontTexcoord(CCamera& camera); 52 | void RenderVolumeData(CCamera&camera); 53 | void SetCommonRenderAttributes(QOpenGLShaderProgram &program, CCamera& camera); 54 | 55 | void GenBackTexcoordFrameBuffer(); 56 | void GenFrontTexcoordFrameBuffer(); 57 | public: 58 | void ComputeRenderingElements(CCamera camera); 59 | void SetGLBufferDataFromElements(); 60 | void InitShader(); 61 | CSceneVolumeObject(std::weak_ptr volumedata); 62 | ~CSceneVolumeObject(); 63 | void UpdateRenderInfo();// if the is_changed_ of mesh is seted, the opengl buffer will be updated 64 | 65 | void Render(CCamera camera); 66 | }; 67 | #endif -------------------------------------------------------------------------------- /Src/DataColle/Polyhedron_type_fwd.h: -------------------------------------------------------------------------------- 1 | #ifndef POLYHEDRON_TYPE_FWD_H 2 | #define POLYHEDRON_TYPE_FWD_H 3 | 4 | #include // for std::allocator 5 | #include // for std::pair 6 | #include 7 | 8 | #include 9 | #ifdef USE_FORWARD_DECL 10 | 11 | namespace CGAL { 12 | 13 | template < typename FT_ > 14 | struct Simple_cartesian; 15 | 16 | class Epick; 17 | class Epeck; 18 | 19 | class Polyhedron_items_3; 20 | 21 | template < class T, class I, class A> 22 | class HalfedgeDS_default; 23 | 24 | template < class PolyhedronTraits_3, 25 | class PolyhedronItems_3, 26 | template < class T, class I, class A> 27 | class T_HDS, 28 | class Alloc 29 | > 30 | class Polyhedron_3; 31 | 32 | template 33 | class Nef_polyhedron_3; 34 | 35 | class SNC_indexed_items; 36 | 37 | namespace Mesh_3 { 38 | template 39 | class Mesh_polyhedron_items; 40 | } // end namespace Mesh_3 41 | 42 | 43 | 44 | } // end namespace CGAL 45 | 46 | // kernel 47 | 48 | typedef CGAL::Epick Kernel; 49 | typedef CGAL::Epeck Exact_Kernel; 50 | 51 | typedef std::pair Patch_id; 52 | 53 | 54 | template < class Refs> 55 | class Halfedge_with_attributes : public CGAL::HalfedgeDS_halfedge_max_base_with_id 56 | { 57 | public: 58 | CGAL::Color color_; 59 | Kernel::Point_2 uv_ = Kernel::Point_2(0, 0); 60 | Kernel::Point_2 uv_spare_ = Kernel::Point_2(0, 0); 61 | }; 62 | 63 | class Polyhedron_items_with_attributes_3 :public CGAL::Polyhedron_items_with_id_3{ 64 | public: 65 | 66 | template < class Refs, class Traits> 67 | struct Halfedge_wrapper :public CGAL::Polyhedron_items_with_id_3::Halfedge_wrapper { 68 | typedef Halfedge_with_attributes Halfedge; 69 | }; 70 | }; 71 | 72 | 73 | // surface mesh 74 | //typedef CGAL::Polyhedron_3, 76 | // CGAL::HalfedgeDS_default, 77 | // std::allocator > Polyhedron; 78 | typedef CGAL::Polyhedron_3 > Polyhedron; 82 | //////////////////////////////////////////////////////////////// 83 | 84 | 85 | 86 | typedef CGAL::Nef_polyhedron_3 Nef_polyhedron; 87 | 88 | typedef std::vector Curve; 89 | 90 | typedef Kernel::Point_2 Point_2; 91 | 92 | 93 | 94 | 95 | 96 | #else // USE_FORWARD_DECL 97 | 98 | #include "Polyhedron_type.h" 99 | 100 | #endif // USE_FORWARD_DECL 101 | 102 | #endif // POLYHEDRON_TYPE_FWD_H 103 | -------------------------------------------------------------------------------- /Src/AdditionalLibs/libicp/icp.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2011. All rights reserved. 3 | Institute of Measurement and Control Systems 4 | Karlsruhe Institute of Technology, Germany 5 | 6 | Authors: Andreas Geiger 7 | 8 | libicp is free software; you can redistribute it and/or modify it under the 9 | terms of the GNU General Public License as published by the Free Software 10 | Foundation; either version 2 of the License, or any later version. 11 | 12 | libicp is distributed in the hope that it will be useful, but WITHOUT ANY 13 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 14 | PARTICULAR PURPOSE. See the GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along with 17 | libicp; if not, write to the Free Software Foundation, Inc., 51 Franklin 18 | Street, Fifth Floor, Boston, MA 02110-1301, USA 19 | */ 20 | 21 | #include "icp.h" 22 | 23 | using namespace std; 24 | 25 | Icp::Icp (double *M,const int32_t M_num,const int32_t dim) : 26 | dim(dim), max_iter(200), min_delta(1e-4) { 27 | 28 | // check for correct dimensionality 29 | if (dim!=2 && dim!=3) { 30 | cout << "ERROR: LIBICP works only for data of dimensionality 2 or 3" << endl; 31 | M_tree = 0; 32 | return; 33 | } 34 | 35 | // check for minimum number of points 36 | if (M_num<5) { 37 | cout << "ERROR: LIBICP works only with at least 5 model points" << endl; 38 | M_tree = 0; 39 | return; 40 | } 41 | 42 | // copy model points to M_data 43 | M_data.resize(boost::extents[M_num][dim]); 44 | for (int32_t m=0; m active; 73 | if (indist<=0) { 74 | active.clear(); 75 | for (int32_t i=0; i &active) { 86 | 87 | // check if we have at least 5 active points 88 | if (active.size()<5) 89 | return; 90 | 91 | // iterate until convergence 92 | for (int32_t iter=0; iter m_scalarField; 8 | double m_maxDisValue; 9 | double m_radius; 10 | const CRichModel& model; 11 | map m_sources; 12 | set m_destinations; 13 | string m_nameOfAlgorithm; 14 | __int64 m_maxLenOfQueue; 15 | __int64 m_depthOfResultingTree; 16 | 17 | __int64 m_nTotalMilliSeconds; 18 | protected: 19 | virtual void Initialize() = 0; 20 | virtual void Dispose() = 0; 21 | virtual void Propagate() = 0; 22 | virtual void CollectExperimentalResults() = 0; 23 | public: 24 | double m_memory; 25 | CDistanceApproach(const CRichModel& model, int source); 26 | CDistanceApproach(const CRichModel& model, int source, int destination); 27 | CDistanceApproach(const CRichModel& model, int source, double R); 28 | CDistanceApproach(const CRichModel& model, const map& sources); 29 | CDistanceApproach(const CRichModel& model, const map& sources, const set &destinations); 30 | CDistanceApproach(const CRichModel& model, const set& sources); 31 | CDistanceApproach(const CRichModel& model, const set& sources, double R); 32 | CDistanceApproach(const CRichModel& model, const set& sources, const set& destinations); 33 | public: 34 | virtual void Execute(); 35 | virtual vector BacktraceShortestPath(int end) const = 0; 36 | vector BacktraceIsoline(double val) const; 37 | virtual int GetAncestor(int vIndex) const = 0; 38 | double GetMaxDistance() const; 39 | virtual __int64 GetMaxLenOfQueue() const{return m_maxLenOfQueue;} 40 | virtual __int64 GetMaxPropagationLevels()const {return m_depthOfResultingTree;} 41 | string GetAlgorithmName() const; 42 | __int64 GetRunTime() const{return m_nTotalMilliSeconds;} 43 | double GetMemoryCost() const {return m_memory;} 44 | virtual void OutputExperimentalResults() const; 45 | const vector& GetDistanceField() const; 46 | //vector GetNormalizedDistanceField() const; 47 | //vector GetDistanceFieldDividedBy(double denominator) const; 48 | static vector DiffDistanceField(const vector& field1, 49 | const vector& field2); 50 | }; 51 | 52 | template 53 | pair> GetShortestPathBetween(const CRichModel& model, int source, int end) 54 | { 55 | set sources; 56 | sources.insert(source); 57 | set destinations; 58 | destinations.insert(end); 59 | 60 | T alg(model, sources, destinations); 61 | alg.Execute(); 62 | return make_pair(alg.GetDistanceField()[end], alg.BacktraceShortestPath(end)); 63 | } 64 | 65 | template 66 | double GetShortestDistanceBetween(const CRichModel& model, int source, int end) 67 | { 68 | set sources; 69 | sources.insert(source); 70 | set destinations; 71 | destinations.insert(end); 72 | 73 | T alg(model, sources, destinations); 74 | alg.Execute(); 75 | return alg.GetDistanceField()[end]; 76 | } 77 | -------------------------------------------------------------------------------- /Src/TeethRootRecoAlg/panoramic_fitting.h: -------------------------------------------------------------------------------- 1 | #ifndef CPANORAMIC_FITTING_H 2 | #define CPANORAMIC_FITTING_H 3 | #include"panoramic_simulation.h" 4 | #include "../AdditionalLibs/lbfgs/non_linear_optimization.h" 5 | #include 6 | #include 7 | #include"prereq.h" 8 | #include"opencv2\opencv.hpp" 9 | class CNDTEnergyComputer 10 | { 11 | protected: 12 | cv::Mat panoramic_img_; 13 | cv::Mat pan_grad_; 14 | int cell_num_w_; 15 | int cell_num_h_; 16 | std::vectorcell_weights_; 17 | 18 | std::vector cell_mean_points_; 19 | // covariance matrix for all cells 20 | std::vector cell_covariance_matrix_; 21 | // inverse matrix of covariance matrix for all cells 22 | std::vector cell_inverse_covariance_matrix_; 23 | void ComputeGradient(); 24 | bool ComputeCellCovarianceMatrix(); 25 | bool ComputeCellMeanPoints(); 26 | public: 27 | CNDTEnergyComputer(cv::Mat& panoramic_img); 28 | double ComputeNDTEnergy(std::vector&pts); 29 | 30 | void ChangeCellNum(int cell_num_w, int cell_num_h); 31 | }; 32 | 33 | 34 | class TEETHROOTRECOALG_CLASS CPanoramicFittingOptimization :public Non_Linear_Optimization 35 | { 36 | protected: 37 | enum FittingStage { InitialFitting, NTDRefine }; 38 | FittingStage fitting_stage_= InitialFitting; 39 | std::vector points_; 40 | std::vectortgt_proj_params_; 41 | std::vectorratio_tgt_proj_params_; 42 | CPanoramicProjectorBase &projector_; 43 | 44 | int proj_param_num_; 45 | double ComputeError(std::vector¶ms); 46 | CNDTEnergyComputer ndt_energy_computer_; 47 | 48 | double pano_size_w_; 49 | double pano_size_h_; 50 | 51 | 52 | double pano_scale_; 53 | OpenMesh::Vec2d pano_trans_; 54 | public: 55 | 56 | 57 | CPanoramicFittingOptimization(CPanoramicProjectorBase& projector, std::vector&points, std::vector&tgt_proj_params,cv::Mat &panoramic_img,double pano_size_w,double pano_size_h) :Non_Linear_Optimization(),projector_(projector), ndt_energy_computer_(panoramic_img) 58 | { 59 | pano_size_w_ = pano_size_w; 60 | pano_size_h_ = pano_size_h; 61 | m_variables.resize(6); 62 | 63 | projector.GetParams(m_variables); 64 | points_ = points; 65 | tgt_proj_params_ = tgt_proj_params; 66 | m_parameters.epsilon = 1e-6; 67 | ratio_tgt_proj_params_.resize(tgt_proj_params.size(), 0); 68 | for (int i = 1; i < tgt_proj_params.size(); i++) 69 | { 70 | ratio_tgt_proj_params_[i] = (tgt_proj_params[i][1] - tgt_proj_params[0][1]) / (tgt_proj_params[i][0] - tgt_proj_params[0][0] + 1e-7); 71 | } 72 | 73 | 74 | } 75 | void GetResProjector(CPanoramicProjectorBase&res_projector) 76 | { 77 | res_projector = projector_; 78 | } 79 | lbfgsfloatval_t evaluate( 80 | const lbfgsfloatval_t *x, 81 | lbfgsfloatval_t *g, 82 | const int n, 83 | const lbfgsfloatval_t step 84 | ); 85 | std::vector GetVariables() const 86 | { 87 | return m_variables; 88 | } 89 | void GetPanoScaleAndTrans(double &res_scale, OpenMesh::Vec2d &res_trans); 90 | void RunFitting(); 91 | }; 92 | 93 | #endif 94 | 95 | -------------------------------------------------------------------------------- /Src/DataColle/rplyfile.h: -------------------------------------------------------------------------------- 1 | #ifndef RPLY_FILE_H 2 | #define RPLY_FILE_H 3 | /* ---------------------------------------------------------------------- 4 | * RPly library, read/write PLY files 5 | * Diego Nehab, IMPA 6 | * http://www.impa.br/~diego/software/rply 7 | * 8 | * This library is distributed under the MIT License. See notice 9 | * at the end of this file. 10 | * ---------------------------------------------------------------------- */ 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | /* ---------------------------------------------------------------------- 17 | * Opens a PLY file for reading (fails if file is not a PLY file) 18 | * 19 | * file_pointer: FILE * to file open for reading 20 | * error_cb: error callback function 21 | * idata,pdata: contextual information available to users 22 | * 23 | * Returns 1 if successful, 0 otherwise 24 | * ---------------------------------------------------------------------- */ 25 | p_ply ply_open_from_file(FILE *file_pointer, p_ply_error_cb error_cb, 26 | long idata, void *pdata); 27 | 28 | /* ---------------------------------------------------------------------- 29 | * Creates new PLY file 30 | * 31 | * file_pointer: FILE * to a file open for writing 32 | * storage_mode: file format mode 33 | * error_cb: error callback function 34 | * idata,pdata: contextual information available to users 35 | * 36 | * Returns handle to PLY file if successfull, NULL otherwise 37 | * ---------------------------------------------------------------------- */ 38 | p_ply ply_create_to_file(FILE *file_pointer, e_ply_storage_mode storage_mode, 39 | p_ply_error_cb error_cb, long idata, void *pdata); 40 | 41 | #ifdef __cplusplus 42 | } 43 | #endif 44 | 45 | #endif /* RPLY_FILE_H */ 46 | 47 | /* ---------------------------------------------------------------------- 48 | * Copyright (C) 2003-2015 Diego Nehab. All rights reserved. 49 | * 50 | * Permission is hereby granted, free of charge, to any person obtaining 51 | * a copy of this software and associated documentation files (the 52 | * "Software"), to deal in the Software without restriction, including 53 | * without limitation the rights to use, copy, modify, merge, publish, 54 | * distribute, sublicense, and/or sell copies of the Software, and to 55 | * permit persons to whom the Software is furnished to do so, subject to 56 | * the following conditions: 57 | * 58 | * The above copyright notice and this permission notice shall be 59 | * included in all copies or substantial portions of the Software. 60 | * 61 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 62 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 63 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 64 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 65 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 66 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 67 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 68 | * ---------------------------------------------------------------------- */ 69 | -------------------------------------------------------------------------------- /Src/AdditionalLibs/libicp/icp.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2011. All rights reserved. 3 | Institute of Measurement and Control Systems 4 | Karlsruhe Institute of Technology, Germany 5 | 6 | Authors: Andreas Geiger 7 | 8 | libicp is free software; you can redistribute it and/or modify it under the 9 | terms of the GNU General Public License as published by the Free Software 10 | Foundation; either version 2 of the License, or any later version. 11 | 12 | libicp is distributed in the hope that it will be useful, but WITHOUT ANY 13 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 14 | PARTICULAR PURPOSE. See the GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along with 17 | libicp; if not, write to the Free Software Foundation, Inc., 51 Franklin 18 | Street, Fifth Floor, Boston, MA 02110-1301, USA 19 | */ 20 | 21 | #ifndef ICP_H 22 | #define ICP_H 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #include "matrix.h" 31 | #include "kdtree.h" 32 | 33 | class Icp { 34 | 35 | public: 36 | 37 | // constructor 38 | // input: M ....... pointer to first model point 39 | // M_num ... number of model points 40 | // dim ... dimensionality of model points (2 or 3) 41 | Icp (double *M,const int32_t M_num,const int32_t dim); 42 | 43 | // deconstructor 44 | virtual ~Icp (); 45 | 46 | // set maximum number of iterations (1. stopping criterion) 47 | void setMaxIterations (int32_t val) { max_iter = val; } 48 | 49 | // set minimum delta of rot/trans parameters (2. stopping criterion) 50 | void setMinDeltaParam (double val) { min_delta = val; } 51 | 52 | // fit template to model yielding R,t (M = R*T + t) 53 | // input: T ....... pointer to first template point 54 | // T_num ... number of template points 55 | // R ....... initial rotation matrix 56 | // t ....... initial translation vector 57 | // indist .. inlier distance (if <=0: use all points) 58 | // output: R ....... final rotation matrix 59 | // t ....... final translation vector 60 | void fit(double *T,const int32_t T_num,ICPMatrix &R,ICPMatrix &t,const double indist); 61 | 62 | private: 63 | 64 | // iterative fitting 65 | void fitIterate(double *T,const int32_t T_num,ICPMatrix &R,ICPMatrix &t,const std::vector &active); 66 | 67 | // inherited classes need to overwrite these functions 68 | virtual double fitStep(double *T,const int32_t T_num,ICPMatrix &R,ICPMatrix &t,const std::vector &active) = 0; 69 | virtual std::vector getInliers(double *T,const int32_t T_num,const ICPMatrix &R,const ICPMatrix &t,const double indist) = 0; 70 | 71 | protected: 72 | 73 | // kd tree of model points 74 | kdtree::KDTree* M_tree; 75 | kdtree::KDTreeArray M_data; 76 | 77 | int32_t dim; // dimensionality of model + template data (2 or 3) 78 | int32_t max_iter; // max number of iterations 79 | double min_delta; // min parameter delta 80 | }; 81 | 82 | #endif // ICP_H 83 | -------------------------------------------------------------------------------- /Src/AdditionalLibs/XWGeodesic/EdgePoint.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "RichModel.h" 3 | #include 4 | using namespace std; 5 | struct EdgePoint 6 | { 7 | bool isVertex; 8 | int index; 9 | double proportion; //[0 --> left endpoint; 1 --> right endpoint] 10 | EdgePoint() 11 | { 12 | index = -1; 13 | } 14 | EdgePoint(int index) : index(index), isVertex(true){} 15 | EdgePoint(int index, double proportion) : index(index), proportion(proportion), isVertex(false) {} 16 | EdgePoint(const CRichModel& model, int leftVert, int rightVert, double proportion) : proportion(proportion), isVertex(false) 17 | { 18 | index = model.GetEdgeIndexFromTwoVertices(leftVert, rightVert); 19 | } 20 | bool operator==(const EdgePoint& other) const 21 | { 22 | if (isVertex) 23 | return isVertex == other.isVertex && index == other.index; 24 | return isVertex == other.isVertex && index == other.index && proportion == other.proportion; 25 | } 26 | bool operator!=(const EdgePoint& other) const 27 | { 28 | return !(*this == other); 29 | } 30 | void Reverse(const CRichModel& model) 31 | { 32 | if (isVertex) 33 | return; 34 | index = model.Edge(index).indexOfReverseEdge; 35 | proportion = 1 - proportion; 36 | } 37 | double GetNumbering(const CRichModel& model, int faceID) const 38 | { 39 | if (isVertex) 40 | { 41 | for (int i = 0; i < 3; ++i) 42 | if (model.Face(faceID)[i] == index) 43 | return i; 44 | } 45 | EdgePoint copy(*this); 46 | if (model.Edge(copy.index).indexOfFrontFace != faceID) 47 | copy.Reverse(model); 48 | for (int i = 0; i < 3; ++i) 49 | { 50 | if (model.Edge(copy.index).indexOfLeftVert == model.Face(faceID)[i]) 51 | return i + copy.proportion; 52 | } 53 | return -1; 54 | } 55 | CPoint3D Get3DPoint(const CRichModel& model) const 56 | { 57 | if (isVertex) 58 | return model.Vert(index); 59 | return (1 - proportion) * model.Vert(model.Edge(index).indexOfLeftVert) 60 | + proportion * model.Vert(model.Edge(index).indexOfRightVert); 61 | } 62 | CPoint3D GetShiftPoint(const CRichModel& model) const 63 | { 64 | if (isVertex) 65 | return model.GetShiftVertex(index); 66 | return (1 - proportion) * model.GetShiftVertex(model.Edge(index).indexOfLeftVert) 67 | + proportion * model.GetShiftVertex(model.Edge(index).indexOfRightVert); 68 | } 69 | bool operator <(const EdgePoint& other) const 70 | { 71 | if (isVertex == false && other.isVertex == true) 72 | return true; 73 | if (isVertex == true && other.isVertex == false) 74 | return false; 75 | if (index < other.index) 76 | return true; 77 | if (index > other.index) 78 | return false; 79 | if (proportion < other.proportion) 80 | return true; 81 | if (proportion > other.proportion) 82 | return false; 83 | return false; 84 | } 85 | friend ostream& operator <<(ostream& out, const EdgePoint& ep) 86 | { 87 | if (ep.isVertex) 88 | out << "v " << ep.index << " "; 89 | else 90 | out << "e " << ep.index << " " << ep.proportion << " "; 91 | return out; 92 | } 93 | }; 94 | // 95 | //void SavePathToObj(const CRichModel& model, const vector& pl, const char* filename); 96 | //void SaveIsolineToObj(const CRichModel& model, const vector& isoline, const char* filename); 97 | -------------------------------------------------------------------------------- /Src/TeethStudio/cmodelviewer.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2016_9_25 by ChenNenglun 2 | #include "cmodelviewer.h" 3 | 4 | #include 5 | 6 | using namespace std; 7 | 8 | 9 | void CModelViewer::draw() 10 | { 11 | glClearColor(background_color_(0), background_color_(1), background_color_(2),1); 12 | if(scene_!=NULL) 13 | scene_->Render( camera_); 14 | 15 | } 16 | void CModelViewer::SetBackgroundColor(Eigen::Vector3d background_color) 17 | { 18 | background_color_ = background_color; 19 | } 20 | void CModelViewer::initializeGL() 21 | { 22 | 23 | 24 | QGLViewer::initializeGL(); 25 | 26 | initializeOpenGLFunctions(); 27 | 28 | 29 | 30 | } 31 | CModelViewer::CModelViewer(QWidget *parent) 32 | { 33 | background_color_ = Eigen::Vector3d(1, 1, 1); 34 | scene_ = NULL; 35 | init(); 36 | 37 | } 38 | void CModelViewer::InitCamera() 39 | { 40 | camera_.setType(qglviewer::Camera::Type::ORTHOGRAPHIC); 41 | //camera_.setAspectRatio(1); 42 | camera_.setPosition(qglviewer::Vec(0, 0, 10)); 43 | camera_.lookAt(qglviewer::Vec(0, 0, 0)); 44 | camera_.setUpVector(qglviewer::Vec(0, 1, 0)); 45 | camera_.setZClippingCoefficient(1000); 46 | std::cerr << "zclip " << camera_.zClippingCoefficient() << std::endl; 47 | } 48 | void CModelViewer::keyReleaseEvent(QKeyEvent*e) 49 | { 50 | action_manager_->KeyReleaseEvent(e); 51 | this->update(); 52 | } 53 | void CModelViewer::keyPressEvent(QKeyEvent *e) 54 | { 55 | action_manager_->KeyPressEvent(e); 56 | this->update(); 57 | 58 | } 59 | void CModelViewer::SetScene(CScene* scene) 60 | { 61 | scene_ = scene; 62 | } 63 | CModelViewer::~CModelViewer() 64 | { 65 | 66 | } 67 | void CModelViewer::mousePressEvent(QMouseEvent *e) 68 | { 69 | if (e->modifiers() == Qt::Modifier::CTRL) 70 | QGLViewer::mousePressEvent(e); 71 | 72 | action_manager_->MousePressEvent(e); 73 | this->update(); 74 | } 75 | void CModelViewer::mouseMoveEvent(QMouseEvent *e) 76 | { 77 | if (e->modifiers() == Qt::Modifier::CTRL) 78 | QGLViewer::mouseMoveEvent(e); 79 | 80 | action_manager_->MouseMoveEvent(e); 81 | this->update(); 82 | } 83 | void CModelViewer::mouseReleaseEvent(QMouseEvent *e) 84 | { 85 | if (e->modifiers() == Qt::Modifier::CTRL) 86 | QGLViewer::mouseMoveEvent(e); 87 | 88 | action_manager_->MouseReleaseEvent(e); 89 | this->update(); 90 | } 91 | void CModelViewer::mouseDoubleClickEvent(QMouseEvent *e) 92 | { 93 | action_manager_->MouseDoubleClickEvent(e); 94 | this->update(); 95 | } 96 | void CModelViewer::wheelEvent(QWheelEvent *e) 97 | { 98 | if (e->modifiers() == Qt::Modifier::CTRL) 99 | QGLViewer::wheelEvent(e); 100 | else 101 | action_manager_->WheelEvent(e); 102 | this->update(); 103 | } 104 | void CModelViewer::init() 105 | { 106 | InitCamera(); 107 | setCamera(&camera_); 108 | setMouseBinding(Qt::ControlModifier, Qt::LeftButton, QGLViewer::CAMERA, QGLViewer::ROTATE); 109 | setMouseBinding(Qt::ControlModifier, Qt::RightButton, QGLViewer::CAMERA, QGLViewer::TRANSLATE); 110 | //setMouseBinding(Qt::ControlModifier, Qt::MidButton, QGLViewer::CAMERA, QGLViewer::ZOOM); 111 | setWheelBinding(Qt::ControlModifier, QGLViewer::CAMERA, QGLViewer::ZOOM); 112 | 113 | action_manager_ = new CActionManager(); 114 | action_manager_->Init(this); 115 | } 116 | -------------------------------------------------------------------------------- /Src/TeethRootRecoAlg/ndt_registration.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #ifndef NDT_REGISTRATION_H_ 3 | #define NDT_REGISTRATION_H_ 4 | #include 5 | #include 6 | #include 7 | #include "prereq.h" 8 | using std::vector; 9 | 10 | class TEETHROOTRECOALG_CLASS NDTRegistration 11 | { 12 | public: 13 | ~NDTRegistration(); 14 | static NDTRegistration* GetInstance(); 15 | static void DeleteInstance(); 16 | bool SetPrimitiveImage(vector& image_data, 17 | const int image_width, const int image_height); 18 | int GetImageWidth(); 19 | int GetImageHeight(); 20 | vector& GetPrimitiveImage(); 21 | bool SetBoundaryPoints(vector& points); 22 | bool setBoundaryRootPoint(vector& boundary_points_root); 23 | vector& GetBoundaryPoints(); 24 | void SetBoundaryCenterPoints(Eigen::Vector2d & boundaryCenterPoints); 25 | bool SetCellPartitionParameters(const int cell_init_num_w, 26 | const int cell_init_num_h, const int cell_add_num_w, 27 | const int cell_add_num_h, const int cell_add_count); 28 | bool ComputeImageGradient(); 29 | bool ComputeCellMeanPoints(); 30 | bool ComputeCellCovarianceMatrix(); 31 | bool ComputeOneNDTRegister(); 32 | bool ExecuteNDTRegister(); 33 | bool SetMaxIteratorTimes(const int max_iterator_times); 34 | bool TransformAndRotateBoundaryPoints(int type, double distance); 35 | vector boundary_points_image_to_model; 36 | vector getImageGradient() { return image_gradient_; } 37 | 38 | private: 39 | NDTRegistration(); 40 | 41 | private: 42 | static NDTRegistration* instance_; 43 | // the image which points will be registered with 44 | vector primitive_image_; 45 | //the boundary points of the tooth root in x-ray image 46 | vector boundary_points_root; 47 | //The center point of the buodary in the x-ray image 48 | Eigen::Vector2d boundary_center_points_; 49 | // the points which will be registered with primitive image 50 | vector boundary_points_; 51 | // image gradient for primitive image 52 | vector image_gradient_; 53 | // the sum of gradient in all cells 54 | vector cell_weights_; 55 | // the mean points in all cells 56 | vector cell_mean_points_; 57 | // covariance matrix for all cells 58 | vector cell_covariance_matrix_; 59 | // inverse matrix of covariance matrix for all cells 60 | vector cell_inverse_covariance_matrix_; 61 | // the image width and height for primitive image 62 | int image_width_; 63 | int image_height_; 64 | // the cell num in width and height direction 65 | // for example, the width and height of primitive image is 66 | // 1000 and 800, and the cell num of width and height is 67 | // 100 and 100. So the size of every cell is 10 * 8 68 | int cell_num_w_; 69 | int cell_num_h_; 70 | // the initial cell num, for example, 40 * 40 71 | int cell_init_num_w_; 72 | int cell_init_num_h_; 73 | // the increment of cell num in one step, generally it's 10 * 10 74 | int cell_add_num_w_; 75 | int cell_add_num_h_; 76 | // the number of increment steps, for example, 6 77 | int cell_add_count_; 78 | // the maximum iterator times in one step 79 | int max_iterator_times_; 80 | 81 | Eigen::Matrix image_to_model_ro; 82 | Eigen::Matrix image_to_model_tra; 83 | int cell_add_count_end_; 84 | 85 | }; 86 | 87 | #endif -------------------------------------------------------------------------------- /Src/AdditionalLibs/XWGeodesic/Point3D.cpp: -------------------------------------------------------------------------------- 1 | #include "Point3D.h" 2 | #include "Parameters.h" 3 | CPoint3D::CPoint3D() 4 | { 5 | } 6 | 7 | CPoint3D::CPoint3D(double x, double y, double z) : x(x), y(y), z(z) 8 | { 9 | } 10 | 11 | CPoint3D operator +(const CPoint3D& pt1, const CPoint3D& pt2) 12 | { 13 | return CPoint3D(pt1.x + pt2.x, pt1.y + pt2.y, pt1.z + pt2.z); 14 | } 15 | 16 | CPoint3D operator -(const CPoint3D& pt1, const CPoint3D& pt2) 17 | { 18 | return CPoint3D(pt1.x - pt2.x, pt1.y - pt2.y, pt1.z - pt2.z); 19 | } 20 | 21 | CPoint3D operator *(const CPoint3D& pt, double times) 22 | { 23 | return CPoint3D(pt.x * times, pt.y * times, pt.z * times); 24 | } 25 | 26 | CPoint3D operator /(const CPoint3D& pt, double times) 27 | { 28 | return CPoint3D(pt.x / times, pt.y / times, pt.z / times); 29 | } 30 | 31 | CPoint3D operator *(double times, const CPoint3D& pt) 32 | { 33 | return CPoint3D(pt.x * times, pt.y * times, pt.z * times); 34 | } 35 | 36 | CPoint3D operator*(const CPoint3D& pt1, const CPoint3D& pt2) 37 | { 38 | return CPoint3D(pt1.y * pt2.z - pt1.z * pt2.y, 39 | pt1.z * pt2.x - pt1.x * pt2.z, 40 | pt1.x * pt2.y - pt1.y * pt2.x); 41 | } 42 | 43 | CPoint3D VectorCross(const CPoint3D& pt1, const CPoint3D& pt2, const CPoint3D& pt3) 44 | { 45 | return (pt2 - pt1) * (pt3 - pt2); 46 | } 47 | 48 | double operator ^(const CPoint3D& pt1, const CPoint3D& pt2) 49 | { 50 | return pt1.x * pt2.x + pt1.y * pt2.y + pt1.z * pt2.z; 51 | } 52 | 53 | double GetTriangleArea(const CPoint3D& pt1, const CPoint3D& pt2, const CPoint3D& pt3) 54 | { 55 | CPoint3D crossProduct = (pt2 - pt1) * (pt3 - pt2); 56 | return 0.5 * crossProduct.Len(); 57 | } 58 | 59 | double AngleBetween(const CPoint3D& pt1, const CPoint3D& pt2) 60 | { 61 | double cosAngle = (pt1 ^ pt2) / pt1.Len() / pt2.Len(); 62 | if (cosAngle >= 1) 63 | { 64 | cosAngle = 1; 65 | } 66 | else if (cosAngle <= -1) 67 | { 68 | cosAngle = -1; 69 | } 70 | return acos(cosAngle); 71 | } 72 | 73 | double AngleBetween(const CPoint3D& pt1, const CPoint3D& pt2, const CPoint3D& pt3) 74 | { 75 | CPoint3D u = pt2 - pt1; 76 | CPoint3D v = pt3 - pt2; 77 | double cosAngle = (u ^ v) / u.Len() / v.Len(); 78 | if (cosAngle >= 1) 79 | { 80 | cosAngle = 1; 81 | } 82 | else if (cosAngle <= -1) 83 | { 84 | cosAngle = -1; 85 | } 86 | return acos(cosAngle); 87 | } 88 | 89 | float VectorDot(const float* u, const float* v) 90 | { 91 | return u[0] * v[0] + u[1] * v[1] + u[2] * v[2]; 92 | } 93 | 94 | void VectorCross(const float* u, const float* v, float* n) 95 | { 96 | n[0] = u[1] * v[2] - u[2] * v[1]; 97 | n[1] = u[2] * v[0] - u[0] * v[2]; 98 | n[2] = u[0] * v[1] - u[1] * v[0]; 99 | } 100 | 101 | float AngleBetween(const float* u, const float* v) 102 | { 103 | float lenU = sqrt(u[0] * u[0] + u[1] * u[1] + u[2] * u[2]); 104 | float lenV = sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]); 105 | float dot = VectorDot(u, v) / lenU / lenV; 106 | if (dot < -1) 107 | dot = -1.0; 108 | if (dot > 1) 109 | dot = 1.0; 110 | return acos(dot); 111 | } 112 | 113 | CPoint3D CombinePointAndNormalTo(const CPoint3D& pt, const CPoint3D& normal) 114 | { 115 | return pt + normal * RateOfNormalShift; 116 | } 117 | 118 | CPoint3D CombineTwoNormalsTo(const CPoint3D& pt1, double coef1, const CPoint3D& pt2, double coef2) 119 | { 120 | return coef1 * pt1 + coef2 * pt2; 121 | } -------------------------------------------------------------------------------- /Src/TeethStudio/scene.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2016_9 by ChenNenglun 2 | #include"scene.h" 3 | #include 4 | 5 | CScene::CScene() 6 | { 7 | scene_mesh_.clear(); 8 | scene_curve_.clear(); 9 | 10 | } 11 | CScene::~CScene() 12 | { 13 | 14 | } 15 | 16 | void CScene::Render( CCamera camera) 17 | { 18 | UpdateScene(); 19 | for (auto iter = scene_mesh_.begin(); iter != scene_mesh_.end(); iter++) 20 | { 21 | iter->second->Render(camera); 22 | } 23 | for (auto iter = scene_curve_.begin(); iter != scene_curve_.end(); iter++) 24 | { 25 | iter->second->Render(camera); 26 | } 27 | 28 | for (auto iter = scene_volumedata_.begin(); iter != scene_volumedata_.end(); iter++) 29 | { 30 | iter->second->Render(camera); 31 | } 32 | } 33 | void CScene::UpdateScene() 34 | { 35 | auto mesh_obj_pool=DataPool::GetMeshObjectPool(); 36 | for (auto iter = mesh_obj_pool.begin(); iter != mesh_obj_pool.end(); iter++) 37 | { 38 | //find new mesh 39 | if (scene_mesh_.find(iter->first) == scene_mesh_.end()) 40 | { 41 | CSceneMeshObject *p_scene_mesh_obj=new CSceneMeshObject((std::weak_ptr)iter->second); 42 | scene_mesh_[iter->first] = p_scene_mesh_obj; 43 | } 44 | } 45 | std::vectormto_be_removed; 46 | for (auto iter = scene_mesh_.begin(); iter != scene_mesh_.end(); ++iter) 47 | { 48 | //need to be removed from scene 49 | if (mesh_obj_pool.find(iter->first) == mesh_obj_pool.end()) 50 | { 51 | mto_be_removed.push_back(iter->first); 52 | } 53 | } 54 | for (int i = 0; i < mto_be_removed.size(); i++) 55 | scene_mesh_.erase(mto_be_removed[i]); 56 | 57 | 58 | auto curve_obj_pool = DataPool::GetCurveObjectPool(); 59 | for (auto iter = curve_obj_pool.begin(); iter != curve_obj_pool.end(); iter++) 60 | { 61 | //find new mesh 62 | if (scene_curve_.find(iter->first) == scene_curve_.end()) 63 | { 64 | CSceneCurveObject *p_scene_curve_obj = new CSceneCurveObject((std::weak_ptr)iter->second); 65 | scene_curve_[iter->first] = p_scene_curve_obj; 66 | } 67 | } 68 | std::vectorcto_be_removed; 69 | for (auto iter = scene_curve_.begin(); iter != scene_curve_.end(); ++iter) 70 | { 71 | //need to be removed from scene 72 | if (curve_obj_pool.find(iter->first) == curve_obj_pool.end()) 73 | { 74 | cto_be_removed.push_back(iter->first); 75 | } 76 | } 77 | for (int i = 0; i < cto_be_removed.size(); i++) 78 | { 79 | scene_curve_.erase(cto_be_removed[i]); 80 | } 81 | 82 | 83 | 84 | auto volume_data_obj_pool = DataPool::GetVolumeDataObjectPool(); 85 | for (auto iter = volume_data_obj_pool.begin(); iter != volume_data_obj_pool.end(); iter++) 86 | { 87 | 88 | if (scene_volumedata_.find(iter->first) == scene_volumedata_.end()) 89 | { 90 | CSceneVolumeObject *p_scene_volumedata_obj = new CSceneVolumeObject((std::weak_ptr)iter->second); 91 | scene_volumedata_[iter->first] = p_scene_volumedata_obj; 92 | } 93 | } 94 | std::vectorvto_be_removed; 95 | for (auto iter = scene_volumedata_.begin(); iter != scene_volumedata_.end(); ++iter) 96 | { 97 | //need to be removed from scene 98 | if (scene_volumedata_.find(iter->first) == scene_volumedata_.end()) 99 | { 100 | vto_be_removed.push_back(iter->first); 101 | } 102 | } 103 | for (int i = 0; i < vto_be_removed.size(); i++) 104 | { 105 | scene_volumedata_.erase(vto_be_removed[i]); 106 | } 107 | } -------------------------------------------------------------------------------- /Src/TeethStudio/hot_key_action.cpp: -------------------------------------------------------------------------------- 1 | #include "hot_key_action.h" 2 | #include"ui_context.h" 3 | #include 4 | #include 5 | #include"../DataColle/data_io.h" 6 | #include"../AlgColle/geo_base_alg.h" 7 | #include"../DataColle/data_pool.h" 8 | #include"../AlgColle/geo_alg.h" 9 | #include"../DataColle/aux_geo_utils.h" 10 | #include"../AlgColle/morph_skel_dental_mesh_seg.h" 11 | #include "qfiledialog.h" 12 | #include"cmodelviewer.h" 13 | #include"action_manager.h" 14 | #include"../AlgColle/dental_base_alg.h" 15 | #include"imface_window.h" 16 | #include 17 | #include "panoramic_image_registration.h" 18 | 19 | void CHotKeyAction::KeyPressEvent(QKeyEvent *e) 20 | { 21 | 22 | switch (e->key()) 23 | { 24 | 25 | 26 | 27 | case Qt::Key_V: 28 | { 29 | manager_->SetCurrentActionType(VolumeDataSegmentation); 30 | std::cerr << "switch to volume segmentation action" << std::endl; 31 | break; 32 | 33 | } 34 | case Qt::Key_T://test panoramic simulation 35 | { 36 | manager_->SetCurrentActionType(CPanoramicSimulationTest); 37 | std::cerr << "switch to volume CPanoramicSimulationTest action" << std::endl; 38 | break; 39 | } 40 | case Qt::Key_H: 41 | { 42 | manager_->SetCurrentActionType(HarmonicFieldSegmentation); 43 | std::cerr << "switch to harmonic action" << std::endl; 44 | break; 45 | 46 | } 47 | case Qt::Key_P: 48 | { 49 | manager_->SetCurrentActionType(CTeethReconstructionTest); 50 | std::cerr << "switch to panoramia registration test action" << std::endl; 51 | break; 52 | } 53 | case Qt::Key_K: 54 | { 55 | manager_->SetCurrentActionType(CTeethReconstruction); 56 | std::cerr << "switch to panoramia registration action" << std::endl; 57 | break; 58 | } 59 | case Qt::Key_S: 60 | { 61 | PanoramicImageRegistration* panoramic_image_registration = 62 | new PanoramicImageRegistration(); 63 | panoramic_image_registration->show(); 64 | } 65 | 66 | case Qt::Key_1: 67 | { 68 | manager_->SetCurrentActionType(CSingleTeethProjection); 69 | std::cerr << "switch to single teeth projection!" << std::endl; 70 | 71 | } 72 | //case Qt::Key_M: 73 | //{ 74 | // manager_->SetCurrentActionType(EditFeatureEdge); 75 | // std::cerr << "switch to edit feature edge action" << std::endl; 76 | // break; 77 | //} 78 | 79 | //case Qt::Key_C: 80 | //{ 81 | // DataPool::DeleteAllCurveObjects(); 82 | // 83 | // break; 84 | //} 85 | 86 | /*case Qt::Key_R: 87 | { 88 | std::cerr << "test tri" << std::endl; 89 | std::vectorbounds,inner; 90 | bounds.push_back(Eigen::Vector3d(0, 0,0)); 91 | bounds.push_back(Eigen::Vector3d( 0.00898122,-1.0842e-19,0)); 92 | bounds.push_back(Eigen::Vector3d(0.00776125, 0.00372481, 0)); 93 | 94 | bounds.push_back(Eigen::Vector3d(0.00833388,0.00197644, 0)); 95 | bounds.push_back(Eigen::Vector3d(0.00490583 ,0.000803329, 0)); 96 | Eigen::MatrixXd res_v; 97 | Eigen::MatrixXi res_f; 98 | CGeoAlg::DelaunayTriangulation3d(bounds, res_v, res_f); 99 | 100 | igl::writeOBJ("test_tri.obj", res_v, res_f); 101 | break; 102 | }*/ 103 | //case Qt::Key_O:// 104 | //{ 105 | // std::cerr << "save" << std::endl; 106 | // int mid = CUIContext::GetSelectedMeshObjectId(); 107 | // auto p_mesh_object = DataPool::GetMeshObject(mid); 108 | // CDataIO::WriteMesh("Resources\\out.obj", *p_mesh_object); 109 | //} 110 | } 111 | } 112 | void CHotKeyAction::KeyReleaseEvent(QKeyEvent *e) 113 | { 114 | 115 | } -------------------------------------------------------------------------------- /Src/AdditionalLibs/obb/BV.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************\ 2 | 3 | Copyright 1999 The University of North Carolina at Chapel Hill. 4 | All Rights Reserved. 5 | 6 | Permission to use, copy, modify and distribute this software and its 7 | documentation for educational, research and non-profit purposes, without 8 | fee, and without a written agreement is hereby granted, provided that the 9 | above copyright notice and the following three paragraphs appear in all 10 | copies. 11 | 12 | IN NO EVENT SHALL THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL BE 13 | LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR 14 | CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE 15 | USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY 16 | OF NORTH CAROLINA HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH 17 | DAMAGES. 18 | 19 | THE UNIVERSITY OF NORTH CAROLINA SPECIFICALLY DISCLAIM ANY 20 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE 22 | PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF 23 | NORTH CAROLINA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, 24 | UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 25 | 26 | The authors may be contacted via: 27 | 28 | US Mail: E. Larsen 29 | Department of Computer Science 30 | Sitterson Hall, CB #3175 31 | University of N. Carolina 32 | Chapel Hill, NC 27599-3175 33 | 34 | Phone: (919)962-1749 35 | 36 | EMail: geom@cs.unc.edu 37 | 38 | 39 | \**************************************************************************/ 40 | 41 | #ifndef PQP_BV_H 42 | #define PQP_BV_H 43 | 44 | #include 45 | #include "Tri.h" 46 | #include "PQP_Compile.h" 47 | //#include "..\..\PolygonalMesh.h" 48 | 49 | struct BV 50 | { 51 | PQP_REAL R[3][3]; // orientation of RSS & OBB 52 | 53 | #if PQP_BV_TYPE & RSS_TYPE 54 | PQP_REAL Tr[3]; // position of rectangle 55 | PQP_REAL l[2]; // side lengths of rectangle 56 | PQP_REAL r; // radius of sphere summed with rectangle to form RSS 57 | #endif 58 | 59 | #if PQP_BV_TYPE & OBB_TYPE 60 | PQP_REAL To[3]; // position of obb 61 | PQP_REAL d[3]; // (half) dimensions of obb 62 | #endif 63 | 64 | int first_child; // positive value is index of first_child bv 65 | // negative value is -(index + 1) of triangle 66 | 67 | BV(); 68 | ~BV(); 69 | int Leaf() { return first_child < 0; } 70 | PQP_REAL GetSize(); 71 | void FitToTris(PQP_REAL O[3][3], Tri *tris, int num_tris); 72 | // void FitToTris(PQP_REAL O[3][3], PolygonalMesh *mesh, Tri *tris, int num_tris); 73 | }; 74 | 75 | inline 76 | PQP_REAL 77 | BV::GetSize() 78 | { 79 | #if PQP_BV_TYPE & RSS_TYPE 80 | return (sqrt(l[0]*l[0] + l[1]*l[1]) + 2*r); 81 | #else 82 | return (d[0]*d[0] + d[1]*d[1] + d[2]*d[2]); 83 | #endif 84 | } 85 | 86 | int 87 | BV_Overlap(PQP_REAL R[3][3], PQP_REAL T[3], BV *b1, BV *b2); 88 | 89 | #if PQP_BV_TYPE & RSS_TYPE 90 | PQP_REAL 91 | BV_Distance(PQP_REAL R[3][3], PQP_REAL T[3], BV *b1, BV *b2); 92 | 93 | PQP_REAL 94 | Point_BV_Distance(PQP_REAL R[3][3], PQP_REAL T[3], BV *b, PQP_REAL p[3]); 95 | 96 | #endif 97 | 98 | #endif 99 | 100 | 101 | -------------------------------------------------------------------------------- /Src/AdditionalLibs/XWGeodesic/BaseModel.h: -------------------------------------------------------------------------------- 1 | // BaseModel.h: interface for the CBaseModel class. 2 | // 3 | ////////////////////////////////////////////////////////////////////// 4 | #pragma once 5 | 6 | #include "Point3d.h" 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include"../prereq.h" 12 | using namespace std; 13 | 14 | class ADDITIONALLIBS_CLASS CBaseModel 15 | { 16 | public: 17 | CBaseModel(const string& filename); 18 | public: 19 | struct CFace 20 | { 21 | int verts[3]; 22 | CFace(){} 23 | CFace(int x, int y, int z) 24 | { 25 | verts[0] = x; 26 | verts[1] = y; 27 | verts[2] = z; 28 | } 29 | int& operator[](int index) 30 | { 31 | return verts[index]; 32 | } 33 | int operator[](int index) const 34 | { 35 | return verts[index]; 36 | } 37 | }; 38 | public: 39 | CBaseModel() {} 40 | vector m_Verts; 41 | vector m_Faces; 42 | vector m_NormalsToVerts; 43 | set m_UselessFaces; 44 | string m_filename; 45 | double m_scale; 46 | 47 | protected: 48 | void NormalizeModel(); 49 | void ReadMFile(const string& filename); 50 | void ReadFile(const string& filename); 51 | void ReadObjFile(const string& filename); 52 | void ReadOffFile(const string& filename); 53 | void ComputeScaleAndNormals(); 54 | public: 55 | virtual void LoadModel(); 56 | int GetVertexID(const CPoint3D& pt) const; 57 | void SaveMFile(const string& filename) const; 58 | void SaveOffFile(const string& filename) const; 59 | void SaveObjFile(const string& filename) const; 60 | void SaveScalarFieldObjFile(const vector& vals, const string& filename) const; 61 | void SaveScalarFieldObjFile(const vector& vals, double maxV, const string& filename) const; 62 | void SaveScalarFieldObjFile(const vector& vals, const string& comments, const string& filename) const; 63 | void SavePamametrizationObjFile(const vector>& uvs, const string& filename) const; 64 | void SavePamametrizationObjFile(const map>& uvs, const string& filename) const; 65 | 66 | static vector GetScalarField(const char* filename); 67 | static string GetComments(const char* filename); 68 | virtual void PrintInfo(ostream& out) const; 69 | virtual void Render() const; 70 | inline int GetNumOfVerts() const; 71 | inline int GetNumOfFaces() const; 72 | string GetFileShortName() const; 73 | string GetFileFullName() const; 74 | inline const CPoint3D& Vert(int vertIndex) const; 75 | inline const CPoint3D& Normal(int vertIndex) const; 76 | inline const CFace& Face(int faceIndex) const; 77 | CPoint3D GetShiftVertex(int indexOfVert) const; 78 | //CPoint3D ShiftVertex(int indexOfVert, double epsilon) const; 79 | double GetScale() const {return m_scale;} 80 | void SetFaces(const vector& faces); 81 | const vector& GetFaces() const; 82 | }; 83 | 84 | int CBaseModel::GetNumOfVerts() const 85 | { 86 | return (int)m_Verts.size(); 87 | } 88 | 89 | int CBaseModel::GetNumOfFaces() const 90 | { 91 | return (int)m_Faces.size(); 92 | } 93 | 94 | const CPoint3D& CBaseModel::Vert(int vertIndex) const 95 | { 96 | return m_Verts[vertIndex]; 97 | } 98 | 99 | const CPoint3D& CBaseModel::Normal(int vertIndex) const 100 | { 101 | return m_NormalsToVerts[vertIndex]; 102 | } 103 | 104 | const CBaseModel::CFace& CBaseModel::Face(int faceIndex) const 105 | { 106 | return m_Faces[faceIndex]; 107 | } 108 | 109 | -------------------------------------------------------------------------------- /Src/AdditionalLibs/obb/cpqp_obb_wrapper.cpp: -------------------------------------------------------------------------------- 1 | #include "cpqp_obb_wrapper.h" 2 | #include 3 | #include 4 | CPqpObb::CPqpObb(Eigen::MatrixXd& V, Eigen::MatrixXi& F) 5 | : V_(V),F_(F) 6 | { 7 | m_pqp_model.BeginModel(); 8 | int fcount = 0; 9 | PQP_REAL ps[3][3]; 10 | for (int i = 0; i < F.rows(); i++) 11 | { 12 | for (int j = 0; j id; 41 | qresult.distance = dres.distance; 42 | return qresult; 43 | } 44 | 45 | std::pair GetIntersectionPoint(const Eigen::Vector3d& pt1, const Eigen::Vector3d& pt2, const Eigen::Vector3d& pt3, 46 | const Eigen::Vector3d& pt, const Eigen::Vector3d& dir) 47 | { 48 | Eigen::MatrixXd M(4, 4); 49 | M << pt1.x(), pt2.x(), pt3.x(), -dir.x(), 50 | pt1.y(), pt2.y(), pt3.y(), -dir.y(), 51 | pt1.z(), pt2.z(), pt3.z(), -dir.z(), 52 | 1, 1, 1, 0; 53 | Eigen::VectorXd right(4); 54 | right << pt.x(), pt.y(), pt.z(), 1; 55 | Eigen::VectorXd res = M.inverse() * right; 56 | double t = res(3); 57 | return std::make_pair(pt + t * dir, t); 58 | } 59 | std::vector CPqpObb::QueryRay(const Eigen::Vector3d& pt, const Eigen::Vector3d& dir) 60 | { 61 | double M = 1000; 62 | Eigen::Vector3d start = pt + 1e-4 * dir; 63 | Eigen::Vector3d end = pt + M * dir; 64 | PQP_Model singleTriangle; 65 | singleTriangle.BeginModel(); 66 | PQP_REAL p1[3], p2[3], p3[3]; 67 | p1[0] = (PQP_REAL)(start.x()); 68 | p1[1] = (PQP_REAL)(start.y()); 69 | p1[2] = (PQP_REAL)(start.z()); 70 | p2[0] = (PQP_REAL)(end.x()); 71 | p2[1] = (PQP_REAL)(end.y()); 72 | p2[2] = (PQP_REAL)(end.z()); 73 | p3[0] = (PQP_REAL)(end.x()); 74 | p3[1] = (PQP_REAL)(end.y()); 75 | p3[2] = (PQP_REAL)(end.z()); 76 | singleTriangle.AddTri(p1, p2, p3, 0); 77 | singleTriangle.EndModel(); 78 | PQP_CollideResult result; 79 | PQP_REAL R1[3][3] = { 1, 0, 0, 0, 1, 0, 0, 0, 1 }; 80 | PQP_REAL T1[3] = { 0, 0, 0 }; 81 | PQP_REAL R2[3][3] = { 1, 0, 0, 0, 1, 0, 0, 0, 1 }; 82 | PQP_REAL T2[3] = { 0, 0, 0 }; 83 | int ret = PQP_Collide(&result, R1, T1, &m_pqp_model, R2, T2, &singleTriangle); 84 | std::vector intersections; 85 | for (int i = 0; i < result.num_pairs; ++i) 86 | { 87 | int fid=result.Id1(i); 88 | int count = 0; 89 | std::vectorvs; 90 | for (int j=0;j intersection = GetIntersectionPoint(vs[0],vs[1],vs[2],start, dir); 95 | intersections.push_back(CPqpObb::QueryResult(fid, 96 | intersection.second, intersection.first)); 97 | } 98 | std::sort(intersections.begin(), intersections.end()); 99 | return intersections; 100 | } -------------------------------------------------------------------------------- /Src/AlgColle/curve_base_alg.h: -------------------------------------------------------------------------------- 1 | #ifndef CCURVE_BASE_ALG_H 2 | #define CCURVE_BASE_ALG_H 3 | #include"../DataColle/curve_object.h" 4 | #include"../DataColle/geo_primit.h" 5 | #include"prereq.h" 6 | class ALGCOLLE_CLASS CCurveBaseAlg 7 | { 8 | public: 9 | //proj_dir contain 2 vectors spanned a planner space 10 | static void ProjectCurve2Plannar(std::vector&curve, std::vector proj_dir,std::vector&curve_2d);//proj_dir : 2d frame 11 | static void ComputeMeanOfCurve(std::vector&curve, OpenMesh::Vec3d &res_mean); 12 | static void ComputeBoundingBoxOf2dCurve(std::vector&curve,OpenMesh::Vec2d &bbox_min,OpenMesh::Vec2d &bbox_max); 13 | static double ResampleCurve(std::vector&curve, int num, bool is_closed = false); 14 | //static bool CurveResampling(std::vector p_curveobject); 15 | static OpenMesh::Vec2d ComputeCurveCenter(std::vector &curve); 16 | static bool ComputeCurveNormals(std::vector& p_curvebobj, std::vector &res_normal_list); 17 | static bool ComputeCurveNormals(std::vector& p_curvebobj, std::vector &res_normal_list); 18 | static double ComputeLenOfCurve(std::vector&curve,bool is_closed=false); 19 | static double ComputeScalarOnSegment(OpenMesh::Vec3d seg0, OpenMesh::Vec3d seg1, OpenMesh::Vec3d p, double s0, double s1); 20 | static void ComputeClosedCurveNormal(std::vector &curve, OpenMesh::Vec3d &normal); 21 | static void ComputeArclenParamOfAnchorPoints(std::vector&curve, std::vector>&anchors, std::vector&res_params,bool is_closed=false); 22 | static bool ComputeMatchingWithAnchorsFixed(std::vector&src_curve, std::vector>&src_anchor, std::vector&target_curve, std::vector>&target_anchor, std::vector>&correspond);//assume the anchors are ordered 23 | static double ComputeConvexity(std::vector&curve, int neighbor_num, std::vector&convexity, bool is_closed); 24 | static int ComputLocalMaximamConcavityPoints(std::vector&curve, int neighbor_num, int neighbor_num_for_convexity, std::vector&res_points); 25 | static int ComputLocalMinimalConcavityPoints(std::vector&curve, int neighbor_num, int neighbor_num_for_convexity, std::vector&res_points); 26 | 27 | static bool IsInRegion(std::vector®ion, OpenMesh::Vec2d p); 28 | static double ComputeLenOfCurve(std::vector&curve); 29 | static void ComputeClosestPoint(std::vector&curve, OpenMesh::Vec2d p, int &res_pid); 30 | static void ComputeClosestPoint(std::vector&curve, OpenMesh::Vec3d p, int &res_pid); 31 | static void ComputeNearestPoint(OpenMesh::Vec3d p, std::pair&seg, OpenMesh::Vec3d &res_p, double &res_dis); 32 | static void ComputeClosestPoint(std::vector&curve,bool is_closed, OpenMesh::Vec3d p, OpenMesh::Vec3d &res_p, int &res_pid); 33 | //fit polynomial , for example y=ax^3+bx^2+cx+d 34 | static void PolynomialFitting(std::vector&curve, int degree,std::vector&coeffs); 35 | static void SamplePointsOfPolynomial(std::vector&coeff, double min_x, double max_x, double seg_len,std::vector&res_points); 36 | static OpenMesh::Vec2d ComputePointOfPolynomial(std::vector&coedff, double x); 37 | static OpenMesh::Vec2d ComputeNormalOfPolynomial(std::vector&coeffs,double x); 38 | static OpenMesh::Vec2d ComputeNearestPoint2Polynomial(std::vector&coeff, OpenMesh::Vec2d p); 39 | }; 40 | #endif 41 | -------------------------------------------------------------------------------- /Src/TeethStudio/cvmatandqimage.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** Copyright (c) 2012-2015 Debao Zhang 3 | ** All right reserved. 4 | ** 5 | ** Permission is hereby granted, free of charge, to any person obtaining 6 | ** a copy of this software and associated documentation files (the 7 | ** "Software"), to deal in the Software without restriction, including 8 | ** without limitation the rights to use, copy, modify, merge, publish, 9 | ** distribute, sublicense, and/or sell copies of the Software, and to 10 | ** permit persons to whom the Software is furnished to do so, subject to 11 | ** the following conditions: 12 | ** 13 | ** The above copyright notice and this permission notice shall be 14 | ** included in all copies or substantial portions of the Software. 15 | ** 16 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | ** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | ** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | ** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | ** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | ** 24 | ****************************************************************************/ 25 | 26 | #ifndef CVMATANDQIMAGE_H 27 | #define CVMATANDQIMAGE_H 28 | 29 | #include 30 | #include 31 | 32 | namespace QtOcv { 33 | 34 | enum MatColorOrder { 35 | MCO_BGR, 36 | MCO_RGB, 37 | MCO_BGRA = MCO_BGR, 38 | MCO_RGBA = MCO_RGB, 39 | MCO_ARGB 40 | }; 41 | 42 | 43 | /* Convert QImage to/from cv::Mat 44 | * 45 | * - cv::Mat 46 | * - Supported channels 47 | * - 1 channel 48 | * - 3 channels (B G R), (R G B) 49 | * - 4 channels (B G R A), (R G B A), (A R G B) 50 | * - Supported depth 51 | * - CV_8U [0, 255] 52 | * - CV_16U [0, 65535] 53 | * - CV_32F [0, 1.0] 54 | * 55 | * - QImage 56 | * - All of the formats of QImage are supported. 57 | */ 58 | cv::Mat image2Mat(const QImage &img, int requiredMatType = CV_8UC(0), MatColorOrder requiredOrder=MCO_BGR); 59 | QImage mat2Image(const cv::Mat &mat, MatColorOrder order=MCO_BGR, QImage::Format formatHint = QImage::Format_Invalid); 60 | 61 | /* Convert QImage to/from cv::Mat without data copy 62 | * 63 | * - Supported QImage formats and cv::Mat types are: 64 | * - QImage::Format_Indexed8 <==> CV_8UC1 65 | * - QImage::Format_Alpha8 <==> CV_8UC1 66 | * - QImage::Format_Grayscale8 <==> CV_8UC1 67 | * - QImage::Format_RGB888 <==> CV_8UC3 (R G B) 68 | * - QImage::Format_RGB32 <==> CV_8UC4 (A R G B or B G R A) 69 | * - QImage::Format_ARGB32 <==> CV_8UC4 (A R G B or B G R A) 70 | * - QImage::Format_ARGB32_Premultiplied <==> CV_8UC4 (A R G B or B G R A) 71 | * - QImage::Format_RGBX8888 <==> CV_8UC4 (R G B A) 72 | * - QImage::Format_RGBA8888 <==> CV_8UC4 (R G B A) 73 | * - QImage::Format_RGBA8888_Premultiplied <==> CV_8UC4 (R G B A) 74 | * 75 | * - For QImage::Format_RGB32 ,QImage::Format_ARGB32 76 | * and QImage::Format_ARGB32_Premultiplied, the 77 | * color channel order of cv::Mat will be (B G R A) in little 78 | * endian system or (A R G B) in big endian system. 79 | * 80 | * - User must make sure that the color channels order is the same as 81 | * the color channels order requried by QImage. 82 | */ 83 | cv::Mat image2Mat_shared(const QImage &img, MatColorOrder *order=0); 84 | QImage mat2Image_shared(const cv::Mat &mat, QImage::Format formatHint = QImage::Format_Invalid); 85 | 86 | } //namespace QtOcv 87 | 88 | #endif // CVMATANDQIMAGE_H 89 | -------------------------------------------------------------------------------- /Src/AdditionalLibs/lbfgs/arithmetic_ansi.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ANSI C implementation of vector operations. 3 | * 4 | * Copyright (c) 2007-2010 Naoaki Okazaki 5 | * All rights reserved. 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in 15 | * all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | * THE SOFTWARE. 24 | */ 25 | 26 | /* $Id$ */ 27 | 28 | #include 29 | #include 30 | 31 | #if LBFGS_FLOAT == 32 && LBFGS_IEEE_FLOAT 32 | #define fsigndiff(x, y) (((*(uint32_t*)(x)) ^ (*(uint32_t*)(y))) & 0x80000000U) 33 | #else 34 | #define fsigndiff(x, y) (*(x) * (*(y) / fabs(*(y))) < 0.) 35 | #endif/*LBFGS_IEEE_FLOAT*/ 36 | 37 | inline static void* vecalloc(size_t size) 38 | { 39 | void *memblock = malloc(size); 40 | if (memblock) { 41 | memset(memblock, 0, size); 42 | } 43 | return memblock; 44 | } 45 | 46 | inline static void vecfree(void *memblock) 47 | { 48 | free(memblock); 49 | } 50 | 51 | inline static void vecset(lbfgsfloatval_t *x, const lbfgsfloatval_t c, const int n) 52 | { 53 | int i; 54 | 55 | for (i = 0;i < n;++i) { 56 | x[i] = c; 57 | } 58 | } 59 | 60 | inline static void veccpy(lbfgsfloatval_t *y, const lbfgsfloatval_t *x, const int n) 61 | { 62 | int i; 63 | 64 | for (i = 0;i < n;++i) { 65 | y[i] = x[i]; 66 | } 67 | } 68 | 69 | inline static void vecncpy(lbfgsfloatval_t *y, const lbfgsfloatval_t *x, const int n) 70 | { 71 | int i; 72 | 73 | for (i = 0;i < n;++i) { 74 | y[i] = -x[i]; 75 | } 76 | } 77 | 78 | inline static void vecadd(lbfgsfloatval_t *y, const lbfgsfloatval_t *x, const lbfgsfloatval_t c, const int n) 79 | { 80 | int i; 81 | 82 | for (i = 0;i < n;++i) { 83 | y[i] += c * x[i]; 84 | } 85 | } 86 | 87 | inline static void vecdiff(lbfgsfloatval_t *z, const lbfgsfloatval_t *x, const lbfgsfloatval_t *y, const int n) 88 | { 89 | int i; 90 | 91 | for (i = 0;i < n;++i) { 92 | z[i] = x[i] - y[i]; 93 | } 94 | } 95 | 96 | inline static void vecscale(lbfgsfloatval_t *y, const lbfgsfloatval_t c, const int n) 97 | { 98 | int i; 99 | 100 | for (i = 0;i < n;++i) { 101 | y[i] *= c; 102 | } 103 | } 104 | 105 | inline static void vecmul(lbfgsfloatval_t *y, const lbfgsfloatval_t *x, const int n) 106 | { 107 | int i; 108 | 109 | for (i = 0;i < n;++i) { 110 | y[i] *= x[i]; 111 | } 112 | } 113 | 114 | inline static void vecdot(lbfgsfloatval_t* s, const lbfgsfloatval_t *x, const lbfgsfloatval_t *y, const int n) 115 | { 116 | int i; 117 | *s = 0.; 118 | for (i = 0;i < n;++i) { 119 | *s += x[i] * y[i]; 120 | } 121 | } 122 | 123 | inline static void vec2norm(lbfgsfloatval_t* s, const lbfgsfloatval_t *x, const int n) 124 | { 125 | vecdot(s, x, x, n); 126 | *s = (lbfgsfloatval_t)sqrt(*s); 127 | } 128 | 129 | inline static void vec2norminv(lbfgsfloatval_t* s, const lbfgsfloatval_t *x, const int n) 130 | { 131 | vec2norm(s, x, n); 132 | *s = (lbfgsfloatval_t)(1.0 / *s); 133 | } 134 | -------------------------------------------------------------------------------- /Src/AlgColle/arap_deform.cpp: -------------------------------------------------------------------------------- 1 | #include"arap_deform.h" 2 | 3 | #include "cgal_arap_deform.h" 4 | #include 5 | //CARAPDeformation::CARAPDeformation(COpenMeshT& mesh):mesh_(mesh) 6 | //{ 7 | // 8 | // std::vectorid_fh_map; 9 | // CConverter::ConvertFromOpenMeshToIGL(mesh, v_, f_); 10 | // arap_data_.energy = igl::ARAP_ENERGY_TYPE_SPOKES; 11 | // arap_data_.max_iter = 100; 12 | // 13 | // 14 | //} 15 | //CARAPDeformation::~CARAPDeformation() 16 | //{ 17 | // 18 | //} 19 | ////bool CARAPDeformation::SetRoiVertices();//Set all of vertices on polyhedron as ROI 20 | ////{ 21 | //// 22 | ////} 23 | ////bool CARAPDeformation::SetRoiVertices(const std::vector& vertices_handle_vec);//Set specified vertices as ROI 24 | ////{ 25 | //// 26 | ////} 27 | //bool CARAPDeformation::SetDeformHandle(std::vector& deform_handles) 28 | //{ 29 | // deform_handles_ = deform_handles; 30 | // handle_id_.resize(deform_handles.size()); 31 | // for (int i = 0; i < deform_handles.size(); i++) 32 | // { 33 | // handle_id_(i)=deform_handles[i].idx(); 34 | // } 35 | // igl::arap_precomputation(v_, f_, v_.cols(), handle_id_, arap_data_); 36 | // handle_targt_.resize(handle_id_.rows(),v_.cols()); 37 | // return true; 38 | //} 39 | //bool CARAPDeformation::Deform(std::map&handle_map) 40 | //{ 41 | // std::cerr << "start arap deform" << std::endl; 42 | // for(int i=0;iidx(), 0), v_(viter->idx(), 1), v_(viter->idx(), 2)); 64 | // } 65 | // std::cerr << "end arap" << std::endl; 66 | // return true; 67 | //} 68 | 69 | 70 | CARAPDeformation::CARAPDeformation(COpenMeshT& mesh):mesh_(mesh) 71 | { 72 | std::map< COpenMeshT::VertexHandle, Polyhedron::Vertex_handle> vh_map; 73 | std::map fh_map; 74 | 75 | CConverter::ConvertFromOpenMeshToCGAL(mesh, poly_, vh_map, fh_map); 76 | set_halfedgeds_items_id(poly_); 77 | cgal_id_to_om_vh_map_.resize(mesh.n_vertices()); 78 | om_id_to_cgal_vh_map_.resize(mesh.n_vertices()); 79 | for(auto viter=mesh.vertices_begin();viter!=mesh.vertices_end();viter++) 80 | { 81 | cgal_id_to_om_vh_map_[vh_map[viter]->id()] = viter; 82 | om_id_to_cgal_vh_map_[viter->idx()] = vh_map[viter]; 83 | } 84 | cgal_arap_deform_ = new CgalArapDeform(poly_); 85 | cgal_arap_deform_->SetRoiVertices(); 86 | } 87 | CARAPDeformation::~CARAPDeformation() 88 | { 89 | if (cgal_arap_deform_ == NULL) 90 | delete cgal_arap_deform_; 91 | } 92 | 93 | bool CARAPDeformation::SetDeformMap(std::map& deform_handle_map) 94 | { 95 | std::mapcgal_deform_handle_map; 96 | for (auto iter = deform_handle_map.begin(); iter != deform_handle_map.end(); iter++) 97 | { 98 | cgal_deform_handle_map[om_id_to_cgal_vh_map_[iter->first.idx()]] =Point(iter->second[0], iter->second[1], iter->second[2]); 99 | } 100 | 101 | cgal_arap_deform_->SetDeformMap(cgal_deform_handle_map); 102 | return true; 103 | } 104 | 105 | 106 | bool CARAPDeformation::Deform() 107 | { 108 | cgal_arap_deform_->Deform(); 109 | for (auto viter = poly_.vertices_begin(); viter != poly_.vertices_end(); viter++) 110 | { 111 | Point p = viter->point(); 112 | OpenMesh::Vec3d om_p(p[0], p[1], p[2]); 113 | COpenMeshT::VertexHandle vh=cgal_id_to_om_vh_map_[viter->id()]; 114 | mesh_.point(vh) = om_p; 115 | } 116 | return true; 117 | } 118 | 119 | 120 | 121 | 122 | -------------------------------------------------------------------------------- /Src/AdditionalLibs/XWGeodesic/Point3D.h: -------------------------------------------------------------------------------- 1 | // Point3D.h: interface for the CPoint3D class. 2 | // 3 | ////////////////////////////////////////////////////////////////////// 4 | 5 | #pragma once 6 | #include 7 | #define _USE_MATH_DEFINES 8 | #include 9 | #include 10 | #include 11 | #include"../prereq.h" 12 | using namespace std; 13 | 14 | class ADDITIONALLIBS_CLASS CPoint3D 15 | { 16 | public: 17 | double x, y, z; 18 | CPoint3D(); 19 | CPoint3D(double x, double y, double z); 20 | inline CPoint3D& operator +=(const CPoint3D& pt); 21 | inline CPoint3D& operator -=(const CPoint3D& pt); 22 | inline CPoint3D& operator *=(double times); 23 | inline CPoint3D& operator /=(double times); 24 | inline CPoint3D Rotate() const; 25 | inline CPoint3D GetOrthogonalDir() const; 26 | inline double Len() const; 27 | inline void Normalize(); 28 | bool operator==(const CPoint3D& other) const 29 | { 30 | return x == other.x && y == other.y && z == other.z; 31 | } 32 | bool operator<(const CPoint3D& other) const 33 | { 34 | if (x < other.x) 35 | return true; 36 | else if (x > other.x) 37 | return false; 38 | else if (y < other.y) 39 | return true; 40 | else if (y > other.y) 41 | return false; 42 | else if (z < other.z) 43 | return true; 44 | else if (z > other.z) 45 | return false; 46 | return false; 47 | } 48 | friend ostream& operator<<(ostream& out, const CPoint3D& pt) 49 | { 50 | out << pt.x << " " << pt.y << " " << pt.z << endl; 51 | return out; 52 | } 53 | }; 54 | CPoint3D CPoint3D::Rotate() const 55 | { 56 | return CPoint3D(z, x, y); 57 | } 58 | 59 | CPoint3D& CPoint3D::operator +=(const CPoint3D& pt) 60 | { 61 | x += pt.x; 62 | y += pt.y; 63 | z += pt.z; 64 | return *this; 65 | } 66 | 67 | CPoint3D& CPoint3D::operator -=(const CPoint3D& pt) 68 | { 69 | x -= pt.x; 70 | y -= pt.y; 71 | z -= pt.z; 72 | return *this; 73 | } 74 | 75 | CPoint3D& CPoint3D::operator *=(double times) 76 | { 77 | x *= times; 78 | y *= times; 79 | z *= times; 80 | return *this; 81 | } 82 | 83 | CPoint3D& CPoint3D::operator /=(double times) 84 | { 85 | x /= times; 86 | y /= times; 87 | z /= times; 88 | return *this; 89 | } 90 | 91 | double CPoint3D::Len() const 92 | { 93 | return sqrt(x * x + y * y + z * z); 94 | } 95 | 96 | void CPoint3D::Normalize() 97 | { 98 | double len = Len(); 99 | x /= len; 100 | y /= len; 101 | z /= len; 102 | } 103 | 104 | CPoint3D CPoint3D::GetOrthogonalDir() const 105 | { 106 | vector vals; 107 | vals.push_back(x); 108 | vals.push_back(y); 109 | vals.push_back(z); 110 | int maxPos = max_element(vals.begin(), vals.end()) - vals.begin(); 111 | int minPos = min_element(vals.begin(), vals.end()) - vals.begin(); 112 | if (minPos == maxPos) 113 | minPos = (maxPos + 1) % 3; 114 | double tmp = vals[maxPos]; 115 | vals[maxPos] = -vals[minPos]; 116 | vals[minPos] = tmp; 117 | CPoint3D dir(vals[0], vals[1], vals[2]); 118 | dir.Normalize(); 119 | return dir; 120 | } 121 | 122 | CPoint3D operator +(const CPoint3D& pt1, const CPoint3D& pt2); 123 | CPoint3D operator -(const CPoint3D& pt1, const CPoint3D& pt2); 124 | CPoint3D operator *(const CPoint3D& pt, double times); 125 | CPoint3D operator /(const CPoint3D& pt, double times); 126 | CPoint3D operator *(double times, const CPoint3D& pt); 127 | CPoint3D operator *(const CPoint3D& pt1, const CPoint3D& pt2); 128 | CPoint3D VectorCross(const CPoint3D& pt1, const CPoint3D& pt2, const CPoint3D& pt3); 129 | double operator ^(const CPoint3D& pt1, const CPoint3D& pt2); 130 | double GetTriangleArea(const CPoint3D& pt1, const CPoint3D& pt2, const CPoint3D& pt3); 131 | double AngleBetween(const CPoint3D& pt1, const CPoint3D& pt2); 132 | double AngleBetween(const CPoint3D& pt1, const CPoint3D& pt2, const CPoint3D& pt3); 133 | void VectorCross(const float* u, const float* v, float * n); 134 | float VectorDot(const float* u, const float* v); 135 | float AngleBetween(const float* u, const float* v); 136 | CPoint3D CombinePointAndNormalTo(const CPoint3D& pt, const CPoint3D& normal); 137 | CPoint3D CombineTwoNormalsTo(const CPoint3D& pt1, double coef1, const CPoint3D& pt2, double coef2); --------------------------------------------------------------------------------