├── .gitattributes
├── .gitignore
├── 3rd_graphcut
├── 3rd_graphcut.vcxproj
├── 3rd_graphcut.vcxproj.filters
├── GCO_README.TXT
├── GCoptimization.cpp
├── GCoptimization.h
├── LinkedBlockList.cpp
├── LinkedBlockList.h
├── block.h
├── energy.h
├── example.cpp
├── graph.cpp
├── graph.h
└── maxflow.cpp
├── 3rd_qglviewer
├── 3rd_qglviewer.vcxproj
├── 3rd_qglviewer.vcxproj.filters
├── ImageInterface.cpp
├── ImageInterface.h
├── ImageInterface.ui
├── VRender
│ ├── AxisAlignedBox.h
│ ├── BSPSortMethod.cpp
│ ├── BackFaceCullingOptimizer.cpp
│ ├── EPSExporter.cpp
│ ├── Exporter.cpp
│ ├── Exporter.h
│ ├── FIGExporter.cpp
│ ├── NVector3.cpp
│ ├── NVector3.h
│ ├── Optimizer.h
│ ├── ParserGL.cpp
│ ├── ParserGL.h
│ ├── Primitive.cpp
│ ├── Primitive.h
│ ├── PrimitivePositioning.cpp
│ ├── PrimitivePositioning.h
│ ├── SortMethod.h
│ ├── TopologicalSortMethod.cpp
│ ├── Types.h
│ ├── VRender.cpp
│ ├── VRender.h
│ ├── Vector2.cpp
│ ├── Vector2.h
│ ├── Vector3.cpp
│ ├── Vector3.h
│ ├── VisibilityOptimizer.cpp
│ ├── gpc.cpp
│ └── gpc.h
├── VRenderInterface.ui
├── camera.cpp
├── camera.h
├── config.h
├── constraint.cpp
├── constraint.h
├── domUtils.h
├── frame.cpp
├── frame.h
├── keyFrameInterpolator.cpp
├── keyFrameInterpolator.h
├── manipulatedCameraFrame.cpp
├── manipulatedCameraFrame.h
├── manipulatedFrame.cpp
├── manipulatedFrame.h
├── mouseGrabber.cpp
├── mouseGrabber.h
├── qglviewer-icon.xpm
├── qglviewer.cpp
├── qglviewer.h
├── qglviewer_fr.qm
├── qglviewer_fr.ts
├── quaternion.cpp
├── quaternion.h
├── saveSnapshot.cpp
├── vec.cpp
└── vec.h
├── 3rd_ransac
├── 3rd_ransac.vcxproj
├── 3rd_ransac.vcxproj.filters
├── BasePrimitiveShape.h
├── Bitmap.cpp
├── Bitmap.h
├── BitmapPrimitiveShape.cpp
├── BitmapPrimitiveShape.h
├── CMakeLists.txt
├── Candidate.cpp
├── Candidate.h
├── Cone.cpp
├── Cone.h
├── ConePrimitiveShape.cpp
├── ConePrimitiveShape.h
├── ConePrimitiveShapeConstructor.cpp
├── ConePrimitiveShapeConstructor.h
├── Cylinder.cpp
├── Cylinder.h
├── CylinderPrimitiveShape.cpp
├── CylinderPrimitiveShape.h
├── CylinderPrimitiveShapeConstructor.cpp
├── CylinderPrimitiveShapeConstructor.h
├── FlatNormalThreshPointCompatibilityFunc.h
├── GfxTL
│ ├── AABox.h
│ ├── AABox.hpp
│ ├── AACube.h
│ ├── AACube.hpp
│ ├── AACubeTree.h
│ ├── AACubeTree.hpp
│ ├── AAKdTree.h
│ ├── AAKdTree.hpp
│ ├── AAPlane.h
│ ├── AAPlane.hpp
│ ├── Array.h
│ ├── ArrayArithmetic.h
│ ├── BBoxBuildInformationTreeStrategy.h
│ ├── BBoxDistanceKdTreeStrategy.h
│ ├── BaseTree.h
│ ├── BaseTree.hpp
│ ├── BucketSizeMaxLevelSubdivisionTreeStrategy.h
│ ├── BucketSizeSubdivisionTreeStrategy.h
│ ├── CellBBoxBuildInformationKdTreeStrategy.h
│ ├── CellCenterAACubeTreeStrategy.h
│ ├── CellLevelTreeStrategy.h
│ ├── CellParentTreeStrategy.h
│ ├── CellRangeDataTreeStrategy.h
│ ├── CellSizeDataTreeStrategy.h
│ ├── Covariance.h
│ ├── DynVectorKernel.h
│ ├── FaceNeighborAACubeTreeStrategy.h
│ ├── FlatCopyVector.h
│ ├── Frame.h
│ ├── HyperplaneCoordinateSystem.h
│ ├── ImmediateTreeDataKernels.h
│ ├── IncrementalDistanceKdTreeStrategy.h
│ ├── IndexedIterator.h
│ ├── IndexedTreeDataKernels.h
│ ├── IndexedTreeDataStrategy.h
│ ├── Jacobi.h
│ ├── KdTree.h
│ ├── KdTree.hpp
│ ├── L1Norm.h
│ ├── L2Norm.h
│ ├── LevelBuildInformationTreeStrategy.h
│ ├── LimitedHeap.h
│ ├── MathHelper.h
│ ├── MatrixXX.h
│ ├── MaxIntervalSplittingKdTreeStrategy.h
│ ├── MaxLevelSubdivisionTreeStrategy.h
│ ├── MaxNorm.h
│ ├── Mean.h
│ ├── NearestNeighbor.h
│ ├── NearestNeighbors.h
│ ├── NullClass.h
│ ├── NullStrategy.h
│ ├── NullStrategy.hpp
│ ├── NullTreeStrategy.h
│ ├── OnOff.h
│ ├── Orientation.h
│ ├── Plane.h
│ ├── Plane.hpp
│ ├── ScalarTypeConversion.h
│ ├── ScalarTypeDeferer.h
│ ├── ShuffleIndicesTreeDataKernelStrategy.h
│ ├── SlidingMidpointSplittingKdTreeStrategy.h
│ ├── StdContainerAdaptor.h
│ ├── StdOverrides.h
│ ├── Swap.h
│ ├── VectorKernel.h
│ ├── VectorXD.h
│ └── WeightFunc.h
├── Grid.h
├── IndexIterator.h
├── LevMarFitting.h
├── LevMarFunc.h
├── LevMarLSWeight.h
├── LowStretchSphereParametrization.cpp
├── LowStretchSphereParametrization.h
├── LowStretchTorusParametrization.cpp
├── LowStretchTorusParametrization.h
├── MiscLib
│ ├── AlignedAllocator.h
│ ├── NoShrinkVector.h
│ ├── Pair.h
│ ├── Performance.h
│ ├── Random.cpp
│ ├── Random.h
│ ├── RefCount.cpp
│ ├── RefCount.h
│ ├── RefCountPtr.h
│ ├── RefCounted.h
│ └── Vector.h
├── Octree.h
├── Plane.cpp
├── Plane.h
├── PlanePrimitiveShape.cpp
├── PlanePrimitiveShape.h
├── PlanePrimitiveShapeConstructor.cpp
├── PlanePrimitiveShapeConstructor.h
├── PointCloud.cpp
├── PointCloud.h
├── PrimitiveShape.h
├── PrimitiveShapeConstructor.h
├── PrimitiveShapeVisitor.h
├── RANSAC_orig in release does not work_Issue_523_CloudCompare.pdf
├── RansacShapeDetector.cpp
├── RansacShapeDetector.h
├── ReadMe.txt
├── RebuildAACubeTreeStrategy.h
├── ScoreAACubeTreeStrategy.h
├── ScoreComputer.h
├── ScorePrimitiveShapeVisitor.h
├── SimpleTorusParametrization.cpp
├── SimpleTorusParametrization.h
├── Sphere.cpp
├── Sphere.h
├── SpherePrimitiveShape.cpp
├── SpherePrimitiveShape.h
├── SpherePrimitiveShapeConstructor.cpp
├── SpherePrimitiveShapeConstructor.h
├── Torus.cpp
├── Torus.h
├── TorusPrimitiveShape.cpp
├── TorusPrimitiveShape.h
├── TorusPrimitiveShapeConstructor.cpp
├── TorusPrimitiveShapeConstructor.h
├── basic.h
├── solve.cpp
└── version.txt
├── DemoWithTestData
├── License.txt
├── example_1_pointcloud.ply
├── example_1_result.obj
├── example_1_video.wmv
├── example_2_pointcloud.ply
├── example_2_result.obj
└── example_2_video.wmv
├── License.txt
├── ManhattanModeler.sln
├── ManhattanModeler
├── BoundingBox.cpp
├── BoundingBox.h
├── CCube.cpp
├── CCube.h
├── CDlgAddPlane.cpp
├── CDlgAddPlane.h
├── CFittingBox.cpp
├── CFittingBox.h
├── CMeshObj.cpp
├── CMeshObj.h
├── CPointCloud.cpp
├── CPointCloud.h
├── CPolyHedron.cpp
├── CPolyHedron.h
├── CScanVertex.cpp
├── CScanVertex.h
├── CVector3D.cpp
├── CVector3D.h
├── CVertexGroup.cpp
├── CVertexGroup.h
├── CoordTransf.cpp
├── CoordTransf.h
├── DlgFittingBox.cpp
├── DlgFittingBox.h
├── DlgransacParam.cpp
├── DlgransacParam.h
├── ManhattanModeler.rc
├── ManhattanModeler.vcxproj
├── ManhattanModeler.vcxproj.filters
├── Parameters.cpp
├── Parameters.h
├── PlyLoad.cpp
├── PlyLoad.h
├── ProgressBar.cpp
├── ProgressBar.h
├── Resources
│ ├── ManhattanModeler.qrc
│ ├── exit.png
│ ├── fileopen.png
│ ├── filesave.png
│ ├── fullscreen.png
│ ├── home.png
│ ├── lighton.png
│ ├── manipulation.png
│ ├── snap_shot.png
│ ├── transparent.png
│ └── triangulation.png
├── basic_types.cpp
├── basic_types.h
├── color.cpp
├── color.h
├── counted.cpp
├── counted.h
├── dlgAddPln.ui
├── dlgFittingBox.ui
├── dlg_ransac_detection_parameters.cpp
├── dlg_ransac_detection_parameters.h
├── draw_model.h
├── fitBoxes.cpp
├── fitBoxes.h
├── ioFile.cpp
├── ioFile.h
├── kd_tree
│ ├── PriorityQueue.h
│ ├── QueryGrid.h
│ ├── kdTree.cpp
│ ├── kdTree.h
│ ├── vector2D.h
│ └── vector3D.h
├── logger.cpp
├── logger.h
├── logger_client.cpp
├── logger_client.h
├── main.cpp
├── main_window.cpp
├── main_window.h
├── main_window.ui
├── math_global.cpp
├── math_global.h
├── math_types.cpp
├── math_types.h
├── paint_canvas.cpp
├── paint_canvas.h
├── pgm_io.cpp
├── pgm_io.h
├── plyIO.h
├── ransacParam.ui
├── ransac_detector.cpp
├── ransac_detector.h
├── rply.c
├── rply.h
├── select_tool.cpp
├── select_tool.h
├── simpleWidget.cpp
├── simpleWidget.h
├── smart_pointer.h
├── tool3D.cpp
├── tool3D.h
├── tool_manager3d.cpp
├── tool_manager3d.h
├── tool_name.h
└── tree_item.h
└── ReadMe.md
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .vs
2 | Debug\*.*
3 | Release\*.*
4 | *.tlog
5 | *.recipe
6 | *.user
7 | *.log
8 |
--------------------------------------------------------------------------------
/3rd_graphcut/3rd_graphcut.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;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
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 | Source Files
23 |
24 |
25 | Source Files
26 |
27 |
28 | Source Files
29 |
30 |
31 | Source Files
32 |
33 |
34 |
35 |
36 | Header Files
37 |
38 |
39 | Header Files
40 |
41 |
42 | Header Files
43 |
44 |
45 | Header Files
46 |
47 |
48 | Header Files
49 |
50 |
51 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/3rd_graphcut/LinkedBlockList.cpp:
--------------------------------------------------------------------------------
1 | #include "LinkedBlockList.h"
2 | #include
3 | #include
4 |
5 | /*********************************************************************/
6 |
7 | void LinkedBlockList::addFront(ListType item) {
8 |
9 | if ( m_head_block_size == GCLL_BLOCK_SIZE )
10 | {
11 | LLBlock *tmp = (LLBlock *) new LLBlock;
12 | if ( !tmp ) {printf("\nOut of memory");exit(1);}
13 | tmp -> m_next = m_head;
14 | m_head = tmp;
15 | m_head_block_size = 0;
16 | }
17 |
18 | m_head ->m_item[m_head_block_size] = item;
19 | m_head_block_size++;
20 | }
21 |
22 | /*********************************************************************/
23 |
24 | ListType LinkedBlockList::next()
25 | {
26 | ListType toReturn = m_cursor -> m_item[m_cursor_ind];
27 |
28 | m_cursor_ind++;
29 |
30 | if ( m_cursor == m_head && m_cursor_ind >= m_head_block_size )
31 | {
32 | m_cursor = m_cursor ->m_next;
33 | m_cursor_ind = 0;
34 | }
35 | else if ( m_cursor_ind == GCLL_BLOCK_SIZE )
36 | {
37 | m_cursor = m_cursor ->m_next;
38 | m_cursor_ind = 0;
39 | }
40 | return(toReturn);
41 | }
42 |
43 | /*********************************************************************/
44 |
45 | bool LinkedBlockList::hasNext()
46 | {
47 | if ( m_cursor != 0 ) return (true);
48 | else return(false);
49 | }
50 |
51 |
52 | /*********************************************************************/
53 |
54 | LinkedBlockList::~LinkedBlockList()
55 | {
56 | LLBlock *tmp;
57 |
58 | while ( m_head != 0 )
59 | {
60 | tmp = m_head;
61 | m_head = m_head->m_next;
62 | delete tmp;
63 | }
64 | };
65 |
66 | /*********************************************************************/
67 |
68 |
--------------------------------------------------------------------------------
/3rd_graphcut/LinkedBlockList.h:
--------------------------------------------------------------------------------
1 | /* Singly Linked List of Blocks */
2 | // This data structure should be used only for the GCoptimization class implementation
3 | // because it lucks some important general functions for general list, like remove_item()
4 | // The head block may be not full
5 | // For regular 2D grids, it's better to set GCLL_BLOCK_SIZE to 2
6 | // For other graphs, it should be set to the average expected number of neighbors
7 | // Data in linked list for the neighborhood system is allocated in blocks of size GCLL_BLOCK_SIZE
8 |
9 | #ifndef __LINKEDBLOCKLIST_H__
10 | #define __LINKEDBLOCKLIST_H__
11 |
12 | #define GCLL_BLOCK_SIZE 4
13 | // GCLL_BLOCKSIZE should "fit" into the type BlockType. That is
14 | // if GCLL_BLOCKSIZE is larger than 255 but smaller than largest short integer
15 | // then BlockType should be set to short
16 | typedef char BlockType;
17 |
18 | //The type of data stored in the linked list
19 | typedef void * ListType;
20 |
21 | class LinkedBlockList{
22 |
23 | public:
24 | void addFront(ListType item);
25 | inline bool isEmpty(){if (m_head == 0) return(true); else return(false);};
26 | inline LinkedBlockList(){m_head = 0; m_head_block_size = GCLL_BLOCK_SIZE;};
27 | ~LinkedBlockList();
28 |
29 | // Next three functins are for the linked list traversal
30 | inline void setCursorFront(){m_cursor = m_head; m_cursor_ind = 0;};
31 | ListType next();
32 | bool hasNext();
33 |
34 | private:
35 | typedef struct LLBlockStruct{
36 | ListType m_item[GCLL_BLOCK_SIZE];
37 | struct LLBlockStruct *m_next;
38 | } LLBlock;
39 |
40 | LLBlock *m_head;
41 | // Remembers the number of elements in the head block, since it may not be full
42 | BlockType m_head_block_size;
43 | // For block traversal, points to current element in the current block
44 | BlockType m_cursor_ind;
45 | // For block traversal, points to current block in the linked list
46 | LLBlock *m_cursor;
47 | };
48 |
49 | #endif
50 |
51 |
--------------------------------------------------------------------------------
/3rd_qglviewer/ImageInterface.cpp:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 |
3 | Copyright (C) 2002-2013 Gilles Debunne. All rights reserved.
4 |
5 | This file is part of the QGLViewer library version 2.4.0.
6 |
7 | http://www.libqglviewer.com - contact@libqglviewer.com
8 |
9 | This file may be used under the terms of the GNU General Public License
10 | versions 2.0 or 3.0 as published by the Free Software Foundation and
11 | appearing in the LICENSE file included in the packaging of this file.
12 | In addition, as a special exception, Gilles Debunne gives you certain
13 | additional rights, described in the file GPL_EXCEPTION in this package.
14 |
15 | libQGLViewer uses dual licensing. Commercial/proprietary software must
16 | purchase a libQGLViewer Commercial License.
17 |
18 | This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
19 | WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 |
21 | *****************************************************************************/
22 |
23 | #include "qglviewer.h"
24 | #include "ImageInterface.h"
25 |
26 |
27 | ImageInterface::ImageInterface(QWidget *parent)
28 | : QDialog(parent)
29 | {
30 | setupUi(this);
31 | viewer_ = dynamic_cast(parent);
32 |
33 | imgHeight->setValue(viewer_->height());
34 | imgWidth->setValue(viewer_->width());
35 |
36 | connect(imgScale, SIGNAL(valueChanged(int)), this, SLOT(scaleChanged(int)));
37 | }
38 |
39 | void ImageInterface::scaleChanged(int s) {
40 | int h = viewer_->height() * s;
41 | int w = viewer_->width() * s;
42 |
43 | imgHeight->setValue(h);
44 | imgWidth->setValue(w);
45 | }
--------------------------------------------------------------------------------
/3rd_qglviewer/ImageInterface.h:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 |
3 | Copyright (C) 2002-2013 Gilles Debunne. All rights reserved.
4 |
5 | This file is part of the QGLViewer library version 2.4.0.
6 |
7 | http://www.libqglviewer.com - contact@libqglviewer.com
8 |
9 | This file may be used under the terms of the GNU General Public License
10 | versions 2.0 or 3.0 as published by the Free Software Foundation and
11 | appearing in the LICENSE file included in the packaging of this file.
12 | In addition, as a special exception, Gilles Debunne gives you certain
13 | additional rights, described in the file GPL_EXCEPTION in this package.
14 |
15 | libQGLViewer uses dual licensing. Commercial/proprietary software must
16 | purchase a libQGLViewer Commercial License.
17 |
18 | This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
19 | WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 |
21 | *****************************************************************************/
22 |
23 | #ifndef _SAVE_SNAPSHOT_H_
24 | #define _SAVE_SNAPSHOT_H_
25 |
26 | #include "qglviewer.h"
27 | #include "ui_ImageInterface.h"
28 |
29 |
30 | class QGLVIEWER_EXPORT ImageInterface: public QDialog, public Ui::ImageInterface
31 | {
32 | Q_OBJECT
33 | public:
34 | ImageInterface(QWidget *parent) ;
35 |
36 | private Q_SLOTS:
37 | void scaleChanged(int s);
38 |
39 | private:
40 | QGLViewer* viewer_;
41 | };
42 |
43 | #endif
44 |
45 |
--------------------------------------------------------------------------------
/3rd_qglviewer/VRender/BackFaceCullingOptimizer.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of the VRender library.
3 | Copyright (C) 2005 Cyril Soler (Cyril.Soler@imag.fr)
4 | Version 1.0.0, released on June 27, 2005.
5 |
6 | http://artis.imag.fr/Members/Cyril.Soler/VRender
7 |
8 | VRender is free software; you can redistribute it and/or modify
9 | it under the terms of the GNU General Public License as published by
10 | the Free Software Foundation; either version 2 of the License, or
11 | (at your option) any later version.
12 |
13 | VRender is distributed in the hope that it will be useful,
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | GNU General Public License for more details.
17 |
18 | You should have received a copy of the GNU General Public License
19 | along with VRender; if not, write to the Free Software Foundation, Inc.,
20 | 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
21 | */
22 |
23 | /****************************************************************************
24 |
25 | Copyright (C) 2002-2013 Gilles Debunne. All rights reserved.
26 |
27 | This file is part of the QGLViewer library version 2.4.0.
28 |
29 | http://www.libqglviewer.com - contact@libqglviewer.com
30 |
31 | This file may be used under the terms of the GNU General Public License
32 | versions 2.0 or 3.0 as published by the Free Software Foundation and
33 | appearing in the LICENSE file included in the packaging of this file.
34 | In addition, as a special exception, Gilles Debunne gives you certain
35 | additional rights, described in the file GPL_EXCEPTION in this package.
36 |
37 | libQGLViewer uses dual licensing. Commercial/proprietary software must
38 | purchase a libQGLViewer Commercial License.
39 |
40 | This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
41 | WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
42 |
43 | *****************************************************************************/
44 |
45 | #include
46 | #include "VRender.h"
47 | #include "Optimizer.h"
48 | #include "Primitive.h"
49 |
50 | using namespace std ;
51 | using namespace vrender ;
52 |
53 | // Over-simplified algorithm to check wether a polygon is front-facing or not.
54 | // Only works for convex polygons.
55 |
56 | void BackFaceCullingOptimizer::optimize(std::vector& primitives_tab,VRenderParams&)
57 | {
58 | Polygone *P ;
59 | int nb_culled = 0 ;
60 |
61 | for(unsigned int i=0;i(primitives_tab[i])) != NULL)
63 | {
64 | for(unsigned int j=0;jnbVertices();++j)
65 | if(( (P->vertex(j+2) - P->vertex(j+1))^(P->vertex(j+1) - P->vertex(j))).z() > 0.0 )
66 | {
67 | delete primitives_tab[i] ;
68 | primitives_tab[i] = NULL ;
69 | ++nb_culled ;
70 | break ;
71 | }
72 | }
73 |
74 | // Rule out gaps. This avoids testing for null primitives later.
75 |
76 | int j=0 ;
77 | for(unsigned int k=0;k&,VRenderParams&) = 0 ;
59 | virtual ~Optimizer() {} ;
60 | };
61 |
62 | // Optimizes visibility by culling primitives which do not appear in the
63 | // rendered image. Computations are done analytically rather than using an item
64 | // buffer.
65 |
66 | class VisibilityOptimizer: public Optimizer
67 | {
68 | public:
69 | virtual void optimize(std::vector&,VRenderParams&) ;
70 | virtual ~VisibilityOptimizer() {} ;
71 | };
72 |
73 | // Optimizes by collapsing together primitives which can be, without
74 | // perturbating the back to front painting algorithm.
75 |
76 | class PrimitiveSplitOptimizer: public Optimizer
77 | {
78 | public:
79 | virtual void optimize(std::vector&,VRenderParams&) {}
80 | virtual ~PrimitiveSplitOptimizer() {} ;
81 | };
82 |
83 | class BackFaceCullingOptimizer: public Optimizer
84 | {
85 | public:
86 | virtual void optimize(std::vector&,VRenderParams&) ;
87 | virtual ~BackFaceCullingOptimizer() {} ;
88 | };
89 | }
90 |
91 | #endif
92 |
--------------------------------------------------------------------------------
/3rd_qglviewer/VRender/ParserGL.h:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of the VRender library.
3 | Copyright (C) 2005 Cyril Soler (Cyril.Soler@imag.fr)
4 | Version 1.0.0, released on June 27, 2005.
5 |
6 | http://artis.imag.fr/Members/Cyril.Soler/VRender
7 |
8 | VRender is free software; you can redistribute it and/or modify
9 | it under the terms of the GNU General Public License as published by
10 | the Free Software Foundation; either version 2 of the License, or
11 | (at your option) any later version.
12 |
13 | VRender is distributed in the hope that it will be useful,
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | GNU General Public License for more details.
17 |
18 | You should have received a copy of the GNU General Public License
19 | along with VRender; if not, write to the Free Software Foundation, Inc.,
20 | 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
21 | */
22 |
23 | /****************************************************************************
24 |
25 | Copyright (C) 2002-2013 Gilles Debunne. All rights reserved.
26 |
27 | This file is part of the QGLViewer library version 2.4.0.
28 |
29 | http://www.libqglviewer.com - contact@libqglviewer.com
30 |
31 | This file may be used under the terms of the GNU General Public License
32 | versions 2.0 or 3.0 as published by the Free Software Foundation and
33 | appearing in the LICENSE file included in the packaging of this file.
34 | In addition, as a special exception, Gilles Debunne gives you certain
35 | additional rights, described in the file GPL_EXCEPTION in this package.
36 |
37 | libQGLViewer uses dual licensing. Commercial/proprietary software must
38 | purchase a libQGLViewer Commercial License.
39 |
40 | This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
41 | WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
42 |
43 | *****************************************************************************/
44 |
45 | #ifndef _VRENDER_PARSERGL_H
46 | #define _VRENDER_PARSERGL_H
47 |
48 | // This class implements the conversion from OpenGL feedback buffer into more
49 | // usable data structures such as points, segments, and polygons (See Primitive.h)
50 |
51 | #include
52 | #include "Primitive.h"
53 |
54 | namespace vrender
55 | {
56 | class ParserGL
57 | {
58 | public:
59 | void parseFeedbackBuffer( GLfloat *,
60 | int size,
61 | std::vector& primitive_tab,
62 | VRenderParams& vparams) ;
63 | void printStats() const ;
64 |
65 | inline GLfloat xmin() const { return _xmin ; }
66 | inline GLfloat ymin() const { return _ymin ; }
67 | inline GLfloat zmin() const { return _zmin ; }
68 | inline GLfloat xmax() const { return _xmax ; }
69 | inline GLfloat ymax() const { return _ymax ; }
70 | inline GLfloat zmax() const { return _zmax ; }
71 | private:
72 | int nb_lines ;
73 | int nb_polys ;
74 | int nb_points ;
75 | int nb_degenerated_lines ;
76 | int nb_degenerated_polys ;
77 | int nb_degenerated_points ;
78 |
79 | GLfloat _xmin ;
80 | GLfloat _ymin ;
81 | GLfloat _zmin ;
82 | GLfloat _xmax ;
83 | GLfloat _ymax ;
84 | GLfloat _zmax ;
85 | };
86 | }
87 |
88 | #endif
89 |
--------------------------------------------------------------------------------
/3rd_qglviewer/VRender/Types.h:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of the VRender library.
3 | Copyright (C) 2005 Cyril Soler (Cyril.Soler@imag.fr)
4 | Version 1.0.0, released on June 27, 2005.
5 |
6 | http://artis.imag.fr/Members/Cyril.Soler/VRender
7 |
8 | VRender is free software; you can redistribute it and/or modify
9 | it under the terms of the GNU General Public License as published by
10 | the Free Software Foundation; either version 2 of the License, or
11 | (at your option) any later version.
12 |
13 | VRender is distributed in the hope that it will be useful,
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | GNU General Public License for more details.
17 |
18 | You should have received a copy of the GNU General Public License
19 | along with VRender; if not, write to the Free Software Foundation, Inc.,
20 | 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
21 | */
22 |
23 | /****************************************************************************
24 |
25 | Copyright (C) 2002-2013 Gilles Debunne. All rights reserved.
26 |
27 | This file is part of the QGLViewer library version 2.4.0.
28 |
29 | http://www.libqglviewer.com - contact@libqglviewer.com
30 |
31 | This file may be used under the terms of the GNU General Public License
32 | versions 2.0 or 3.0 as published by the Free Software Foundation and
33 | appearing in the LICENSE file included in the packaging of this file.
34 | In addition, as a special exception, Gilles Debunne gives you certain
35 | additional rights, described in the file GPL_EXCEPTION in this package.
36 |
37 | libQGLViewer uses dual licensing. Commercial/proprietary software must
38 | purchase a libQGLViewer Commercial License.
39 |
40 | This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
41 | WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
42 |
43 | *****************************************************************************/
44 |
45 | #ifndef _VRENDER_TYPES_H
46 | #define _VRENDER_TYPES_H
47 |
48 | #ifdef WIN32
49 | # include
50 | #endif
51 |
52 | #ifdef __APPLE__
53 | # include
54 | #else
55 | # include
56 | #endif
57 |
58 | namespace vrender
59 | {
60 | typedef double FLOAT ;
61 | typedef GLdouble GLFLOAT ;
62 |
63 | #ifdef A_VOIR
64 | typedef T_Vect3 DVector3 ;
65 | typedef T_Vect2 Vector2 ;
66 | #endif
67 |
68 | class Primitive ;
69 | typedef Primitive *PtrPrimitive ;
70 |
71 | const float FLAT_POLYGON_EPS = 1e-5f ;
72 | }
73 |
74 | #endif
75 |
--------------------------------------------------------------------------------
/3rd_qglviewer/qglviewer_fr.qm:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LiangliangNan/ManhattanModeler/ef257690a2c3f4d36be430452db5bbb2d1bd54b0/3rd_qglviewer/qglviewer_fr.qm
--------------------------------------------------------------------------------
/3rd_ransac/BasePrimitiveShape.h:
--------------------------------------------------------------------------------
1 | #ifndef BASEPRIMITIVESHAPE_HEADER
2 | #define BASEPRIMITIVESHAPE_HEADER
3 | #include "PrimitiveShape.h"
4 | #include "ScoreComputer.h"
5 | #include
6 | #include
7 |
8 | #ifndef DLL_LINKAGE
9 | #define DLL_LINKAGE
10 | #endif
11 |
12 | class DLL_LINKAGE BasePrimitiveShape
13 | : public PrimitiveShape
14 | {
15 | protected:
16 | template< class ShapeT >
17 | unsigned int ConfidenceTests(unsigned int numTests, float epsilon,
18 | float normalThresh, float rms, const PointCloud &pc,
19 | const MiscLib::Vector< size_t > &indices) const
20 | {
21 | unsigned int numFailures = 0;
22 | // estimate shapes
23 | const unsigned int numSamples = ShapeT::RequiredSamples;
24 | if(numSamples >= indices.size())
25 | return numTests;
26 | MiscLib::Vector< ShapeT > shapes;
27 | for(unsigned int i = 0; i < numTests; ++i)
28 | {
29 | MiscLib::Vector< size_t > sampleIndices;
30 | for(unsigned int j = 0; j < numSamples; ++j)
31 | {
32 | size_t idx;
33 | do
34 | {
35 | idx = indices[MiscLib::rn_rand() % indices.size()];
36 | }
37 | while(std::find(sampleIndices.begin(), sampleIndices.end(), idx)
38 | != sampleIndices.end());
39 | sampleIndices.push_back(idx);
40 | }
41 | MiscLib::Vector< Vec3f > samples(numSamples << 1);
42 | for(unsigned int j = 0; j < numSamples; ++j)
43 | {
44 | samples[j] = pc[sampleIndices[j]].pos;
45 | samples[j + numSamples] = pc[sampleIndices[j]].normal;
46 | }
47 | ShapeT shape;
48 | if(shape.Init(samples))
49 | shapes.push_back(shape);
50 | else
51 | ++numFailures;
52 | }
53 |
54 | MiscLib::Vector< size_t > scores(shapes.size(), 0);
55 | //MiscLib::Vector< float > sse(shapes.size(), 0.f);
56 | Vec3f n;
57 | for(size_t i = 0; i < indices.size(); ++i)
58 | {
59 | for(size_t j = 0; j < shapes.size(); ++j)
60 | {
61 | //float d = shapes[j].Distance(pc[indices[i]].pos);
62 | //sse[j] += d * d;
63 | float d = shapes[j].DistanceAndNormal(pc[indices[i]].pos, &n);
64 | if(d > epsilon)
65 | continue;
66 | float dn = n.dot(pc[indices[i]].normal);
67 | if(fabs(dn) > normalThresh)
68 | ++scores[j];
69 | }
70 | }
71 |
72 | for(size_t i = 0; i < /*sse.size()*/scores.size(); ++i)
73 | {
74 | if(scores[i] < .9f * indices.size())
75 | //if(fabs(std::sqrt(sse[i] / indices.size()) - rms) > 1e-2)
76 | ++numFailures;
77 | }
78 |
79 | return numFailures;
80 | }
81 | };
82 |
83 | #endif
84 |
--------------------------------------------------------------------------------
/3rd_ransac/Bitmap.h:
--------------------------------------------------------------------------------
1 | #ifndef BITMAP_HEADER
2 | #define BITMAP_HEADER
3 | #include
4 | #include
5 | #include
6 | #include
7 |
8 | #ifndef DLL_LINKAGE
9 | #define DLL_LINKAGE
10 | #endif
11 |
12 | DLL_LINKAGE void DilateSquare(const MiscLib::Vector< char > &bitmap, size_t uextent,
13 | size_t vextent, bool uwrap, bool vwrap,
14 | MiscLib::Vector< char > *dilated);
15 | DLL_LINKAGE void DilateCross(const MiscLib::Vector< char > &bitmap, size_t uextent,
16 | size_t vextent, bool uwrap, bool vwrap,
17 | MiscLib::Vector< char > *dilated);
18 | DLL_LINKAGE void ErodeSquare(const MiscLib::Vector< char > &bitmap, size_t uextent,
19 | size_t vextent, bool uwrap, bool vwrap,
20 | MiscLib::Vector< char > *eroded);
21 | DLL_LINKAGE void ErodeCross(const MiscLib::Vector< char > &bitmap, size_t uextent,
22 | size_t vextent, bool uwrap, bool vwrap,
23 | MiscLib::Vector< char > *eroded);
24 | DLL_LINKAGE void Components(const MiscLib::Vector< char > &bitmap, size_t uextent,
25 | size_t vextent, bool uwrap, bool vwrap,
26 | MiscLib::Vector< int > *componentsImg,
27 | MiscLib::Vector< std::pair< int, size_t > > *labels);
28 | DLL_LINKAGE void PreWrappedComponents(const MiscLib::Vector< char > &bitmap, size_t uextent,
29 | size_t vextent, MiscLib::Vector< int > *componentsImg,
30 | MiscLib::Vector< int > *relabelComponentsImg,
31 | const MiscLib::Vector< std::pair< int, size_t > > &inLabels,
32 | MiscLib::Vector< std::pair< int, size_t > > *labels);
33 | DLL_LINKAGE int Label(int n[], int size, int *curLabel,
34 | MiscLib::Vector< std::pair< int, size_t > > *labels);
35 | DLL_LINKAGE void AssociateLabel(int a, int b,
36 | MiscLib::Vector< std::pair< int, size_t > > *labels);
37 | DLL_LINKAGE int ReduceLabel(int a, const MiscLib::Vector<
38 | std::pair< int, size_t > > &labels);
39 | // finds the loops around a connected component as polygons
40 | DLL_LINKAGE void ComponentLoops(const MiscLib::Vector< int > &componentImg, size_t uextent,
41 | size_t vextent, int label, bool uwrap, bool vwrap,
42 | MiscLib::Vector< MiscLib::Vector< GfxTL::VectorXD< 2, size_t > > > *polys);
43 |
44 | #endif
45 |
--------------------------------------------------------------------------------
/3rd_ransac/ConePrimitiveShapeConstructor.cpp:
--------------------------------------------------------------------------------
1 | #include "ConePrimitiveShapeConstructor.h"
2 | #include "ConePrimitiveShape.h"
3 | #include "Cone.h"
4 | #include "ScoreComputer.h"
5 | #include
6 |
7 | size_t ConePrimitiveShapeConstructor::Identifier() const
8 | {
9 | return 3;
10 | }
11 |
12 | unsigned int ConePrimitiveShapeConstructor::RequiredSamples() const
13 | {
14 | return 3;
15 | }
16 |
17 | PrimitiveShape *ConePrimitiveShapeConstructor::Construct(
18 | const MiscLib::Vector< Vec3f > &points,
19 | const MiscLib::Vector< Vec3f > &normals) const
20 | {
21 | Cone cone;
22 | if(!cone.Init(points[0], points[1], points[2], normals[0], normals[1],
23 | normals[2]))
24 | return NULL;
25 | if(cone.Angle() > 1.4835298641951801403851371532153)
26 | // do not allow cones with an opening angle of more than 85 degrees
27 | return NULL;
28 | return new ConePrimitiveShape(cone);
29 | }
30 |
31 | PrimitiveShape *ConePrimitiveShapeConstructor::Construct(
32 | const MiscLib::Vector< Vec3f > &samples) const
33 | {
34 | Cone cone;
35 | if(!cone.Init(samples))
36 | return NULL;
37 | return new ConePrimitiveShape(cone);
38 | }
39 |
40 | PrimitiveShape *ConePrimitiveShapeConstructor::Deserialize(std::istream *i,
41 | bool binary) const
42 | {
43 | Cone cone;
44 | cone.Init(binary, i);
45 | ConePrimitiveShape *shape = new ConePrimitiveShape(cone);
46 | return shape;
47 | }
48 |
49 | size_t ConePrimitiveShapeConstructor::SerializedSize() const
50 | {
51 | return Cone::SerializedSize();
52 | }
53 |
--------------------------------------------------------------------------------
/3rd_ransac/ConePrimitiveShapeConstructor.h:
--------------------------------------------------------------------------------
1 | #ifndef CONEPRIMITIVESHAPECONSTRUCTOR_HEADER
2 | #define CONEPRIMITIVESHAPECONSTRUCTOR_HEADER
3 | #include "PrimitiveShapeConstructor.h"
4 |
5 | #ifndef DLL_LINKAGE
6 | #define DLL_LINKAGE
7 | #endif
8 |
9 | class DLL_LINKAGE ConePrimitiveShapeConstructor
10 | : public PrimitiveShapeConstructor
11 | {
12 | public:
13 | size_t Identifier() const;
14 | unsigned int RequiredSamples() const;
15 | PrimitiveShape *Construct(const MiscLib::Vector< Vec3f > &points,
16 | const MiscLib::Vector< Vec3f > &normals) const;
17 | PrimitiveShape *Construct(const MiscLib::Vector< Vec3f > &samples) const;
18 | PrimitiveShape *Deserialize(std::istream *i, bool binary = true) const;
19 | size_t SerializedSize() const;
20 | };
21 |
22 | #endif
23 |
24 |
--------------------------------------------------------------------------------
/3rd_ransac/CylinderPrimitiveShapeConstructor.cpp:
--------------------------------------------------------------------------------
1 | #include "CylinderPrimitiveShapeConstructor.h"
2 | #include "ScoreComputer.h"
3 | #include
4 |
5 | size_t CylinderPrimitiveShapeConstructor::Identifier() const
6 | {
7 | return 2;
8 | }
9 |
10 | unsigned int CylinderPrimitiveShapeConstructor::RequiredSamples() const
11 | {
12 | return 2;
13 | }
14 |
15 | PrimitiveShape *CylinderPrimitiveShapeConstructor::Construct(
16 | const MiscLib::Vector< Vec3f > &points,
17 | const MiscLib::Vector< Vec3f > &normals) const
18 | {
19 | Cylinder cy;
20 | MiscLib::Vector< Vec3f > samples(points);
21 | std::copy(normals.begin(), normals.end(), std::back_inserter(samples));
22 | if(!cy.Init(samples))
23 | return NULL;
24 | return new CylinderPrimitiveShape(cy);
25 | }
26 |
27 | PrimitiveShape *CylinderPrimitiveShapeConstructor::Construct(
28 | const MiscLib::Vector< Vec3f > &samples) const
29 | {
30 | Cylinder cy;
31 | if(!cy.Init(samples))
32 | return NULL;
33 | return new CylinderPrimitiveShape(cy);
34 | }
35 |
36 | PrimitiveShape *CylinderPrimitiveShapeConstructor::Deserialize(
37 | std::istream *i, bool binary) const
38 | {
39 | Cylinder cylinder;
40 | cylinder.Init(binary, i);
41 | CylinderPrimitiveShape *shape = new CylinderPrimitiveShape(cylinder);
42 | return shape;
43 | }
44 |
45 | size_t CylinderPrimitiveShapeConstructor::SerializedSize() const
46 | {
47 | return Cylinder::SerializedSize();
48 | }
49 |
--------------------------------------------------------------------------------
/3rd_ransac/CylinderPrimitiveShapeConstructor.h:
--------------------------------------------------------------------------------
1 | #ifndef CYLINDERPRIMITIVESHAPECONSTRUCTOR_HEADER
2 | #define CYLINDERPRIMITIVESHAPECONSTRUCTOR_HEADER
3 | #include "PrimitiveShapeConstructor.h"
4 | #include "CylinderPrimitiveShape.h"
5 |
6 | #ifndef DLL_LINKAGE
7 | #define DLL_LINKAGE
8 | #endif
9 |
10 | class DLL_LINKAGE CylinderPrimitiveShapeConstructor
11 | : public PrimitiveShapeConstructor
12 | {
13 | public:
14 | size_t Identifier() const;
15 | unsigned int RequiredSamples() const;
16 | PrimitiveShape *Construct(const MiscLib::Vector< Vec3f > &points,
17 | const MiscLib::Vector< Vec3f > &normals) const;
18 | PrimitiveShape *Construct(const MiscLib::Vector< Vec3f > &samples) const;
19 | PrimitiveShape *Deserialize(std::istream *i, bool binary = true) const;
20 | size_t SerializedSize() const;
21 | };
22 |
23 | #endif
24 |
--------------------------------------------------------------------------------
/3rd_ransac/FlatNormalThreshPointCompatibilityFunc.h:
--------------------------------------------------------------------------------
1 | #ifndef FLATNORMALTHRESHPOINTCOMPATIBILITYFUNC_HEADER
2 | #define FLATNORMALTHRESHPOINTCOMPATIBILITYFUNC_HEADER
3 | #include
4 |
5 | class FlatNormalThreshPointCompatibilityFunc
6 | {
7 | public:
8 | FlatNormalThreshPointCompatibilityFunc() {}
9 | FlatNormalThreshPointCompatibilityFunc(float distThresh,
10 | float normalThresh)
11 | : m_distThresh(distThresh)
12 | , m_normalThresh(normalThresh)
13 | {}
14 | template< class ShapeT, class OctreeT >
15 | bool operator()(const ShapeT &shape, const OctreeT &oct,
16 | unsigned int i) const
17 | {
18 | Vec3f n;
19 | float distance = shape.DistanceAndNormal(oct.at(i), &n);
20 | if(distance < m_distThresh)
21 | return fabs(n.dot(oct.at(i).normal)) >= m_normalThresh;
22 | return false;
23 | }
24 | bool operator()(float distance, float normalDeviation) const
25 | {
26 | return distance < m_distThresh
27 | && fabs(normalDeviation) >= m_normalThresh;
28 | }
29 | float DistanceThresh() const { return m_distThresh; }
30 | float NormalThresh() const { return m_normalThresh; }
31 |
32 | private:
33 | float m_distThresh;
34 | float m_normalThresh;
35 | };
36 |
37 | #endif
38 |
--------------------------------------------------------------------------------
/3rd_ransac/GfxTL/AABox.hpp:
--------------------------------------------------------------------------------
1 |
2 | namespace GfxTL
3 | {
4 | template< class Point >
5 | AABox< Point >::AABox(const PointType &pmin, const PointType &pmax)
6 | : _pmin(pmin)
7 | , _pmax(pmax)
8 | {}
9 |
10 | template< class Point >
11 | void AABox< Point >::Infinite()
12 | {
13 | for(unsigned int i = 0; i < Dim; ++i)
14 | {
15 | _pmin[i] = -std::numeric_limits< ScalarType >::infinity();
16 | _pmax[i] = std::numeric_limits< ScalarType >::infinity();
17 | }
18 | }
19 |
20 | template< class Point >
21 | void AABox< Point >::Split(unsigned int axis, ScalarType s,
22 | AABox< Point > *left, AABox< Point > *right) const
23 | {
24 | *left = *right = *this;
25 | if(_pmax[axis] > s)
26 | left->_pmax[axis] = s;
27 | if(_pmin[axis] < s)
28 | right->_pmin[axis] = s;
29 | }
30 |
31 | template< class Point >
32 | void AABox< Point >::Center(Point *center) const
33 | {
34 | *center = _pmin;
35 | *center += _pmax;
36 | *center /= 2;
37 | }
38 |
39 | template< class Point >
40 | Point AABox< Point >::operator[](unsigned int index) const
41 | {
42 | Point p;
43 | for(unsigned int i = 0; i < Dim; ++i)
44 | {
45 | if(index & (1 << i))
46 | p[i] = _pmin[i];
47 | else
48 | p[i] = _pmax[i];
49 | }
50 | return p;
51 | }
52 |
53 | template< class Point >
54 | Point &AABox< Point >::Min()
55 | {
56 | return _pmin;
57 | }
58 |
59 | template< class Point >
60 | const Point &AABox< Point >::Min() const
61 | {
62 | return _pmin;
63 | }
64 |
65 | template< class Point >
66 | Point &AABox< Point >::Max()
67 | {
68 | return _pmax;
69 | }
70 |
71 | template< class Point >
72 | const Point &AABox< Point >::Max() const
73 | {
74 | return _pmax;
75 | }
76 |
77 | template< class Point >
78 | typename AABox< Point >::ScalarType AABox< Point >::DiagLength() const
79 | {
80 | return (_pmax - _pmin).Length();
81 | }
82 |
83 | template< class Point >
84 | bool AABox< Point >::IsInside(const Point &p) const
85 | {
86 | for(unsigned int i = 0; i < Dim; ++i)
87 | if(_pmin[i] > p[i] || _pmax[i] < p[i])
88 | return false;
89 | return true;
90 | }
91 |
92 | template< class Point >
93 | AABox< Point > &AABox< Point >::operator+=(const PointType &p)
94 | {
95 | for(unsigned int i = 0; i < Dim; ++i)
96 | {
97 | if(_pmin[i] > p[i])
98 | _pmin[i] = p[i];
99 | if(_pmax[i] < p[i])
100 | _pmax[i] = p[i];
101 | }
102 | return *this;
103 | }
104 | };
105 |
106 |
--------------------------------------------------------------------------------
/3rd_ransac/GfxTL/AAPlane.h:
--------------------------------------------------------------------------------
1 | #ifndef __GfxTL__AAPLANE_HEADER__
2 | #define __GfxTL__AAPLANE_HEADER__
3 |
4 | namespace GfxTL
5 | {
6 | template< class PointT >
7 | class AAPlane
8 | {
9 | public:
10 | typedef PointT PointType;
11 | typedef typename PointType::ScalarType ScalarType;
12 |
13 | AAPlane();
14 | AAPlane(unsigned int axis, ScalarType value);
15 | AAPlane(unsigned int axis, const PointType &p);
16 | inline ScalarType operator()(const PointType &p) const;
17 | void Set(unsigned int axis, ScalarType value);
18 | inline unsigned int Axis() const;
19 | inline ScalarType Value() const;
20 | void Value(ScalarType v);
21 |
22 | private:
23 | unsigned int _axis;
24 | ScalarType _value;
25 | };
26 |
27 | template< class PointT >
28 | typename AAPlane< PointT >::ScalarType AAPlane< PointT >::operator()(
29 | const PointType &p) const
30 | {
31 | return p[_axis] - _value;
32 | }
33 |
34 | template< class PointT >
35 | unsigned int AAPlane< PointT >::Axis() const
36 | {
37 | return _axis;
38 | }
39 |
40 | template< class PointT >
41 | typename AAPlane< PointT >::ScalarType AAPlane< PointT >::Value() const
42 | {
43 | return _value;
44 | }
45 |
46 | template< class PointT >
47 | void AAPlane< PointT >::Value(ScalarType v)
48 | {
49 | _value = v;
50 | }
51 | };
52 |
53 | #include "AAPlane.hpp"
54 |
55 | #endif
--------------------------------------------------------------------------------
/3rd_ransac/GfxTL/AAPlane.hpp:
--------------------------------------------------------------------------------
1 |
2 | namespace GfxTL
3 | {
4 | template< class PointT >
5 | AAPlane< PointT >::AAPlane()
6 | {}
7 |
8 | template< class PointT >
9 | AAPlane< PointT >::AAPlane(unsigned int axis, ScalarType value)
10 | : _axis(axis)
11 | , _value(value)
12 | {
13 | }
14 |
15 | template< class PointT >
16 | AAPlane< PointT >::AAPlane(unsigned int axis, const PointType &p)
17 | : _axis(axis)
18 | , _value(p[axis])
19 | {
20 | }
21 |
22 | template< class PointT >
23 | void AAPlane< PointT >::Set(unsigned int axis, ScalarType value)
24 | {
25 | _axis = axis;
26 | _value = value;
27 | }
28 | };
29 |
--------------------------------------------------------------------------------
/3rd_ransac/GfxTL/ArrayArithmetic.h:
--------------------------------------------------------------------------------
1 | #ifndef GfxTL__ARRAYARITHMETIC_HEADER__
2 | #define GfxTL__ARRAYARITHMETIC_HEADER__
3 | #include
4 |
5 | namespace GfxTL
6 | {
7 |
8 | // c-style (row major) array layout
9 | template< unsigned int DimT >
10 | class ArrayArithmetic
11 | {
12 | public:
13 | ArrayArithmetic() {}
14 |
15 | template< class ExtentT >
16 | ArrayArithmetic(const ExtentT &ext)
17 | {
18 | Extent(ext);
19 | }
20 |
21 | template< class ExtentT >
22 | void Extent(const ExtentT &ext)
23 | {
24 | m_fac[DimT - 1] = 1;
25 | for(unsigned int i = DimT - 1; i != 0; --i)
26 | m_fac[i - 1] = m_fac[i] * ext[i];
27 | m_transFac[0] = 1;
28 | for(unsigned int i = 0; i < DimT - 1; ++i)
29 | m_transFac[i + 1] = m_transFac[i] * ext[i];
30 | }
31 |
32 | template< class SubscriptT >
33 | size_t Sub2Idx(const SubscriptT &sub) const
34 | {
35 | size_t idx = sub[0] * m_fac[0];
36 | for(unsigned int i = 1; i < DimT; ++i)
37 | idx += sub[i] * m_fac[i];
38 | return idx;
39 | }
40 |
41 | template< class SubscriptT >
42 | size_t Sub2TransposedIdx(const SubscriptT &sub) const
43 | {
44 | size_t idx = sub[0] * m_transFac[0];
45 | for(unsigned int i = 1; i < DimT; ++i)
46 | idx += sub[i] * m_transFac[i];
47 | return idx;
48 | }
49 |
50 | template< class SubscriptT >
51 | intptr_t Sub2Off(const SubscriptT &sub) const
52 | {
53 | intptr_t off = sub[0] * m_fac[0];
54 | for(unsigned int i = 1; i < DimT; ++i)
55 | off += sub[i] * m_fac[i];
56 | return off;
57 | }
58 |
59 | template< class SubscriptT >
60 | void Idx2Sub(size_t idx, SubscriptT *sub) const
61 | {
62 | for(unsigned int i = 0; i < DimT; ++i)
63 | {
64 | (*sub)[i] = idx / m_fac[i];
65 | idx %= m_fac[i];
66 | }
67 | }
68 |
69 | template< class SubscriptT >
70 | void TransposedIdx2Sub(size_t tidx, SubscriptT *sub) const
71 | {
72 | for(unsigned int i = DimT - 1; i != -1; --i)
73 | {
74 | (*sub)[i] = tidx / m_transFac[i];
75 | tidx %= m_transFac[i];
76 | }
77 | }
78 |
79 | // convert to column major index (Fortran and Matlab array layout)
80 | size_t Idx2TransposedIdx(size_t idx) const
81 | {
82 | size_t tidx = 0;
83 | for(unsigned int i = 0; i < DimT; ++i)
84 | {
85 | size_t j = idx / m_fac[i];
86 | idx %= m_fac[i];
87 | tidx += j * m_transFac[i];
88 | }
89 | return tidx;
90 | }
91 |
92 | // convert column major index (Fortran and Matlab array layout) to row major (c/c++ array layout)
93 | size_t TransposedIdx2Idx(size_t tidx) const
94 | {
95 | size_t idx = 0;
96 | for(unsigned int i = DimT - 1; i != -1; --i)
97 | {
98 | size_t j = tidx / m_transFac[i];
99 | tidx %= m_transFac[i];
100 | idx += j * m_fac[i];
101 | }
102 | return idx;
103 | }
104 |
105 | private:
106 | size_t m_fac[DimT];
107 | size_t m_transFac[DimT];
108 | };
109 |
110 | };
111 |
112 | #endif
113 |
--------------------------------------------------------------------------------
/3rd_ransac/GfxTL/BaseTree.hpp:
--------------------------------------------------------------------------------
1 |
2 | namespace GfxTL
3 | {
4 | template< class Cell >
5 | BaseTree< Cell >::BaseTree()
6 | : _root(NULL)
7 | {}
8 |
9 | template< class Cell >
10 | BaseTree< Cell >::BaseTree(const BaseTree< Cell > &bt)
11 | : _root(NULL)
12 | {
13 | if(bt._root)
14 | _root = new Cell(*bt._root);
15 | }
16 |
17 | template< class Cell >
18 | BaseTree< Cell >::~BaseTree()
19 | {
20 | Clear();
21 | }
22 |
23 | template< class Cell >
24 | void BaseTree< Cell >::Clear()
25 | {
26 | if(_root)
27 | {
28 | delete _root;
29 | _root = NULL;
30 | }
31 | }
32 |
33 | template< class Cell >
34 | void BaseTree< Cell >::Init()
35 | {}
36 |
37 | template< class Cell >
38 | typename BaseTree< Cell >::CellType *
39 | BaseTree< Cell >::Root()
40 | {
41 | return _root;
42 | }
43 |
44 | template< class Cell >
45 | const typename BaseTree< Cell >::CellType *
46 | BaseTree< Cell >::Root() const
47 | {
48 | return _root;
49 | }
50 |
51 | template< class Cell >
52 | void BaseTree< Cell >::Root(Cell *root)
53 | {
54 | _root = root;
55 | }
56 |
57 | template< class Cell >
58 | bool BaseTree< Cell >::IsLeaf(const CellType *cell) const
59 | {
60 | return (*cell)[0] == NULL;
61 | }
62 |
63 | template< class Cell >
64 | BaseTree< Cell > &BaseTree< Cell >::operator=(const BaseTree< Cell > &bt)
65 | {
66 | Clear();
67 | if(bt._root)
68 | _root = new Cell(*bt._root);
69 | return *this;
70 | }
71 | };
--------------------------------------------------------------------------------
/3rd_ransac/GfxTL/BucketSizeMaxLevelSubdivisionTreeStrategy.h:
--------------------------------------------------------------------------------
1 | #ifndef GfxTL__BUCKETSIZEMAXLEVELSUBDIVISIONTREESTRATEGY_HEADER__
2 | #define GfxTL__BUCKETSIZEMAXLEVELSUBDIVISIONTREESTRATEGY_HEADER__
3 |
4 | namespace GfxTL
5 | {
6 | template< class InheritedStrategyT >
7 | struct BucketSizeMaxLevelSubdivisionTreeStrategy
8 | {
9 | typedef typename InheritedStrategyT::value_type value_type;
10 |
11 | struct CellData
12 | : public InheritedStrategyT::CellData
13 | {};
14 |
15 | template< class BaseT >
16 | class StrategyBase
17 | : public InheritedStrategyT::template StrategyBase< BaseT >
18 | {
19 | public:
20 | typedef typename InheritedStrategyT::template StrategyBase< BaseT >
21 | BaseType;
22 | typedef typename BaseType::CellType CellType;
23 |
24 | StrategyBase()
25 | : m_maxBucketSize(10)
26 | , m_maxLevel(20)
27 | {}
28 | unsigned int &MaxBucketSize() { return m_maxBucketSize; }
29 | const unsigned int MaxBucketSize() const
30 | { return m_maxBucketSize; }
31 | unsigned int &MaxSubdivisionLevel() { return m_maxLevel; }
32 | const unsigned int MaxSubdivisionLevel() const
33 | { return m_maxLevel; }
34 |
35 | protected:
36 | template< class BuildInformationT >
37 | bool ShouldSubdivide(const CellType &cell,
38 | const BuildInformationT &bi) const
39 | {
40 | return cell.Size() > m_maxBucketSize
41 | && bi.Level() < m_maxLevel;
42 | }
43 |
44 | private:
45 | unsigned int m_maxBucketSize;
46 | unsigned int m_maxLevel;
47 | };
48 | };
49 | };
50 |
51 | #endif
52 |
--------------------------------------------------------------------------------
/3rd_ransac/GfxTL/BucketSizeSubdivisionTreeStrategy.h:
--------------------------------------------------------------------------------
1 | #ifndef GfxTL__BUCKETSIZESUBDIVISIONTREESTRATEGY_HEADER__
2 | #define GfxTL__BUCKETSIZESUBDIVISIONTREESTRATEGY_HEADER__
3 |
4 | namespace GfxTL
5 | {
6 | template< class InheritedStrategyT >
7 | struct BucketSizeSubdivisionTreeStrategy
8 | {
9 | typedef typename InheritedStrategyT::value_type value_type;
10 |
11 | struct CellData
12 | : public InheritedStrategyT::CellData
13 | {};
14 |
15 | template< class BaseT >
16 | class StrategyBase
17 | : public InheritedStrategyT::template StrategyBase< BaseT >
18 | {
19 | public:
20 | typedef typename InheritedStrategyT::template StrategyBase< BaseT >
21 | BaseType;
22 | typedef typename BaseType::CellType CellType;
23 |
24 | StrategyBase()
25 | : m_maxBucketSize(10)
26 | {}
27 | void InitMaxBucketSize(size_t size)
28 | {
29 | m_maxBucketSize = size;
30 | }
31 | size_t &MaxBucketSize() { return m_maxBucketSize; }
32 | const size_t MaxBucketSize() const { return m_maxBucketSize; }
33 |
34 | protected:
35 | template< class BuildInformationT >
36 | bool ShouldSubdivide(const CellType &cell,
37 | const BuildInformationT &bi) const
38 | {
39 | return cell.Size() > m_maxBucketSize;
40 | }
41 |
42 | private:
43 | size_t m_maxBucketSize;
44 | };
45 | };
46 | };
47 |
48 | #endif
49 |
--------------------------------------------------------------------------------
/3rd_ransac/GfxTL/CellCenterAACubeTreeStrategy.h:
--------------------------------------------------------------------------------
1 | #ifndef GfxTL__CELLCENTERAACUBETREESTRATEGY_HEADER__
2 | #define GfxTL__CELLCENTERAACUBETREESTRATEGY_HEADER__
3 | #include
4 | #include
5 |
6 | namespace GfxTL
7 | {
8 | template< unsigned int DimT, class InheritedStrategyT >
9 | struct CellCenterAACubeTreeStrategy
10 | {
11 | typedef typename InheritedStrategyT::value_type value_type;
12 | class CellData
13 | : public InheritedStrategyT::CellData
14 | {
15 | public:
16 | typedef typename GfxTL::ScalarTypeDeferer< value_type >::ScalarType
17 | ScalarType;
18 | const GfxTL::VectorXD< DimT, ScalarType > &Center() const
19 | { return m_center; }
20 | GfxTL::VectorXD< DimT, ScalarType > &Center()
21 | { return m_center; }
22 |
23 | private:
24 | GfxTL::VectorXD< DimT, ScalarType > m_center;
25 | };
26 |
27 | template< class BaseT >
28 | class StrategyBase
29 | : public InheritedStrategyT::template StrategyBase< BaseT >
30 | {
31 | public:
32 | typedef typename InheritedStrategyT::template StrategyBase< BaseT >
33 | BaseType;
34 | typedef typename BaseType::CellType CellType;
35 | typedef typename GfxTL::ScalarTypeDeferer< value_type >::ScalarType
36 | ScalarType;
37 |
38 | protected:
39 | typedef GfxTL::VectorXD< DimT, ScalarType > CellCenterType;
40 |
41 | template< class BaseTraversalT >
42 | class CellCenterTraversalInformation
43 | : public BaseTraversalT
44 | {};
45 |
46 | template< class BuildInformationT >
47 | void InitRoot(const BuildInformationT &bi, CellType *root)
48 | {
49 | BaseType::InitRoot(bi, root);
50 | bi.Cube().Center(&root->Center());
51 | }
52 |
53 | template< class BuildInformationT >
54 | void InitCell(const CellType &parent, const BuildInformationT &pbi,
55 | unsigned int child, const BuildInformationT &bi,
56 | CellType *cell)
57 | {
58 | BaseType::InitCell(parent, pbi, child, bi, cell);
59 | bi.Cube().Center(&cell->Center());
60 | }
61 |
62 | template< class TraversalInformationT >
63 | void CellCenter(const CellType &cell,
64 | const TraversalInformationT &, CellCenterType *center) const
65 | {
66 | *center = cell.Center();
67 | }
68 | };
69 | };
70 | };
71 |
72 | #endif
73 |
--------------------------------------------------------------------------------
/3rd_ransac/GfxTL/CellLevelTreeStrategy.h:
--------------------------------------------------------------------------------
1 | #ifndef GfxTL__CELLLEVELTREESTRATEGY_HEADER__
2 | #define GfxTL__CELLLEVELTREESTRATEGY_HEADER__
3 |
4 | namespace GfxTL
5 | {
6 | template< class InheritedStrategyT >
7 | struct CellLevelTreeStrategy
8 | {
9 | typedef typename InheritedStrategyT::value_type value_type;
10 | class CellData
11 | : public InheritedStrategyT::CellData
12 | {
13 | public:
14 | const size_t Level() const { return m_level; }
15 | void Level(size_t l) { m_level = l; }
16 |
17 | private:
18 | size_t m_level;
19 | };
20 |
21 | template< class BaseT >
22 | class StrategyBase
23 | : public InheritedStrategyT::template StrategyBase< BaseT >
24 | {
25 | public:
26 | typedef typename InheritedStrategyT::template StrategyBase< BaseT >
27 | BaseType;
28 | typedef typename BaseType::CellType CellType;
29 |
30 | protected:
31 | class BuildInformation
32 | : public BaseType::BuildInformation
33 | {
34 | public:
35 | size_t Level() const { return m_level; }
36 | void Level(size_t l) { m_level = l; }
37 | private:
38 | size_t m_level;
39 | };
40 |
41 | template< class BaseTraversalT >
42 | class CellLevelTraversalInformation
43 | : public BaseTraversalT
44 | {};
45 |
46 | template< class BuildInformationT >
47 | void InitRootBuildInformation(BuildInformationT *bi)
48 | {
49 | BaseType::InitRootBuildInformation(bi);
50 | bi->Level(0);
51 | }
52 |
53 | template< class BuildInformationT >
54 | void InitBuildInformation(const CellType &parent,
55 | const BuildInformationT &parentInfo, unsigned int childIdx,
56 | BuildInformationT *bi) const
57 | {
58 | BaseType::InitBuildInformation(parent, parentInfo, childIdx,
59 | bi);
60 | bi->Level(parentInfo.Level() + 1);
61 | }
62 |
63 | template< class BuildInformationT >
64 | void InitRoot(const BuildInformationT &bi, CellType *root)
65 | {
66 | BaseType::InitRoot(bi, root);
67 | root->Level(bi.Level());
68 | }
69 |
70 | template< class BuildInformationT >
71 | void InitCell(const CellType &parent, const BuildInformationT &pbi,
72 | unsigned int child, const BuildInformationT &bi,
73 | CellType *cell)
74 | {
75 | BaseType::InitCell(parent, pbi, child, bi, cell);
76 | cell->Level(bi.Level());
77 | }
78 |
79 | template< class TraversalInformationT >
80 | const size_t CellLevel(const CellType &cell,
81 | const TraversalInformationT &) const
82 | {
83 | return cell.Level();
84 | }
85 | };
86 | };
87 | };
88 |
89 | #endif
90 |
--------------------------------------------------------------------------------
/3rd_ransac/GfxTL/CellParentTreeStrategy.h:
--------------------------------------------------------------------------------
1 | #ifndef GfxTL__CELLPARENTTREESTRATEGY_HEADER__
2 | #define GfxTL__CELLPARENTTREESTRATEGY_HEADER__
3 |
4 | namespace GfxTL
5 | {
6 |
7 | template< class InheritedStrategyT >
8 | struct CellParentTreeStrategy
9 | {
10 | typedef typename InheritedStrategyT::value_type value_type;
11 |
12 | template< class BaseT >
13 | class StrategyBase;
14 |
15 | class CellData
16 | : public InheritedStrategyT::CellData
17 | {
18 | public:
19 | template< class BaseT >
20 | friend class StrategyBase;
21 | typedef typename InheritedStrategyT::CellData BaseType;
22 |
23 | private:
24 | CellData *m_parent;
25 | };
26 |
27 | template< class BaseT >
28 | class StrategyBase
29 | : public InheritedStrategyT::template StrategyBase< BaseT >
30 | {
31 | public:
32 | typedef typename InheritedStrategyT::template StrategyBase< BaseT > BaseType;
33 | typedef typename BaseType::CellType CellType;
34 |
35 | const CellType * const CellParent(const CellType &c) const
36 | {
37 | return (const CellType * const)c.m_parent;
38 | }
39 |
40 | CellType * const CellParent(CellType &c)
41 | {
42 | return (CellType *)c.m_parent;
43 | }
44 |
45 | protected:
46 | class BuildInformation
47 | : public BaseType::BuildInformation
48 | {
49 | public:
50 | CellType *Parent() const { return m_parent; }
51 | void Parent(CellType *p) { m_parent = p; }
52 | private:
53 | CellType *m_parent;
54 | };
55 |
56 | template< class BuildInformationT >
57 | void InitRootBuildInformation(BuildInformationT *bi)
58 | {
59 | BaseType::InitRootBuildInformation(bi);
60 | bi->Parent(NULL);
61 | }
62 |
63 | template< class BuildInformationT >
64 | void InitBuildInformation(const CellType &parent,
65 | const BuildInformationT &parentInfo, unsigned int childIdx,
66 | BuildInformationT *bi)
67 | {
68 | BaseType::InitBuildInformation(parent, parentInfo, childIdx, bi);
69 | bi->Parent(const_cast< CellType * >(&parent));
70 | }
71 |
72 | template< class BuildInformationT >
73 | void InitCell(const CellType &parent,
74 | const BuildInformationT &parentInfo, unsigned int childIdx,
75 | const BuildInformationT &bi, CellType *cell)
76 | {
77 | BaseType::InitCell(parent, parentInfo, childIdx, bi, cell);
78 | cell->m_parent = bi.Parent();
79 | }
80 | };
81 | };
82 |
83 | };
84 |
85 | #endif
86 |
--------------------------------------------------------------------------------
/3rd_ransac/GfxTL/DynVectorKernel.h:
--------------------------------------------------------------------------------
1 | #ifndef GfxTL__DYNVECTORKERNEL_HEADER__
2 | #define GfxTL__DYNVECTORKERNEL_HEADER__
3 |
4 | namespace GfxTL
5 | {
6 | template< class T >
7 | class DynVectorKernel
8 | {
9 | public:
10 | DynVectorKernel(unsigned int dim);
11 |
12 | void Add(const T a[], const T b[], T *r) const;
13 | T Dot(const T a[], const T b[]) const;
14 | T SqrDistance(const T a[], const T b[]) const;
15 |
16 | private:
17 | unsigned int m_dim;
18 | };
19 |
20 | template< class T >
21 | DynVectorKernel< T >::DynVectorKernel(unsigned int dim)
22 | : m_dim(dim)
23 | {}
24 |
25 | template< class T >
26 | void DynVectorKernel< T >::Add(const T a[], const T b[], T *r) const
27 | {
28 | for(unsigned int i = 0; i < m_dim; ++i)
29 | r[i] = a[i] + b[i];
30 | }
31 |
32 | template< class T >
33 | T DynVectorKernel< T >::Dot(const T a[], const T b[]) const
34 | {
35 | T r = a[0] * b[0];
36 | for(size_t i = 1; i < m_dim; ++i)
37 | r += a[i] * b[i];
38 | return r;
39 | }
40 |
41 | template< class T >
42 | T DynVectorKernel< T >::SqrDistance(const T a[], const T b[]) const
43 | {
44 | T r = 0, d;
45 | for(size_t i = 0; i < m_dim; ++i)
46 | {
47 | d = a[i] - b[i];
48 | r += d * d;
49 | }
50 | return r;
51 | }
52 | };
53 |
54 | #endif
55 |
--------------------------------------------------------------------------------
/3rd_ransac/GfxTL/HyperplaneCoordinateSystem.h:
--------------------------------------------------------------------------------
1 | #ifndef __GfxTL_HYPERPLANECOORDINATESYSTEM_HEADER__
2 | #define __GfxTL_HYPERPLANECOORDINATESYSTEM_HEADER__
3 | #include
4 | #include
5 |
6 | namespace GfxTL
7 | {
8 |
9 | template< class Scalar, unsigned int D >
10 | class HyperplaneCoordinateSystem
11 | {
12 | public:
13 | enum { Dim = D, HDim = Dim - 1 };
14 | };
15 |
16 | template< class ScalarT >
17 | class HyperplaneCoordinateSystem< ScalarT, 2 >
18 | {
19 | public:
20 | enum { Dim = 2, HDim = Dim - 1 };
21 | typedef ScalarT ScalarType;
22 | typedef VectorXD< Dim, ScalarType > PointType;
23 |
24 | template< class V >
25 | void FromNormal(const V &v)
26 | {
27 | m_axis[0][0] = -v[1];
28 | m_axis[0][1] = v[0];
29 | }
30 |
31 | PointType &operator[](unsigned int i)
32 | {
33 | return m_axis[i];
34 | }
35 |
36 | const PointType &operator[](unsigned int i) const
37 | {
38 | return m_axis[i];
39 | }
40 |
41 | private:
42 | PointType m_axis[Dim - 1];
43 | };
44 |
45 | template< class Scalar >
46 | class HyperplaneCoordinateSystem< Scalar, 3 >
47 | {
48 | public:
49 | enum { Dim = 3, HDim = Dim - 1 };
50 | typedef Scalar ScalarType;
51 | typedef VectorXD< Dim, ScalarType > PointType;
52 |
53 | HyperplaneCoordinateSystem()
54 | {
55 | for(unsigned int i = 0; i < Dim - 1; ++i)
56 | _axis[i].Zero();
57 | }
58 |
59 | HyperplaneCoordinateSystem(ScalarType x, ScalarType y, ScalarType z)
60 | {
61 | FromNormal(PointType(x, y, z));
62 | }
63 |
64 | template< class V >
65 | HyperplaneCoordinateSystem(V n)
66 | {
67 | FromNormal(n);
68 | }
69 |
70 | void FromNormal(ScalarType x, ScalarType y, ScalarType z)
71 | {
72 | FromNormal(PointType(x, y, z));
73 | }
74 |
75 | template< class V >
76 | void FromNormal(const V &n)
77 | {
78 | FromNormal(PointType(n[0], n[1], n[2]));
79 | }
80 |
81 | void FromNormal(const PointType &n)
82 | {
83 | // perform arbitrary axis algorithm as
84 | // specified by AutoCAD
85 | if(Math< ScalarType >::Abs(n[0]) < ScalarType(0.015625f)
86 | && Math< ScalarType >::Abs(n[1]) < ScalarType(0.015625f))
87 | _axis[0] = PointType(0, 1, 0) % n;
88 | else
89 | _axis[0] = PointType(0, 0, 1) % n;
90 | _axis[0].Normalize();
91 | _axis[1] = n % _axis[0];
92 | _axis[1].Normalize();
93 | }
94 |
95 | PointType &operator[](unsigned int i)
96 | {
97 | return _axis[i];
98 | }
99 |
100 | const PointType &operator[](unsigned int i) const
101 | {
102 | return _axis[i];
103 | }
104 |
105 | private:
106 | PointType _axis[Dim - 1];
107 | };
108 |
109 | };
110 |
111 | #endif
112 |
--------------------------------------------------------------------------------
/3rd_ransac/GfxTL/L1Norm.h:
--------------------------------------------------------------------------------
1 | #ifndef GfxTL__L1NORM_HEADER__
2 | #define GfxTL__L1NORM_HEADER__
3 | #include
4 | #include
5 | #include
6 |
7 | namespace GfxTL
8 | {
9 | template< class VectorKernelT >
10 | struct L1Norm
11 | : public VectorKernelT
12 | {
13 | template< class ScalarAT, class ScalarBT >
14 | struct DistanceType
15 | {
16 | typedef typename ScalarTypeConversion< ScalarAT,
17 | ScalarBT >::DifferenceType Type;
18 | };
19 |
20 | template< class PointAT, class PointBT >
21 | typename DistanceType
22 | <
23 | typename ScalarTypeDeferer< PointAT >::ScalarType,
24 | typename ScalarTypeDeferer< PointBT >::ScalarType
25 | >::Type
26 | Distance(const PointAT &p, const PointBT &v) const
27 | {
28 | typedef typename DistanceType
29 | <
30 | typename ScalarTypeDeferer< PointAT >::ScalarType,
31 | typename ScalarTypeDeferer< PointBT >::ScalarType
32 | >::Type DistType;
33 | DistType d = p[0] - v[0], di;
34 | d = Math< DistType >::Abs(d);
35 | for(unsigned int i = 1; i < m_dim; ++i)
36 | {
37 | di = p[i] - v[i];
38 | d += Math< DistType >::Abs(di);
39 | }
40 | return d;
41 | }
42 |
43 | template< class PointAT, class PointBT >
44 | typename DistanceType
45 | <
46 | typename ScalarTypeDeferer< PointAT >::ScalarType,
47 | typename ScalarTypeDeferer< PointBT >::ScalarType
48 | >::Type
49 | SqrDistance(const PointAT &p, const PointBT &v) const
50 | {
51 | return Distance(p, v);
52 | }
53 |
54 | template< class ScalarT >
55 | ScalarT RootOfDistance(ScalarT sqrDistance) const
56 | {
57 | return sqrDistance;
58 | }
59 |
60 | template< class DistScalarT, class DiffScalarT >
61 | DistScalarT IncrementalBoxSqrDistance(DistScalarT boxSqrDist, DiffScalarT boxDiff,
62 | DiffScalarT cutDiff) const
63 | {
64 | return boxSqrDist + (DistScalarT)cutDiff
65 | - (DistScalarT)boxDiff;
66 | }
67 |
68 | template< class PointAT, class PointBT >
69 | typename DistanceType
70 | <
71 | typename ScalarTypeDeferer< PointAT >::ScalarType,
72 | typename ScalarTypeDeferer< PointBT >::ScalarType
73 | >::Type
74 | BoxSqrDistance(const PointAT &a, const PointBT &min,
75 | const PointBT &max) const
76 | {
77 | typename DistanceType
78 | <
79 | typename ScalarTypeDeferer< PointAT >::ScalarType,
80 | typename ScalarTypeDeferer< PointBT >::ScalarType
81 | >::Type sqrDist = 0, t;
82 | for(unsigned int i = 0; i < m_dim; ++i)
83 | {
84 | if(a[i] < min[i])
85 | {
86 | t = min[i] - a[i];
87 | sqrDist += t;
88 | }
89 | else if(a[i] > max[i])
90 | {
91 | t = a[i] - max[i];
92 | sqrDist += t;
93 | }
94 | }
95 | return sqrDist;
96 | }
97 | };
98 | };
99 |
100 | #endif
101 |
--------------------------------------------------------------------------------
/3rd_ransac/GfxTL/LevelBuildInformationTreeStrategy.h:
--------------------------------------------------------------------------------
1 | #ifndef GfxTL__LEVELBUILDINFORMATIONTREESTRATEGY_HEADER__
2 | #define GfxTL__LEVELBUILDINFORMATIONTREESTRATEGY_HEADER__
3 |
4 | namespace GfxTL
5 | {
6 | template< class InheritedStrategyT >
7 | struct LevelBuildInformationTreeStrategy
8 | {
9 | typedef typename InheritedStrategyT::value_type value_type;
10 | struct CellData
11 | : public InheritedStrategyT::CellData
12 | {};
13 |
14 | template< class BaseT >
15 | class StrategyBase
16 | : public InheritedStrategyT::template StrategyBase< BaseT >
17 | {
18 | public:
19 | typedef typename InheritedStrategyT::template StrategyBase< BaseT >
20 | BaseType;
21 | typedef typename BaseType::CellType CellType;
22 |
23 | protected:
24 | class BuildInformation
25 | : public BaseType::BuildInformation
26 | {
27 | public:
28 | size_t Level() const { return m_level; }
29 | void Level(size_t l) { m_level = l; }
30 | private:
31 | size_t m_level;
32 | };
33 |
34 | template< class BuildInformationT >
35 | void InitRootBuildInformation(BuildInformationT *bi)
36 | {
37 | BaseType::InitRootBuildInformation(bi);
38 | bi->Level(0);
39 | }
40 |
41 | template< class BuildInformationT >
42 | void InitBuildInformation(const CellType &parent,
43 | const BuildInformationT &parentInfo, unsigned int childIdx,
44 | BuildInformationT *bi) const
45 | {
46 | BaseType::InitBuildInformation(parent, parentInfo, childIdx,
47 | bi);
48 | bi->Level(parentInfo.Level() + 1);
49 | }
50 | };
51 | };
52 | };
53 |
54 | #endif
55 |
--------------------------------------------------------------------------------
/3rd_ransac/GfxTL/MathHelper.h:
--------------------------------------------------------------------------------
1 | #ifndef __GfxTL_MATHHELPER_HEADER__
2 | #define __GfxTL_MATHHELPER_HEADER__
3 | #ifndef _USE_MATH_DEFINES
4 | #define _USE_MATH_DEFINES
5 | #endif
6 | #include
7 |
8 | namespace GfxTL
9 | {
10 | template< class ScalarT >
11 | class Math
12 | {
13 | public:
14 | static inline ScalarT Abs(ScalarT s)
15 | {
16 | if(s < 0)
17 | return -s;
18 | return s;
19 | }
20 |
21 | static inline ScalarT Sign(ScalarT s)
22 | {
23 | if(s < 0)
24 | return -1;
25 | else if(s > 0)
26 | return 1;
27 | return 0;
28 | }
29 |
30 | static inline ScalarT Clamp(ScalarT s, ScalarT bottom, ScalarT top)
31 | {
32 | if(s < bottom)
33 | return bottom;
34 | if(s > top)
35 | return top;
36 | return s;
37 | }
38 |
39 | static inline ScalarT Max(ScalarT a, ScalarT b)
40 | {
41 | if(a > b)
42 | return a;
43 | return b;
44 | }
45 |
46 | static inline ScalarT Min(ScalarT a, ScalarT b)
47 | {
48 | if(a < b)
49 | return a;
50 | return b;
51 | }
52 | };
53 |
54 | /*template< >
55 | class Math< float >
56 | {
57 | public:
58 | static inline float Abs(float s)
59 | {
60 | // *reinterpret_cast< unsigned int * >(&s) &= 0x7FFFFFFFu;
61 | if(s < 0) return -s;
62 | return s;
63 | }
64 |
65 | static inline float Sign(float s)
66 | {
67 | if(s < 0)
68 | return -1;
69 | else
70 | return 1;
71 | }
72 |
73 | static inline float Clamp(float s, float bottom, float top)
74 | {
75 | if(s < bottom)
76 | return bottom;
77 | if(s > top)
78 | return top;
79 | return s;
80 | }
81 |
82 | static inline float Max(float a, float b)
83 | {
84 | if(a > b)
85 | return a;
86 | return b;
87 | }
88 |
89 | static inline float Min(float a, float b)
90 | {
91 | if(a < b)
92 | return a;
93 | return b;
94 | }
95 | };*/
96 | };
97 |
98 | #endif
99 |
100 |
--------------------------------------------------------------------------------
/3rd_ransac/GfxTL/MaxIntervalSplittingKdTreeStrategy.h:
--------------------------------------------------------------------------------
1 | #ifndef GfxTL__MAXINTERVALSPLITTINGKDTREESTRATEGY_HEADER__
2 | #define GfxTL__MAXINTERVALSPLITTINGKDTREESTRATEGY_HEADER__
3 | #include
4 | #include
5 |
6 | namespace GfxTL
7 | {
8 | template< class InheritedStrategyT >
9 | struct MaxIntervalSplittingKdTreeStrategy
10 | {
11 | typedef typename InheritedStrategyT::value_type value_type;
12 |
13 | struct CellData
14 | : public InheritedStrategyT::CellData
15 | {};
16 |
17 | template< class BaseT >
18 | class StrategyBase
19 | : public InheritedStrategyT::template StrategyBase< BaseT >
20 | {
21 | public:
22 | typedef typename InheritedStrategyT::template StrategyBase< BaseT >
23 | BaseType;
24 | typedef typename BaseType::CellType CellType;
25 | typedef typename ScalarTypeDeferer< value_type >::ScalarType
26 | ScalarType;
27 | typedef typename ScalarTypeConversion< ScalarType, ScalarType >::
28 | DifferenceType DiffScalarType;
29 |
30 | protected:
31 | template< class BuildInformationT >
32 | void ComputeSplit(const BuildInformationT &bi, CellType *cell)
33 | {
34 | DiffScalarType *diff = new DiffScalarType[BaseType::m_dim];
35 | this->Sub(bi.BBox()[1], bi.BBox()[0], &diff);
36 | unsigned int axis = 0;
37 | DiffScalarType length = diff[0];
38 | for(unsigned int j = 1; j < BaseType::m_dim; ++j)
39 | {
40 | if(diff[j] > length)
41 | {
42 | axis = j;
43 | length = diff[j];
44 | }
45 | }
46 | cell->SplitAxis() = axis;
47 | cell->SplitValue() =
48 | (bi.BBox()[0][axis] + bi.BBox()[1][axis]) / 2;
49 | delete[] diff;
50 | }
51 |
52 | template< class BuildInformationT >
53 | void ComputeSplit(unsigned int axis, const BuildInformationT &bi,
54 | CellType *cell)
55 | {
56 | DiffScalarType *diff = new DiffScalarType[BaseType::m_dim];
57 | Sub(bi.BBox()[1], bi.BBox()[0], &diff);
58 | cell->SplitAxis() = axis;
59 | cell->SplitValue() =
60 | (bi.BBox()[0][axis] + bi.BBox()[1][axis]) / 2;
61 | delete[] diff;
62 | }
63 |
64 | template< class BuildInformationT >
65 | bool AlternateSplit(const BuildInformationT &bi, CellType *cell)
66 | {
67 | unsigned int axis = (cell->SplitAxis() + 1) % BaseType::m_dim;
68 | cell->SplitAxis() = axis;
69 | cell->SplitValue() =
70 | (bi.BBox()[1][axis] + bi.BBox()[0][axis]) / 2;
71 | return true;
72 | }
73 | };
74 | };
75 | };
76 |
77 | #endif
78 |
--------------------------------------------------------------------------------
/3rd_ransac/GfxTL/MaxLevelSubdivisionTreeStrategy.h:
--------------------------------------------------------------------------------
1 | #ifndef GfxTL__MAXLEVELSUBDIVISIONTREESTRATEGY_HEADER__
2 | #define GfxTL__MAXLEVELSUBDIVISIONTREESTRATEGY_HEADER__
3 |
4 | namespace GfxTL
5 | {
6 | template< class InheritedStrategyT >
7 | struct MaxLevelSubdivisionTreeStrategy
8 | {
9 | typedef typename InheritedStrategyT::value_type value_type;
10 |
11 | class CellData
12 | : public InheritedStrategyT::CellData
13 | {};
14 |
15 | template< class BaseT >
16 | class StrategyBase
17 | : public InheritedStrategyT::StrategyBase< BaseT >
18 | {
19 | public:
20 | typedef typename InheritedStrategyT::StrategyBase< BaseT >
21 | BaseType;
22 | typedef typename BaseType::CellType CellType;
23 |
24 | StrategyBase()
25 | : m_maxSubdivisionLevel(15)
26 | {}
27 |
28 | size_t MaxSubdivisionLevel() const
29 | {
30 | return m_maxSubdivisionLevel;
31 | }
32 |
33 | void MaxSubdivisionLevel(size_t level)
34 | {
35 | m_maxSubdivisionLevel = level;
36 | }
37 |
38 | protected:
39 | template< class BuildInformationT >
40 | bool ShouldSubdivide(const CellType &cell, BuildInformationT &bi) const
41 | {
42 | return bi.Level() < m_maxSubdivisionLevel;
43 | }
44 |
45 | private:
46 | size_t m_maxSubdivisionLevel;
47 | };
48 | };
49 | };
50 |
51 | #endif
52 |
--------------------------------------------------------------------------------
/3rd_ransac/GfxTL/MaxNorm.h:
--------------------------------------------------------------------------------
1 | #ifndef GfxTL__MAXNORM_HEADER__
2 | #define GfxTL__MAXNORM_HEADER__
3 | #include
4 | #include
5 | #include
6 |
7 | namespace GfxTL
8 | {
9 | template< class VectorKernelT >
10 | struct MaxNorm
11 | : public VectorKernelT
12 | {
13 | template< class ScalarAT, class ScalarBT >
14 | struct DistanceType
15 | {
16 | typedef typename ScalarTypeConversion< ScalarAT,
17 | ScalarBT >::DifferenceType Type;
18 | };
19 |
20 | template< class PointAT, class PointBT >
21 | typename DistanceType
22 | <
23 | typename ScalarTypeDeferer< PointAT >::ScalarType,
24 | typename ScalarTypeDeferer< PointBT >::ScalarType
25 | >::Type
26 | Distance(const PointAT &p, const PointBT &v) const
27 | {
28 | typedef typename DistanceType
29 | <
30 | typename ScalarTypeDeferer< PointAT >::ScalarType,
31 | typename ScalarTypeDeferer< PointBT >::ScalarType
32 | >::Type DistType;
33 | DistType di, max = Math< DistType >::Abs(p[0] - v[0]);
34 | for(size_t i = 1; i < m_dim; ++i)
35 | {
36 | di = Math< DistType >::Abs(p[i] - v[i]);
37 | if(di > max)
38 | max = di;
39 | }
40 | return max;
41 | }
42 |
43 | template< class PointAT, class PointBT >
44 | typename DistanceType
45 | <
46 | typename ScalarTypeDeferer< PointAT >::ScalarType,
47 | typename ScalarTypeDeferer< PointBT >::ScalarType
48 | >::Type
49 | SqrDistance(const PointAT &p, const PointBT &v) const
50 | {
51 | typedef typename DistanceType
52 | <
53 | typename ScalarTypeDeferer< PointAT >::ScalarType,
54 | typename ScalarTypeDeferer< PointBT >::ScalarType
55 | >::Type DistType;
56 | DistType di, max = Math< DistType >::Abs(p[0] - v[0]);
57 | for(size_t i = 1; i < m_dim; ++i)
58 | {
59 | di = Math< DistType >::Abs(p[i] - v[i]);
60 | if(di > max)
61 | max = di;
62 | }
63 | return max;
64 | }
65 |
66 | template< class ScalarT >
67 | ScalarT RootOfDistance(ScalarT sqrDistance) const
68 | {
69 | return sqrDistance;
70 | }
71 |
72 | template< class DistScalarT, class DiffScalarT >
73 | DistScalarT IncrementalBoxSqrDistance(DistScalarT boxDist, DiffScalarT boxDiff,
74 | DiffScalarT cutDiff) const
75 | {
76 | return std::max(boxDist, (DistScalarT)Math< DiffScalarT >::Abs(cutDiff));
77 | }
78 |
79 | template< class PointAT, class PointBT >
80 | typename DistanceType
81 | <
82 | typename ScalarTypeDeferer< PointAT >::ScalarType,
83 | typename ScalarTypeDeferer< PointBT >::ScalarType
84 | >::Type
85 | BoxSqrDistance(const PointAT &a, const PointBT &min,
86 | const PointBT &max) const
87 | {
88 | typename DistanceType
89 | <
90 | typename ScalarTypeDeferer< PointAT >::ScalarType,
91 | typename ScalarTypeDeferer< PointBT >::ScalarType
92 | >::Type sqrDist = 0, t;
93 | for(unsigned int i = 0; i < m_dim; ++i)
94 | {
95 | if(a[i] < min[i])
96 | {
97 | t = min[i] - a[i];
98 | if(t > sqrDist)
99 | sqrDist = t;
100 | }
101 | else if(a[i] > max[i])
102 | {
103 | t = a[i] - max[i];
104 | if(t > sqrDist)
105 | sqrDist = t;
106 | }
107 | }
108 | return sqrDist;
109 | }
110 | };
111 | };
112 |
113 | #endif
114 |
--------------------------------------------------------------------------------
/3rd_ransac/GfxTL/Mean.h:
--------------------------------------------------------------------------------
1 | #ifndef __GfxTL_MEAN_HEADER__
2 | #define __GfxTL_MEAN_HEADER__
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 |
11 | namespace GfxTL
12 | {
13 | template< class PointT, class PointsForwardIt, class WeightsForwardIt >
14 | void Mean(PointsForwardIt begin, PointsForwardIt end,
15 | WeightsForwardIt weights, PointT *mean)
16 | {
17 | mean->Zero();
18 | typename PointT::ScalarType totalWeight = 0;
19 | for(; begin != end; ++begin, ++weights)
20 | {
21 | *mean += typename PointT::ScalarType(*weights)
22 | * ((const PointT)(*begin));
23 | totalWeight += *weights;
24 | }
25 | if(totalWeight)
26 | *mean /= totalWeight;
27 | }
28 |
29 | template< class PointsForwardIt, class WeightsForwardIt,
30 | class ScalarT >
31 | void Mean(PointsForwardIt begin, PointsForwardIt end,
32 | WeightsForwardIt weights, VectorXD< 3, ScalarT > *mean)
33 | {
34 | mean->Zero();
35 | ScalarT totalWeight = 0, w;
36 | for(; begin != end; ++begin, ++weights)
37 | {
38 | w = (ScalarT)*weights;
39 | (*mean)[0] += w * (*begin)[0];
40 | (*mean)[1] += w * (*begin)[1];
41 | (*mean)[2] += w * (*begin)[2];
42 | totalWeight += w;
43 | }
44 | if(totalWeight)
45 | *mean /= totalWeight;
46 | }
47 |
48 | template< class PointT, class PointsForwardIt >
49 | void Mean(PointsForwardIt begin, PointsForwardIt end, PointT *mean)
50 | {
51 | Mean(begin, end, UnitWeightIterator(), mean);
52 | }
53 |
54 | // This computes an average of unoriented normals
55 | template< class NormalsItT, class WeightsItT, class MeanT >
56 | bool MeanOfNormals(NormalsItT begin, NormalsItT end, WeightsItT weights,
57 | MeanT *mean)
58 | {
59 | typedef typename MeanT::ScalarType ScalarType;
60 | enum { Dim = MeanT::Dim };
61 | GfxTL::MatrixXX< Dim, Dim, ScalarType > cov, eigenVectors;
62 | GfxTL::VectorXD< Dim, ScalarType > center, eigenValues;
63 | center.Zero();
64 | CovarianceMatrix(center, begin, end, weights, &cov);
65 | if(!Jacobi(cov, &eigenValues, &eigenVectors))
66 | {
67 | mean->Zero();
68 | return false;
69 | }
70 | // find the maximal eigenvalue and corresponding vector
71 | ScalarType maxEigVal = eigenValues[0];
72 | unsigned int maxEigIdx = 0;
73 | for(unsigned int i = 1; i < Dim; ++i)
74 | if(eigenValues[i] > maxEigVal)
75 | {
76 | maxEigVal = eigenValues[i];
77 | maxEigIdx = i;
78 | }
79 | *mean = MeanT(eigenVectors[maxEigIdx]);
80 | return true;
81 | }
82 |
83 | template< class NormalsItT, class MeanT >
84 | bool MeanOfNormals(NormalsItT begin, NormalsItT end, MeanT *mean)
85 | {
86 | return MeanOfNormals(begin, end, UnitWeightIterator(), mean);
87 | }
88 | };
89 |
90 | #endif
91 |
--------------------------------------------------------------------------------
/3rd_ransac/GfxTL/NearestNeighbor.h:
--------------------------------------------------------------------------------
1 | #ifndef GfxTL__NEARESTNEIGHBOR_HEADER__
2 | #define GfxTL__NEARESTNEIGHBOR_HEADER__
3 |
4 | namespace GfxTL
5 | {
6 |
7 | template< class ScalarT, class IndexT = size_t >
8 | struct NN
9 | {
10 | typedef ScalarT ScalarType;
11 | typedef IndexT IndexType;
12 | ScalarType sqrDist;
13 | IndexType index;
14 | NN() {}
15 | NN(ScalarType d, IndexType i)
16 | : sqrDist(d)
17 | , index(i)
18 | {}
19 | bool operator<(const NN &nn) const
20 | {
21 | return sqrDist < nn.sqrDist;
22 | }
23 | bool operator>(const NN &nn) const
24 | {
25 | return sqrDist > nn.sqrDist;
26 | }
27 | bool operator<=(const NN &nn) const
28 | {
29 | return sqrDist <= nn.sqrDist;
30 | }
31 | bool operator>=(const NN &nn) const
32 | {
33 | return sqrDist >= nn.sqrDist;
34 | }
35 | bool operator==(const NN &nn) const
36 | {
37 | return sqrDist == nn.sqrDist && index == nn.index;
38 | }
39 | bool operator!=(const NN &nn) const
40 | {
41 | return sqrDist != nn.sqrDist || index != nn.index;
42 | }
43 | operator IndexType() const
44 | {
45 | return index;
46 | }
47 | operator IndexType &()
48 | {
49 | return index;
50 | }
51 | operator ScalarType() const
52 | {
53 | return sqrDist;
54 | }
55 | };
56 |
57 | };
58 |
59 | #endif
60 |
--------------------------------------------------------------------------------
/3rd_ransac/GfxTL/NullClass.h:
--------------------------------------------------------------------------------
1 | #ifndef GfxTL_NULLCLASS_HEADER__
2 | #define GfxTL_NULLCLASS_HEADER__
3 |
4 | namespace GfxTL
5 | {
6 | class NullClass
7 | {};
8 | };
9 |
10 | #endif
11 |
--------------------------------------------------------------------------------
/3rd_ransac/GfxTL/NullStrategy.h:
--------------------------------------------------------------------------------
1 | #ifndef __GfxTL_NULLSTRATEGY_HEADER__
2 | #define __GfxTL_NULLSTRATEGY_HEADER__
3 |
4 | namespace GfxTL
5 | {
6 |
7 | class NullStrategy
8 | {
9 | public:
10 | template< class Point >
11 | class CellData
12 | {};
13 |
14 | template< class Base >
15 | class StrategyBase
16 | : public Base
17 | {
18 | public:
19 | typedef typename Base::CellType CellType;
20 | // typedef typename CellType::PointType PointType;
21 | // typedef typename CellType::ScalarType ScalarType;
22 |
23 | template< class BoundingVolume >
24 | inline bool RefreshCell(const BoundingVolume &bv,
25 | CellType *cell);
26 | template< class ParamT >
27 | inline void Parameters(const ParamT &);
28 | void StartPointInfoCache();
29 | void StopPointInfoCache();
30 |
31 | protected:
32 | bool ShouldSubdivide(const CellType &cell) const;
33 | void InitCellData(CellType *);
34 | void InitLevelDependentCellData(CellType *);
35 | };
36 | };
37 |
38 | template< class Base >
39 | template< class BoundingVolume >
40 | inline bool NullStrategy::StrategyBase< Base >::
41 | RefreshCell(const BoundingVolume &, CellType *)
42 | {
43 | return false;
44 | }
45 |
46 | template< class Base >
47 | template< class ParamT >
48 | inline void NullStrategy::StrategyBase< Base >::
49 | Parameters(const ParamT &)
50 | {}
51 |
52 | };
53 |
54 | #include "NullStrategy.hpp"
55 |
56 | #endif
--------------------------------------------------------------------------------
/3rd_ransac/GfxTL/NullStrategy.hpp:
--------------------------------------------------------------------------------
1 | namespace GfxTL
2 | {
3 |
4 | template< class Base >
5 | void NullStrategy::StrategyBase< Base >::StartPointInfoCache()
6 | {}
7 |
8 | template< class Base >
9 | void NullStrategy::StrategyBase< Base >::StopPointInfoCache()
10 | {}
11 |
12 | template< class Base >
13 | bool NullStrategy::StrategyBase< Base >::ShouldSubdivide(
14 | const CellType &cell) const
15 | {
16 | return false;
17 | }
18 |
19 | template< class Base >
20 | void NullStrategy::StrategyBase< Base >::InitCellData(CellType *)
21 | {}
22 |
23 | template< class Base >
24 | void NullStrategy::StrategyBase< Base >::
25 | InitLevelDependentCellData(CellType *)
26 | {}
27 |
28 | };
--------------------------------------------------------------------------------
/3rd_ransac/GfxTL/NullTreeStrategy.h:
--------------------------------------------------------------------------------
1 | #ifndef GfxTL__NULLTREESTRATEGY_HEADER__
2 | #define GfxTL__NULLTREESTRATEGY_HEADER__
3 |
4 | namespace GfxTL
5 | {
6 | struct NullTreeStrategy
7 | {
8 | struct CellData
9 | {};
10 |
11 | template< class BaseT >
12 | struct StrategyBase
13 | : public BaseT
14 | {};
15 | };
16 | };
17 |
18 | #endif
19 |
--------------------------------------------------------------------------------
/3rd_ransac/GfxTL/OnOff.h:
--------------------------------------------------------------------------------
1 | #ifndef GfxTL__ONOFF_HEADER__
2 | #define GfxTL__ONOFF_HEADER__
3 |
4 | namespace GfxTL
5 | {
6 |
7 | template< bool T >
8 | class OnOff {};
9 |
10 | typedef OnOff< true > On;
11 | typedef OnOff< false > Off;
12 | typedef OnOff< true > Yes;
13 | typedef OnOff< false > No;
14 |
15 | };
16 |
17 | #endif
18 |
--------------------------------------------------------------------------------
/3rd_ransac/GfxTL/Orientation.h:
--------------------------------------------------------------------------------
1 | #ifndef GfxTL__ORIENTATION_HEADER__
2 | #define GfxTL__ORIENTATION_HEADER__
3 |
4 | #include
5 |
6 | namespace GfxTL
7 | {
8 | template< class ScalarT >
9 | inline ScalarT Orientation(const VectorXD< 2, ScalarT > &p1,
10 | const VectorXD< 2, ScalarT > &p2,
11 | const VectorXD< 2, ScalarT > &c)
12 | {
13 | return ((p1[0] - c[0]) * (p2[1] - c[1])) -
14 | ((p1[1] - c[1]) * (p2[0] - c[0]));
15 | }
16 | };
17 |
18 | #endif
19 |
--------------------------------------------------------------------------------
/3rd_ransac/GfxTL/Plane.hpp:
--------------------------------------------------------------------------------
1 |
2 | namespace GfxTL
3 | {
4 | template< class PointT >
5 | Plane< PointT >::Plane()
6 | {}
7 |
8 | template< class PointT >
9 | Plane< PointT >::Plane(const PointType &normal, const PointType &origin)
10 | : _normal(normal)
11 | {
12 | _d = -(_normal * origin);
13 | }
14 |
15 | template< class PointT >
16 | void Plane< PointT >::Set(const PointType &origin, const PointType &normal)
17 | {
18 | _normal = normal;
19 | _d = -(_normal * origin);
20 | }
21 |
22 | template< class PointT >
23 | typename Plane< PointT >::ScalarType Plane< PointT >::SignedDistance(
24 | const PointType &p) const
25 | {
26 | return _normal * p + _d;
27 | }
28 |
29 | template< class PointT >
30 | void Plane< PointT >::Orient(const PointType &n)
31 | {
32 | ScalarType factor = Math< ScalarType >::Sign(_normal * n);
33 | _normal *= factor;
34 | _d *= factor;
35 | }
36 |
37 | template< class PointT >
38 | void Plane< PointT >::Project(const PointType &p, PointType *s) const
39 | {
40 | *s = p - SignedDistance(p) * _normal;
41 | }
42 |
43 | template< class PointT >
44 | void Plane< PointT >::Normal(PointType *normal) const
45 | {
46 | *normal = _normal;
47 | }
48 |
49 | template< class PointT >
50 | void Plane< PointT >::Normal(const PointType &normal)
51 | {
52 | _normal = normal;
53 | }
54 |
55 | template< class PointT >
56 | typename Plane< PointT >::PointType &Plane< PointT >::Normal()
57 | {
58 | return _normal;
59 | }
60 |
61 | template< class PointT >
62 | const typename Plane< PointT >::PointType &Plane< PointT >::Normal() const
63 | {
64 | return _normal;
65 | }
66 |
67 | template< class PointT >
68 | void Plane< PointT >::Origin(const PointType &o)
69 | {
70 | _d = -(_normal * o);
71 | }
72 |
73 | template< class PointT >
74 | typename Plane< PointT >::ScalarType Plane< PointT >::Intersect(
75 | const PointType &p, const PointType &r) const
76 | {
77 | return -SignedDistance(p) / (_normal * r);
78 | }
79 | };
80 |
--------------------------------------------------------------------------------
/3rd_ransac/GfxTL/ScalarTypeDeferer.h:
--------------------------------------------------------------------------------
1 | #ifndef GfxTL__SCALARTYPEDEFERER_HEADER__
2 | #define GfxTL__SCALARTYPEDEFERER_HEADER__
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 |
9 | namespace GfxTL
10 | {
11 | template< class PointT >
12 | struct ScalarTypeDeferer
13 | {
14 | typedef typename PointT::value_type ScalarType;
15 | };
16 |
17 | template< class ScalarT >
18 | struct ScalarTypeDeferer< ScalarT * >
19 | {
20 | typedef ScalarT ScalarType;
21 | };
22 |
23 | template< class ScalarT >
24 | struct ScalarTypeDeferer< const ScalarT * >
25 | {
26 | typedef ScalarT ScalarType;
27 | };
28 |
29 | template< unsigned int DimT, class ScalarT >
30 | struct ScalarTypeDeferer< VectorXD< DimT, ScalarT > >
31 | {
32 | typedef ScalarT ScalarType;
33 | };
34 |
35 | template< >
36 | struct ScalarTypeDeferer< float >
37 | {
38 | typedef float ScalarType;
39 | };
40 |
41 | template< >
42 | struct ScalarTypeDeferer< double >
43 | {
44 | typedef double ScalarType;
45 | };
46 |
47 | template< >
48 | struct ScalarTypeDeferer< int >
49 | {
50 | typedef int ScalarType;
51 | };
52 |
53 | template< >
54 | struct ScalarTypeDeferer< char >
55 | {
56 | typedef char ScalarType;
57 | };
58 |
59 | template< >
60 | struct ScalarTypeDeferer< short >
61 | {
62 | typedef short ScalarType;
63 | };
64 |
65 | template< class IteratorT >
66 | struct ScalarTypeDeferer< ArrayAccessor< 1, IteratorT > >
67 | {
68 | typedef typename ArrayAccessor< 1, IteratorT >::value_type ScalarType;
69 | };
70 |
71 | template< class T >
72 | struct ScalarTypeDeferer< std::unique_ptr< T > >
73 | {
74 | typedef T ScalarType;
75 | };
76 |
77 | template< class T, class A >
78 | struct ScalarTypeDeferer< MiscLib::Vector< T, A > >
79 | {
80 | typedef T ScalarType;
81 | };
82 |
83 | template< class T, class A >
84 | struct ScalarTypeDeferer< std::vector< T, A > >
85 | {
86 | typedef T ScalarType;
87 | };
88 | };
89 |
90 | #endif
91 |
--------------------------------------------------------------------------------
/3rd_ransac/GfxTL/ShuffleIndicesTreeDataKernelStrategy.h:
--------------------------------------------------------------------------------
1 | #ifndef GfxTL__SHUFFLEINDICESTREEDATAKERNELSTRATEGY_HEADER__
2 | #define GfxTL__SHUFFLEINDICESTREEDATAKERNELSTRATEGY_HEADER__
3 | #include
4 | #include
5 |
6 | namespace GfxTL
7 | {
8 | template< class DataKernelT,
9 | class ShuffleIndicesT = std::vector< unsigned int > >
10 | class ShuffleIndicesTreeDataKernelStrategy
11 | : public DataKernelT
12 | {
13 | public:
14 | typedef typename DataKernelT::value_type value_type;
15 | typedef typename DataKernelT::HandleType HandleType;
16 | typedef typename DataKernelT::DereferencedType DereferencedType;
17 |
18 | ShuffleIndicesTreeDataKernelStrategy() : m_shuffleIndices(NULL) {}
19 | void ShuffleIndices(ShuffleIndicesT *shuffleIndices)
20 | { m_shuffleIndices = shuffleIndices; }
21 | ShuffleIndicesT *ShuffleIndices() const { return m_shuffleIndices; }
22 |
23 | protected:
24 | void SwapHandles(HandleType a, HandleType b)
25 | {
26 | if(m_shuffleIndices)
27 | Swap(a, b, m_shuffleIndices);
28 | DataKernelT::SwapHandles(a, b);
29 | }
30 |
31 | private:
32 | ShuffleIndicesT *m_shuffleIndices;
33 | };
34 | };
35 |
36 | #endif
37 |
--------------------------------------------------------------------------------
/3rd_ransac/GfxTL/StdContainerAdaptor.h:
--------------------------------------------------------------------------------
1 | #ifndef __GfxTL_STDCONTAINERADAPTOR_HEADER__
2 | #define __GfxTL_STDCONTAINERADAPTOR_HEADER__
3 | #include
4 |
5 | namespace GfxTL
6 | {
7 | template< template< class, class > class ContainerT,
8 | template< class > class AllocatorT = std::allocator >
9 | struct StdContainerAdaptor
10 | {
11 | template< class T >
12 | class Container
13 | : public ContainerT< T, AllocatorT< T > >
14 | {
15 | public:
16 | typedef ContainerT< T, std::allocator< T > > ContainerType;
17 | Container() {}
18 | Container(typename ContainerType::size_type s)
19 | : ContainerType(s)
20 | {}
21 | Container(typename ContainerType::size_type s,
22 | const typename ContainerType::value_type &v)
23 | : ContainerType(s, v)
24 | {}
25 | };
26 | };
27 | };
28 |
29 | #endif
30 |
31 |
--------------------------------------------------------------------------------
/3rd_ransac/GfxTL/StdOverrides.h:
--------------------------------------------------------------------------------
1 | #ifndef GfxTL__STDOVERRIDES_HEADER__
2 | #define GfxTL__STDOVERRIDES_HEADER__
3 | #include
4 | #include
5 | #ifndef _USE_MATH_DEFINES
6 | #define _USE_MATH_DEFINES
7 | #endif
8 | #include
9 |
10 | namespace GfxTL
11 | {
12 |
13 | using std::swap;
14 | using std::min;
15 | using std::max;
16 | using std::sqrt;
17 |
18 | };
19 |
20 | #endif
21 |
--------------------------------------------------------------------------------
/3rd_ransac/GfxTL/Swap.h:
--------------------------------------------------------------------------------
1 | #ifndef GfxTL__SWAP_HEADER__
2 | #define GfxTL__SWAP_HEADER__
3 | #include
4 |
5 | namespace GfxTL
6 | {
7 |
8 | template< class ContainerT, class HandleT >
9 | void Swap(HandleT a, HandleT b, ContainerT *container)
10 | {
11 | using namespace std;
12 | swap(container->at(a), container->at(b));
13 | }
14 |
15 | };
16 |
17 | #endif
18 |
--------------------------------------------------------------------------------
/3rd_ransac/IndexIterator.h:
--------------------------------------------------------------------------------
1 | #ifndef INDEXITERATOR_HEADER
2 | #define INDEXITERATOR_HEADER
3 | #include
4 |
5 | #ifndef DLL_LINKAGE
6 | #define DLL_LINKAGE
7 | #endif
8 |
9 | class DLL_LINKAGE IndexIterator
10 | {
11 | public:
12 | typedef const size_t value_type;
13 | typedef value_type *pointer;
14 | typedef value_type &reference;
15 | typedef std::forward_iterator_tag iterator_category;
16 | typedef size_t size_type;
17 | typedef size_t difference_type;
18 | IndexIterator() {}
19 | IndexIterator(size_t index) : m_index(index) {}
20 | const size_t operator*() const { return m_index; }
21 | const size_t *operator->() const { return &m_index; }
22 | IndexIterator &operator++() { ++m_index; return *this; }
23 | IndexIterator operator++(int) { size_t save = m_index; ++m_index; return IndexIterator(save); }
24 | bool operator==(IndexIterator a) const { return m_index == a.m_index; }
25 | bool operator!=(IndexIterator a) const { return m_index != a.m_index; }
26 | IndexIterator &operator+=(size_t offset)
27 | {
28 | m_index += offset;
29 | return *this;
30 | }
31 | IndexIterator &operator-=(size_t offset)
32 | {
33 | m_index -= offset;
34 | return *this;
35 | }
36 | IndexIterator operator+(size_t offset) const
37 | {
38 | return IndexIterator(m_index + offset);
39 | }
40 | IndexIterator operator-(size_t offset) const
41 | {
42 | return IndexIterator(m_index - offset);
43 | }
44 | size_t operator-(IndexIterator i) const
45 | {
46 | return m_index - i.m_index;
47 | }
48 |
49 | size_t operator[](size_t i) const
50 | {
51 | return m_index + i;
52 | }
53 |
54 | private:
55 | size_t m_index;
56 | };
57 |
58 | #endif
59 |
--------------------------------------------------------------------------------
/3rd_ransac/LevMarFunc.h:
--------------------------------------------------------------------------------
1 | #ifndef LEVMARFUNC_HEADER
2 | #define LEVMARFUNC_HEADER
3 |
4 | template< class ScalarT >
5 | struct LevMarFunc {
6 | virtual ScalarT operator()(const ScalarT *param) const = 0;
7 | virtual void operator()(const ScalarT *param, ScalarT *gradient) const = 0;
8 | };
9 |
10 | #endif
11 |
--------------------------------------------------------------------------------
/3rd_ransac/LevMarLSWeight.h:
--------------------------------------------------------------------------------
1 | #ifndef LEVMARLSWEIGHT_HEADER
2 | #define LEVMARLSWEIGHT_HEADER
3 | #include
4 | #include
5 |
6 | #ifndef DLL_LINKAGE
7 | #define DLL_LINKAGE
8 | #endif
9 |
10 | class DLL_LINKAGE LevMarLSWeight
11 | {
12 | public:
13 | float Weigh(float d) const { return d; }
14 | template< unsigned int N >
15 | void DerivWeigh(float d, float *gradient) const {}
16 | };
17 |
18 | #endif
19 |
--------------------------------------------------------------------------------
/3rd_ransac/MiscLib/AlignedAllocator.h:
--------------------------------------------------------------------------------
1 | #ifndef MiscLib__ALIGNEDALLOCATOR_HEADER__
2 | #define MiscLib__ALIGNEDALLOCATOR_HEADER__
3 |
4 | #include
5 | #if defined(__APPLE__) || (defined(_WIN32) && defined(__MINGW32__))
6 | #include
7 | #else
8 | #include
9 | #endif
10 |
11 | #if defined(__x86_64__) || defined(__i386__) || defined(_M_IX86) || defined(_M_X64)
12 | #include
13 | #endif
14 |
15 | #ifdef _mm_malloc
16 | #ifndef a_malloc
17 | #define a_malloc(sz, align) _mm_malloc((sz), (align))
18 | #endif // !a_malloc
19 | #endif // !_mm_malloc
20 | #ifdef _mm_free
21 | #ifndef a_free
22 | #define a_free(ptr) _mm_free((ptr))
23 | #endif // !a_free
24 | #endif // !_mm_free
25 |
26 | #ifndef a_free
27 | #define a_free(a) free(a)
28 | #endif // !_mm_free
29 |
30 | #ifndef a_malloc
31 | #if defined(__APPLE__)
32 | #define a_malloc(sz, align) malloc(sz) // OSX aligns all allocations to 16 byte boundaries (except valloc which aligns to page boundaries) - so specific alignment requests are ignored.
33 | #elif (defined(_WIN32) && defined(__MINGW32__))
34 | // #define a_malloc(sz, align) _aligned_malloc((align), (sz)) // Liangliang: seems the order of the argument is wrong? But it still crashes after switched.
35 | #define a_malloc(sz, align) malloc(sz) // Liangliang: the normal malloc works.
36 | #else
37 | #define a_malloc(sz, align) aligned_alloc((align), (sz))
38 | #endif
39 | #endif // !a_malloc
40 |
41 | #include
42 | #ifdef max
43 | #undef max
44 | #endif
45 |
46 | namespace MiscLib
47 | {
48 |
49 | enum { DefaultAlignment = sizeof(size_t) };
50 |
51 | template< class T, unsigned int Align = DefaultAlignment >
52 | class AlignedAllocator
53 | {
54 | public:
55 | typedef size_t size_type;
56 | typedef ptrdiff_t difference_type;
57 | typedef T *pointer;
58 | typedef const T *const_pointer;
59 | typedef T &reference;
60 | typedef const T &const_reference;
61 | typedef T value_type;
62 | template< class U >
63 | struct rebind { typedef AlignedAllocator< U, Align > other; };
64 |
65 | AlignedAllocator() throw() {}
66 | AlignedAllocator(const AlignedAllocator< T, Align > &) throw() {}
67 | template< class U >
68 | AlignedAllocator(const AlignedAllocator< U, Align > &) throw() {}
69 | pointer address(reference x) const { return &x; }
70 | const_pointer address(const_reference x) const { return &x; }
71 | pointer allocate(size_type s, std::allocator< void >::const_pointer hint = 0)
72 | { return (T *)a_malloc(s * sizeof(T), Align); }
73 | void deallocate(pointer p, size_type) { a_free(p); }
74 | size_type max_size() const throw() { return std::numeric_limits< size_type >::max(); }
75 | void construct(pointer p, const T& val) { new(static_cast< void * >(p)) T(val); }
76 | void destroy(pointer p) { p->~T(); }
77 | template< class U >
78 | bool operator==(const AlignedAllocator< U, Align > &) const { return true; }
79 | template< class U >
80 | bool operator==(const U &) const { return false; }
81 | template< class U >
82 | bool operator!=(const AlignedAllocator< U, Align > &) const { return false; }
83 | template< class U >
84 | bool operator!=(const U &) const { return true; }
85 | };
86 |
87 | template< unsigned int Align = sizeof(size_t) >
88 | struct MakeFixedAlignedAllocator
89 | {
90 | template< class T >
91 | struct AllocType : public AlignedAllocator< T, Align > {};
92 | };
93 |
94 | };
95 |
96 | #endif
97 |
--------------------------------------------------------------------------------
/3rd_ransac/MiscLib/Pair.h:
--------------------------------------------------------------------------------
1 | #ifndef MiscLib__PAIR_HEADER__
2 | #define MiscLib__PAIR_HEADER__
3 | #include
4 |
5 | namespace MiscLib
6 | {
7 | template< class FirstT, class SecondT >
8 | struct Pair
9 | {
10 | typedef FirstT FirstType;
11 | typedef SecondT SecondType;
12 | Pair() {}
13 | Pair(FirstType &f, SecondType &s)
14 | : first(f)
15 | , second(s)
16 | {}
17 | Pair(const std::pair< FirstType, SecondType > &p)
18 | : first(p.first)
19 | , second(p.second)
20 | {}
21 | Pair< FirstType, SecondType > &operator=(
22 | const std::pair< FirstType, SecondType > &p)
23 | {
24 | first = p.first;
25 | second = p.second;
26 | }
27 | FirstType first;
28 | SecondType second;
29 | };
30 |
31 | template< class FirstT >
32 | struct Pair< FirstT, FirstT >
33 | {
34 | typedef FirstT FirstType;
35 | typedef FirstType SecondType;
36 | FirstType first, second;
37 | Pair() {}
38 | Pair(FirstType &f, SecondType &s)
39 | : first(f)
40 | , second(s)
41 | {}
42 | Pair(std::pair< FirstType, SecondType > &p)
43 | : first(p.first)
44 | , second(p.second)
45 | {}
46 | Pair< FirstType, SecondType > &operator=(
47 | const std::pair< FirstType, SecondType > &p)
48 | {
49 | first = p.first;
50 | second = p.second;
51 | }
52 | operator FirstType *() { return &first; }
53 | operator const FirstType *() const { return &first; }
54 | };
55 |
56 | template< class FirstT, class SecondT >
57 | Pair< FirstT, SecondT > MakePair(FirstT &first, SecondT &second)
58 | {
59 | return Pair< FirstT, SecondT >(first, second);
60 | }
61 | };
62 |
63 | #endif
64 |
--------------------------------------------------------------------------------
/3rd_ransac/MiscLib/Performance.h:
--------------------------------------------------------------------------------
1 | #ifndef MiscLib__PERFORMANCE_HEADER__
2 | #define MiscLib__PERFORMANCE_HEADER__
3 | #ifdef WIN32
4 | #include
5 | #undef max
6 | #undef min
7 | #endif
8 |
9 | namespace MiscLib
10 | {
11 | #ifdef WIN32
12 | typedef __int64 performance_t;
13 | inline performance_t GetPerformanceCounter()
14 | {
15 | LARGE_INTEGER count;
16 | QueryPerformanceCounter(&count);
17 | return count.QuadPart;
18 | }
19 | inline double GetPerformanceFreq()
20 | {
21 | LARGE_INTEGER dummy_performance_freq;
22 | QueryPerformanceFrequency(&dummy_performance_freq);
23 | performance_t performance_freq = dummy_performance_freq.QuadPart;
24 | return double(performance_freq);
25 | }
26 | #else
27 | typedef clock_t performance_t;
28 | inline performance_t GetPerformanceCounter()
29 | {
30 | return clock();
31 | }
32 | inline double GetPerformanceFreq() { return double(CLOCKS_PER_SEC); }
33 | #endif
34 | };
35 |
36 | #endif
37 |
--------------------------------------------------------------------------------
/3rd_ransac/MiscLib/Random.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * random.c
3 | *
4 | * implementiert lagged Fibonacci random sequence
5 | * exakt nach Knuth TAOCP Vol.2 pp.186f
6 | *
7 | */
8 | #include
9 | #include "Random.h"
10 |
11 | using namespace MiscLib;
12 |
13 | #define KK 100
14 | #define LL 37
15 | #define MM MiscLib_RN_RAND_MOD
16 | #define TT 70
17 |
18 | #define mod_diff(x,y) ( (x) - (y) & (MM-1) )
19 | #define is_odd(x) ( (x) & 1 )
20 | #define evenize(x) ( (x) & (MM-2) )
21 |
22 | size_t MiscLib::rn_buf[MiscLib_RN_BUFSIZE];
23 | size_t MiscLib::rn_point = MiscLib_RN_BUFSIZE;
24 |
25 | void MiscLib::rn_setseed(size_t seed)
26 | {
27 | int t, j;
28 | size_t x[KK+KK-1];
29 | size_t ss = evenize(seed+2);
30 | for (j=0;j=MM) ss-=MM-2;
34 | }
35 | for (;j0; j--) x[j+j]=x[j];
41 | for (j=KK+KK-2; j>KK-LL; j-=2) x[KK+KK-1-j]=evenize(x[j]);
42 | for (j=KK+KK-2; j>=KK; j--) if (is_odd(x[j])) {
43 | x[j-(KK-LL)]=mod_diff(x[j-(KK-LL)],x[j]);
44 | x[j-KK]=mod_diff(x[j-KK],x[j]);
45 | }
46 | if(is_odd(ss)) {
47 | for (j=KK;j>0;j--) x[j]=x[j-1];
48 | x[0]=x[KK];
49 | if (is_odd(x[KK])) x[LL]=mod_diff(x[LL],x[KK]);
50 | }
51 | if (ss) ss>>=1; else t--;
52 | }
53 | for (j=0;j idx)?
24 | rn_buf[idx] : rn_refresh();
25 | }
26 | inline size_t rn_urand(size_t m)
27 | {
28 | return rn_rand() % m;
29 | }
30 | inline float rn_frand()
31 | {
32 | return (float)rn_rand() / MiscLib_RN_RAND_MOD;
33 | }
34 | };
35 |
36 | #endif
37 |
--------------------------------------------------------------------------------
/3rd_ransac/MiscLib/RefCount.cpp:
--------------------------------------------------------------------------------
1 | #include "RefCount.h"
2 | #ifdef _DEBUG
3 | #include
4 | #endif
5 |
6 | using namespace MiscLib;
7 |
8 | RefCount::~RefCount()
9 | {
10 | #ifdef _DEBUG
11 | assert(m_refCount == 0);
12 | #endif
13 | }
14 |
--------------------------------------------------------------------------------
/3rd_ransac/MiscLib/RefCount.h:
--------------------------------------------------------------------------------
1 | #ifndef MiscLib__REFCOUNT_HEADER__
2 | #define MiscLib__REFCOUNT_HEADER__
3 | #ifdef DOPARALLEL
4 | #include
5 | #endif
6 |
7 | namespace MiscLib
8 | {
9 | class RefCount
10 | {
11 | public:
12 | inline RefCount();
13 | inline RefCount(const RefCount &);
14 | inline unsigned int AddRef() const;
15 | inline unsigned int Release() const;
16 | inline RefCount &operator=(const RefCount &);
17 |
18 | protected:
19 | virtual ~RefCount();
20 |
21 | private:
22 | mutable unsigned int m_refCount;
23 | };
24 |
25 | RefCount::RefCount()
26 | : m_refCount(1)
27 | {}
28 |
29 | RefCount::RefCount(const RefCount &)
30 | : m_refCount(1)
31 | {
32 | // do not copy the ref count!
33 | }
34 |
35 | unsigned int RefCount::AddRef() const
36 | {
37 | #ifdef DOPARALLEL
38 | #pragma omp atomic
39 | #endif
40 | ++m_refCount;
41 | return m_refCount;
42 | }
43 |
44 | unsigned int RefCount::Release() const
45 | {
46 | if(m_refCount == 1)
47 | {
48 | #ifdef DOPARALLEL
49 | #pragma omp critical
50 | #endif
51 | {
52 | if(m_refCount)
53 | {
54 | m_refCount = 0;
55 | delete this;
56 | }
57 | }
58 | return 0;
59 | }
60 | #ifdef DOPARALLEL
61 | #pragma omp atomic
62 | #endif
63 | --m_refCount;
64 | return m_refCount;
65 | }
66 |
67 | RefCount &RefCount::operator=(const RefCount &)
68 | {
69 | // do not copy the ref count!!!
70 | return *this;
71 | }
72 | };
73 |
74 | #endif
75 |
--------------------------------------------------------------------------------
/3rd_ransac/MiscLib/RefCountPtr.h:
--------------------------------------------------------------------------------
1 | #ifndef MiscLib__REFCOUNTPTR_HEADER__
2 | #define MiscLib__REFCOUNTPTR_HEADER__
3 |
4 | namespace MiscLib
5 | {
6 | template< class T >
7 | class RefCountPtr
8 | {
9 | public:
10 | RefCountPtr()
11 | : m_ptr(0)
12 | {}
13 |
14 | template< class P >
15 | RefCountPtr(P *ptr)
16 | : m_ptr(ptr)
17 | {
18 | if(m_ptr)
19 | m_ptr->AddRef();
20 | }
21 |
22 | RefCountPtr(const RefCountPtr< T > &ptr)
23 | : m_ptr(ptr.m_ptr)
24 | {
25 | if(m_ptr)
26 | m_ptr->AddRef();
27 | }
28 |
29 | template< class P >
30 | RefCountPtr(const RefCountPtr< P > &ptr)
31 | : m_ptr(ptr.m_ptr)
32 | {
33 | if(m_ptr)
34 | m_ptr->AddRef();
35 | }
36 |
37 | ~RefCountPtr()
38 | {
39 | if(m_ptr)
40 | m_ptr->Release();
41 | }
42 |
43 | void Release()
44 | {
45 | if(m_ptr)
46 | {
47 | m_ptr->Release();
48 | m_ptr = 0;
49 | }
50 | }
51 |
52 | template< class N >
53 | T *New()
54 | {
55 | if(m_ptr)
56 | m_ptr->Release();
57 | m_ptr = new N();
58 | return m_ptr;
59 | }
60 |
61 | RefCountPtr< T > &operator=(const RefCountPtr< T > &ptr)
62 | {
63 | if(m_ptr == ptr.m_ptr)
64 | return *this;
65 | if(m_ptr)
66 | m_ptr->Release();
67 | m_ptr = ptr.m_ptr;
68 | if(m_ptr)
69 | m_ptr->AddRef();
70 | return *this;
71 | }
72 |
73 | template< class P >
74 | RefCountPtr< T > &operator=(const RefCountPtr< P > &ptr)
75 | {
76 | if(m_ptr == ptr.m_ptr)
77 | return *this;
78 | if(m_ptr)
79 | m_ptr->Release();
80 | m_ptr = ptr.m_ptr;
81 | if(m_ptr)
82 | m_ptr->AddRef();
83 | return *this;
84 | }
85 |
86 | template< class P >
87 | RefCountPtr< T > &operator=(P *ptr)
88 | {
89 | if(m_ptr == ptr)
90 | return *this;
91 | if(m_ptr)
92 | m_ptr->Release();
93 | m_ptr = ptr;
94 | if(m_ptr)
95 | m_ptr->AddRef();
96 | return *this;
97 | }
98 |
99 | T *operator->()
100 | {
101 | return m_ptr;
102 | }
103 |
104 | const T *operator->() const
105 | {
106 | return m_ptr;
107 | }
108 |
109 | T &operator*()
110 | {
111 | return *m_ptr;
112 | }
113 |
114 | const T &operator*() const
115 | {
116 | return *m_ptr;
117 | }
118 |
119 | operator T *()
120 | {
121 | return m_ptr;
122 | }
123 |
124 | operator const T *() const
125 | {
126 | return m_ptr;
127 | }
128 |
129 | T *Ptr()
130 | {
131 | return m_ptr;
132 | }
133 |
134 | const T *Ptr() const
135 | {
136 | return m_ptr;
137 | }
138 |
139 | template< class P >
140 | bool operator==(const RefCountPtr< P > &ptr) const
141 | {
142 | return m_ptr == ptr.m_ptr;
143 | }
144 |
145 | template< class P >
146 | bool operator==(P *ptr) const
147 | {
148 | return m_ptr == ptr;
149 | }
150 |
151 | private:
152 | T *m_ptr;
153 | };
154 | };
155 |
156 | #endif
157 |
--------------------------------------------------------------------------------
/3rd_ransac/MiscLib/RefCounted.h:
--------------------------------------------------------------------------------
1 | #ifndef MiscLib__REFCOUNTED_HEADER__
2 | #define MiscLib__REFCOUNTED_HEADER__
3 | #ifdef DOPARALLEL
4 | #include
5 | #endif
6 |
7 | namespace MiscLib
8 | {
9 | template< class T >
10 | class RefCounted
11 | : public T
12 | {
13 | public:
14 | RefCounted()
15 | : m_refCount(1)
16 | {}
17 |
18 | RefCounted(const RefCounted< T > &r)
19 | : T(r)
20 | , m_refCount(1)
21 | {
22 | // do not copy the ref count!
23 | }
24 |
25 | unsigned int AddRef() const
26 | {
27 | #ifdef DOPARALLEL
28 | #pragma omp atomic
29 | #endif
30 | ++m_refCount;
31 | return m_refCount;
32 | }
33 |
34 | unsigned int Release() const
35 | {
36 | if(m_refCount == 1)
37 | {
38 | #ifdef DOPARALLEL
39 | #pragma omp critical
40 | #endif
41 | {
42 | if(m_refCount)
43 | {
44 | m_refCount = 0;
45 | delete this;
46 | }
47 | }
48 | return 0;
49 | }
50 | #ifdef DOPARALLEL
51 | #pragma omp atomic
52 | #endif
53 | --m_refCount;
54 | return m_refCount;
55 | }
56 |
57 | RefCounted &operator=(const RefCounted &r)
58 | {
59 | *((T *)this) = r;
60 | return *this; // do not copy the ref count!
61 | }
62 |
63 | protected:
64 | virtual ~RefCounted()
65 | {}
66 |
67 | private:
68 | mutable unsigned int m_refCount;
69 | };
70 | };
71 |
72 | #endif
73 |
--------------------------------------------------------------------------------
/3rd_ransac/Octree.h:
--------------------------------------------------------------------------------
1 | #ifndef OCTREE_HEADER
2 | #define OCTREE_HEADER
3 | #include "PointCloud.h"
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include
13 | #include
14 | #include
15 | #include "ScoreAACubeTreeStrategy.h"
16 | #include "RebuildAACubeTreeStrategy.h"
17 | #include
18 |
19 | typedef GfxTL::AACubeTree
20 | <
21 | 3, ScoreAACubeTreeStrategy
22 | <
23 | 3, RebuildAACubeTreeStrategy
24 | <
25 | GfxTL::BucketSizeMaxLevelSubdivisionTreeStrategy
26 | <
27 | GfxTL::CellLevelTreeStrategy
28 | <
29 | GfxTL::CellCenterAACubeTreeStrategy
30 | <
31 | 3,
32 | GfxTL::BaseAACubeTreeStrategy
33 | <
34 | GfxTL::CellRangeDataTreeStrategy
35 | <
36 | GfxTL::NullTreeStrategy,
37 | GfxTL::ShuffleIndicesTreeDataKernelStrategy
38 | <
39 | GfxTL::ImmediateRangeTreeDataKernel< PointCloud >,
40 | MiscLib::Vector< size_t >
41 | >
42 | >
43 | >
44 | >
45 | >
46 | >
47 | >
48 | >
49 | > ImmediateOctreeType;
50 |
51 | typedef GfxTL::AACubeTree
52 | <
53 | 3, ScoreAACubeTreeStrategy
54 | <
55 | 3, RebuildAACubeTreeStrategy
56 | <
57 | GfxTL::BucketSizeMaxLevelSubdivisionTreeStrategy
58 | <
59 | GfxTL::CellLevelTreeStrategy
60 | <
61 | GfxTL::CellCenterAACubeTreeStrategy
62 | <
63 | 3,
64 | GfxTL::BaseAACubeTreeStrategy
65 | <
66 | GfxTL::CellRangeDataTreeStrategy
67 | <
68 | GfxTL::NullTreeStrategy,
69 | GfxTL::IteratedIndexedIteratorTreeDataKernel
70 | <
71 | MiscLib::Vector< size_t >::iterator,
72 | PointCloud::const_iterator
73 | >
74 | >
75 | >
76 | >
77 | >
78 | >
79 | >
80 | >
81 | > IndexedOctreeType;
82 |
83 | #endif
84 |
--------------------------------------------------------------------------------
/3rd_ransac/Plane.h:
--------------------------------------------------------------------------------
1 | #ifndef _PLANE_H_
2 | #define _PLANE_H_
3 | #include "basic.h"
4 | #include
5 | #include "PointCloud.h"
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 |
12 | #ifndef DLL_LINKAGE
13 | #define DLL_LINKAGE
14 | #endif
15 |
16 | class DLL_LINKAGE Plane
17 | {
18 | public:
19 | enum { RequiredSamples = 1 };
20 | Plane() {}
21 | Plane(Vec3f p1, Vec3f p2, Vec3f p3);
22 | Plane(Vec3f p1, Vec3f normal);
23 | virtual ~Plane();
24 | bool Init(Vec3f p1, Vec3f p2, Vec3f p3);
25 | bool Init(const MiscLib::Vector< Vec3f > &samples);
26 | bool InitAverage(const MiscLib::Vector< Vec3f > &samples);
27 | bool Init(bool binary, std::istream *i);
28 | void Init(FILE *i);
29 | void Init(float* array);
30 | float getDistance (const Vec3f &pos) const {return fabs(m_dist - m_normal.dot(pos));}
31 | float Distance(const Vec3f &pos) const { return fabs(m_dist - m_normal.dot(pos)); }
32 | float SignedDistance(const Vec3f &pos) const { return m_normal.dot(pos) - m_dist; }
33 | void Normal(const Vec3f &, Vec3f *n) const { *n = m_normal; }
34 | float DistanceAndNormal(const Vec3f &pos, Vec3f *n) const { *n = m_normal; return Distance(pos); }
35 | const Vec3f &getNormal () const {return m_normal;}
36 | const Vec3f &getPosition () const {return m_pos;}
37 | bool equals (Plane plane);
38 | float SignedDistToOrigin() const { return m_dist; }
39 | bool Fit(const PointCloud &pc,
40 | MiscLib::Vector< size_t >::const_iterator begin,
41 | MiscLib::Vector< size_t >::const_iterator end)
42 | { return LeastSquaresFit(pc, begin, end); }
43 | bool LeastSquaresFit(const PointCloud &pc,
44 | MiscLib::Vector< size_t >::const_iterator begin,
45 | MiscLib::Vector< size_t >::const_iterator end);
46 | template< class IteratorT >
47 | bool LeastSquaresFit(IteratorT begin, IteratorT end);
48 | static bool Interpolate(const MiscLib::Vector< Plane > &planes,
49 | const MiscLib::Vector< float > &weights, Plane *ip);
50 | void Serialize(bool binary, std::ostream *o) const;
51 | static size_t SerializedSize();
52 | void Serialize(FILE *o) const;
53 | void Serialize(float* array) const;
54 | static size_t SerializedFloatSize();
55 |
56 | void Transform(float scale, const Vec3f &translate);
57 | float Intersect(const Vec3f &p, const Vec3f &r) const;
58 |
59 | protected:
60 | Vec3f m_normal;
61 | Vec3f m_pos;
62 | float m_dist;
63 | };
64 |
65 | template< class IteratorT >
66 | bool Plane::LeastSquaresFit(IteratorT begin, IteratorT end)
67 | {
68 | GfxTL::Plane< GfxTL::Vector3Df > pl;
69 | GfxTL::Vector3Df mean;
70 | GfxTL::Mean(begin, end, &mean);
71 | pl.Fit(mean, begin, end);
72 | *this = Plane(Vec3f(mean.Data()), Vec3f(pl.Normal().Data()));
73 | return true;
74 | }
75 |
76 | #endif //_PLANE_H_
77 |
--------------------------------------------------------------------------------
/3rd_ransac/PlanePrimitiveShapeConstructor.cpp:
--------------------------------------------------------------------------------
1 | #include "PlanePrimitiveShapeConstructor.h"
2 | #include "PlanePrimitiveShape.h"
3 | #include "ScoreComputer.h"
4 | #include
5 |
6 | size_t PlanePrimitiveShapeConstructor::Identifier() const
7 | {
8 | return 0;
9 | }
10 |
11 | unsigned int PlanePrimitiveShapeConstructor::RequiredSamples() const
12 | {
13 | return 3;
14 | }
15 |
16 | PrimitiveShape *PlanePrimitiveShapeConstructor::Construct(
17 | const MiscLib::Vector< Vec3f > &points, const MiscLib::Vector< Vec3f > &) const
18 | {
19 | return new PlanePrimitiveShape(points[0], points[1], points[2]);
20 | }
21 |
22 | PrimitiveShape *PlanePrimitiveShapeConstructor::Construct(
23 | const MiscLib::Vector< Vec3f > &samples) const
24 | {
25 | Plane plane;
26 | if(!plane.Init(samples))
27 | return NULL;
28 | return new PlanePrimitiveShape(plane);
29 | }
30 |
31 | PrimitiveShape *PlanePrimitiveShapeConstructor::Deserialize(std::istream *i,
32 | bool binary) const
33 | {
34 | Plane plane;
35 | plane.Init(binary, i);
36 | PlanePrimitiveShape *shape = new PlanePrimitiveShape(plane);
37 | return shape;
38 | }
39 |
40 | size_t PlanePrimitiveShapeConstructor::SerializedSize() const
41 | {
42 | return Plane::SerializedSize();
43 | }
44 |
--------------------------------------------------------------------------------
/3rd_ransac/PlanePrimitiveShapeConstructor.h:
--------------------------------------------------------------------------------
1 | #ifndef PLANEPRIMITIVESHAPECONSTRUCTOR_HEADER
2 | #define PLANEPRIMITIVESHAPECONSTRUCTOR_HEADER
3 | #include "PrimitiveShapeConstructor.h"
4 |
5 | #ifndef DLL_LINKAGE
6 | #define DLL_LINKAGE
7 | #endif
8 |
9 | class DLL_LINKAGE PlanePrimitiveShapeConstructor
10 | : public PrimitiveShapeConstructor
11 | {
12 | public:
13 | size_t Identifier() const;
14 | unsigned int RequiredSamples() const;
15 | PrimitiveShape *Construct(const MiscLib::Vector< Vec3f > &points,
16 | const MiscLib::Vector< Vec3f > &normals) const;
17 | PrimitiveShape *Construct(const MiscLib::Vector< Vec3f > &samples) const;
18 | PrimitiveShape *Deserialize(std::istream *i, bool binary = true) const;
19 | size_t SerializedSize() const;
20 | };
21 |
22 | #endif
23 |
--------------------------------------------------------------------------------
/3rd_ransac/PointCloud.h:
--------------------------------------------------------------------------------
1 | #ifndef _POINTCLOUD_H
2 | #define _POINTCLOUD_H
3 | #include
4 | #ifndef _USE_MATH_DEFINES
5 | #define _USE_MATH_DEFINES
6 | #endif
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include "basic.h"
12 | #include
13 | #include
14 | #undef min
15 | #undef max
16 |
17 |
18 | #define POINT_HAS_INDEX // Liangliang: easy feedback
19 |
20 |
21 | #ifndef DLL_LINKAGE
22 | #define DLL_LINKAGE
23 | #endif
24 |
25 | struct DLL_LINKAGE Point {
26 | enum { Dim = 3 };
27 | typedef float ScalarType;
28 | typedef float value_type;
29 | Vec3f pos;
30 | Vec3f normal;
31 |
32 | #ifdef POINT_HAS_INDEX
33 | std::size_t index;
34 | #endif
35 |
36 | //unsigned int meshFaceIndex;
37 | Point() {}
38 | Point(const Vec3f &Pos) {/*index = -1;*/ pos = Pos; normal = Vec3f(0,0,0); }
39 | Point(const Vec3f &Pos, const Vec3f &Normal) { pos = Pos; normal = Normal; }
40 | const float operator[](unsigned int i) const
41 | {
42 | return pos[i];
43 | }
44 | float &operator[](unsigned int i)
45 | {
46 | return pos[i];
47 | }
48 | operator const Vec3f &() const
49 | {
50 | return pos;
51 | }
52 | operator Vec3f &()
53 | {
54 | return pos;
55 | }
56 | operator GfxTL::VectorXD< 3, float > &()
57 | {
58 | return *reinterpret_cast< GfxTL::Vector3Df * >(&pos);
59 | }
60 | operator const GfxTL::VectorXD< 3, float > &() const
61 | {
62 | return *reinterpret_cast< const GfxTL::Vector3Df * >(&pos);
63 | }
64 | };
65 |
66 | class DLL_LINKAGE PointCloud
67 | : public MiscLib::Vector< Point >
68 | {
69 | public:
70 | PointCloud();
71 | PointCloud(Point *points, unsigned int size);
72 | PointCloud &operator+=(const PointCloud &other)
73 | {
74 | size_t oldSize = size();
75 | resize(oldSize + other.size());
76 | std::copy(other.begin(), other.end(), begin() + oldSize);
77 | m_min = Vec3f(std::min(m_min[0], other.m_min[0]),
78 | std::min(m_min[1], other.m_min[1]),
79 | std::min(m_min[2], other.m_min[2]));
80 | m_max = Vec3f(std::max(m_max[0], other.m_max[0]),
81 | std::max(m_max[1], other.m_max[1]),
82 | std::max(m_max[2], other.m_max[2]));
83 | return *this;
84 | }
85 | void swapPoints (unsigned int i, unsigned int j)
86 | {
87 | std::swap(at(i), at(j));
88 | }
89 | void calcNormals( float radius, unsigned int kNN = 20, unsigned int maxTries = 100 );
90 | void reset(size_t s = 0);
91 | void setBBox (Vec3f bbl, float size) { m_min = bbl; m_max = m_min + Vec3f(size,size,size); }
92 | void setBBox (Vec3f min, Vec3f max) { m_min = min; m_max = max; }
93 | void widenBBox (float delta) { Vec3f d(delta,delta,delta); m_min -=d; m_max += d; }
94 | float getScale() const
95 | {
96 | Vec3f diff = m_max - m_min;
97 | return std::max(std::max(diff[0], diff[1]), diff[2]);
98 | }
99 | const Vec3f &getOffset() const { return m_min; }
100 | float *getBbox () const;
101 | // returns a transfromed bbox if m_transformed is true
102 | void GetCurrentBBox(Vec3f *min, Vec3f *max) const;
103 | const Vec3f &GetBBoxMin() const { return m_min; }
104 | const Vec3f &GetBBoxMax() const { return m_max; }
105 | Vec3f &GetBBoxMin() { return m_min; }
106 | Vec3f &GetBBoxMax() { return m_max; }
107 | void Translate(const Vec3f &trans);
108 |
109 | private:
110 | Vec3f m_min, m_max;
111 | };
112 |
113 | #endif
114 |
--------------------------------------------------------------------------------
/3rd_ransac/PrimitiveShapeConstructor.h:
--------------------------------------------------------------------------------
1 | #ifndef PRIMITIVESHAPECONSTRUCTOR_HEADER
2 | #define PRIMITIVESHAPECONSTRUCTOR_HEADER
3 | #include "PrimitiveShape.h"
4 | #include "PointCloud.h"
5 | #include
6 | #include
7 | #include
8 | #include
9 |
10 | #ifndef DLL_LINKAGE
11 | #define DLL_LINKAGE
12 | #endif
13 |
14 | #ifdef WIN32
15 | #ifndef DEPRECATED
16 | #define DEPRECATED __declspec(deprecated)
17 | #endif
18 | #else
19 | #define DEPRECATED
20 | #endif
21 |
22 | class DLL_LINKAGE PrimitiveShapeConstructor
23 | : public MiscLib::RefCount
24 | {
25 | public:
26 | virtual size_t Identifier() const = 0;
27 | virtual unsigned int RequiredSamples() const = 0;
28 | virtual PrimitiveShape *Construct(const MiscLib::Vector< Vec3f > &points,
29 | const MiscLib::Vector< Vec3f > &normals) const = 0;
30 | virtual PrimitiveShape *Construct(
31 | const MiscLib::Vector< Vec3f > &samples) const = 0;
32 | virtual PrimitiveShape *Deserialize(std::istream *i,
33 | bool binary = true) const = 0;
34 | virtual size_t SerializedSize() const = 0; // returns the serialized size excluding the identifier byte
35 | };
36 |
37 | #endif
38 |
--------------------------------------------------------------------------------
/3rd_ransac/PrimitiveShapeVisitor.h:
--------------------------------------------------------------------------------
1 | #ifndef PRIMITIVESHAPEVISITOR_HEADER
2 | #define PRIMITIVESHAPEVISITOR_HEADER
3 |
4 | #ifndef DLL_LINKAGE
5 | #define DLL_LINKAGE
6 | #endif
7 |
8 | class DLL_LINKAGE PlanePrimitiveShape;
9 | class DLL_LINKAGE SpherePrimitiveShape;
10 | class DLL_LINKAGE CylinderPrimitiveShape;
11 | class DLL_LINKAGE ConePrimitiveShape;
12 | class DLL_LINKAGE TorusPrimitiveShape;
13 |
14 | class DLL_LINKAGE PrimitiveShapeVisitor
15 | {
16 | public:
17 | virtual ~PrimitiveShapeVisitor() {}
18 | virtual void Visit(const PlanePrimitiveShape &plane) = 0;
19 | virtual void Visit(const SpherePrimitiveShape &sphere) = 0;
20 | virtual void Visit(const CylinderPrimitiveShape &cylinder) = 0;
21 | virtual void Visit(const ConePrimitiveShape &cone) = 0;
22 | virtual void Visit(const TorusPrimitiveShape &torus) = 0;
23 | };
24 |
25 | template< class BaseT >
26 | class PrimitiveShapeVisitorShell
27 | : public BaseT
28 | {
29 | public:
30 | PrimitiveShapeVisitorShell() {}
31 |
32 | template< class T >
33 | PrimitiveShapeVisitorShell(const T &t)
34 | : BaseT(t)
35 | {}
36 |
37 | template< class A, class B >
38 | PrimitiveShapeVisitorShell(const A &a, const B &b)
39 | : BaseT(a, b)
40 | {}
41 |
42 | void Visit(const PlanePrimitiveShape &plane)
43 | {
44 | BaseT::Visit(plane);
45 | }
46 |
47 | void Visit(const SpherePrimitiveShape &sphere)
48 | {
49 | BaseT::Visit(sphere);
50 | }
51 |
52 | void Visit(const CylinderPrimitiveShape &cylinder)
53 | {
54 | BaseT::Visit(cylinder);
55 | }
56 |
57 | void Visit(const ConePrimitiveShape &cone)
58 | {
59 | BaseT::Visit(cone);
60 | }
61 |
62 | void Visit(const TorusPrimitiveShape &torus)
63 | {
64 | BaseT::Visit(torus);
65 | }
66 | };
67 |
68 | #endif
69 |
--------------------------------------------------------------------------------
/3rd_ransac/RANSAC_orig in release does not work_Issue_523_CloudCompare.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LiangliangNan/ManhattanModeler/ef257690a2c3f4d36be430452db5bbb2d1bd54b0/3rd_ransac/RANSAC_orig in release does not work_Issue_523_CloudCompare.pdf
--------------------------------------------------------------------------------
/3rd_ransac/ScoreComputer.h:
--------------------------------------------------------------------------------
1 | #ifndef SCORECOMPUTER_HEADER
2 | #define SCORECOMPUTER_HEADER
3 | #include
4 | #ifndef _USE_MATH_DEFINES
5 | #define _USE_MATH_DEFINES
6 | #endif
7 | #include
8 | #include "PointCloud.h"
9 |
10 | inline float weigh(const float d, const float eps)
11 | {
12 | return std::exp(-d * d / (2.f / 9.f * eps * eps)); // gaussian weighting eps / 3 == sigma
13 | // return 1.f - (d / eps) * (d / eps); // anti-quadratic weighting
14 | // return 1.f - d / eps; // linear weighting
15 | //return d * d; // SSE
16 | }
17 |
18 | template< class BaseT >
19 | class LocalScoreComputer
20 | : public BaseT
21 | {
22 | public:
23 | template< class ShapeT >
24 | static void Score(const ShapeT &shape, const PointCloud &pc, float epsilon,
25 | float normalThresh, MiscLib::Vector< size_t >::const_iterator begin,
26 | MiscLib::Vector< size_t >::const_iterator end,
27 | std::pair< size_t, float > *score,
28 | MiscLib::Vector< size_t > *indices = NULL)
29 | {
30 | Vec3f n;
31 | size_t size = end - begin;
32 | for(size_t iter = 0; iter < size; ++iter)
33 | {
34 | float d = shape.DistanceAndNormal(pc[begin[iter]].pos, &n);
35 | float nd = n.dot(pc[begin[iter]].normal);
36 | if(d < epsilon && fabs(nd) > normalThresh)
37 | {
38 | ++score->first;
39 | score->second += weigh(d,epsilon);
40 | }
41 | }
42 | }
43 | };
44 |
45 | #endif
46 |
--------------------------------------------------------------------------------
/3rd_ransac/ScorePrimitiveShapeVisitor.h:
--------------------------------------------------------------------------------
1 | #ifndef SCOREPRIMITIVESHAPEVISITOR_HEADER
2 | #define SCOREPRIMITIVESHAPEVISITOR_HEADER
3 | #include "PrimitiveShapeVisitor.h"
4 | #include
5 | #include
6 | #include
7 | #include "PlanePrimitiveShape.h"
8 | #include "SpherePrimitiveShape.h"
9 | #include "CylinderPrimitiveShape.h"
10 | #include "ConePrimitiveShape.h"
11 | #include "TorusPrimitiveShape.h"
12 |
13 | template< class PointCompT, class OctreeT >
14 | class ScorePrimitiveShapeVisitorImpl
15 | : public PrimitiveShapeVisitor
16 | {
17 | public:
18 | typedef PointCompT PointCompatibilityFunc;
19 | typedef OctreeT OctreeType;
20 | typedef MiscLib::RefCounted< MiscLib::Vector< size_t > > IndicesType;
21 | ScorePrimitiveShapeVisitorImpl(float distThresh,
22 | float normalThresh) : m_pointComp(distThresh, normalThresh) {}
23 | void SetOctree(const OctreeT &oct) { m_oct = &oct; }
24 | const OctreeT &GetOctree() const { return *m_oct; }
25 | IndicesType *GetIndices() { return m_indices; }
26 | void SetIndices(IndicesType *indices) { m_indices = indices; }
27 | void SetShapeIndex(const MiscLib::Vector< int > &shapeIndex)
28 | { m_shapeIndex = &shapeIndex; }
29 | const MiscLib::Vector< int > &GetShapeIndex() { return *m_shapeIndex; }
30 | template< class ShapeT >
31 | void Visit(const ShapeT &primShape)
32 | {
33 | //if(!m_indices)
34 | // m_indices.New< IndicesType >();
35 | //m_upperBound = 0;
36 | //m_sampled = 0;
37 | m_oct->Score(primShape.Internal(), /*1,*/ this);
38 | }
39 | template< class ShapeT, class OctT >
40 | void operator()(const ShapeT &shape, const OctT &oct, size_t i)
41 | {
42 | if((*m_shapeIndex)[i] != -1)
43 | return;
44 | if(m_pointComp(shape, oct, i))
45 | m_indices->push_back(i);
46 | }
47 | float Epsilon() const { return m_pointComp.DistanceThresh(); }
48 | //size_t &UpperBound() { return m_upperBound; }
49 | //size_t &SampledPoints() { return m_sampled; }
50 | const PointCompatibilityFunc &PointCompFunc() const { return m_pointComp; }
51 |
52 | private:
53 | PointCompatibilityFunc m_pointComp;
54 | const OctreeT *m_oct;
55 | /*MiscLib::RefCountPtr<*/ IndicesType /*>*/ *m_indices;
56 | const MiscLib::Vector< int > *m_shapeIndex;
57 | //size_t m_upperBound;
58 | //size_t m_sampled;
59 | };
60 |
61 | template< class PointCompT, class OctreeT >
62 | class ScorePrimitiveShapeVisitor
63 | : public PrimitiveShapeVisitorShell< ScorePrimitiveShapeVisitorImpl< PointCompT, OctreeT > >
64 | {
65 | public:
66 | ScorePrimitiveShapeVisitor(float distThresh,
67 | float normalThresh) : PrimitiveShapeVisitorShell<
68 | ScorePrimitiveShapeVisitorImpl< PointCompT, OctreeT > >(
69 | distThresh, normalThresh) {}
70 | };
71 |
72 | #endif
73 |
--------------------------------------------------------------------------------
/3rd_ransac/SimpleTorusParametrization.cpp:
--------------------------------------------------------------------------------
1 | #include "SimpleTorusParametrization.h"
2 |
3 | SimpleTorusParametrization::SimpleTorusParametrization(
4 | const Torus &torus)
5 | : m_torus(&torus)
6 | {
7 | m_hcs.FromNormal(m_torus->AxisDirection());
8 | }
9 |
10 | void SimpleTorusParametrization::Shape(const Torus &torus)
11 | {
12 | m_torus = &torus;
13 | m_hcs.FromNormal(m_torus->AxisDirection());
14 | }
15 |
16 | void SimpleTorusParametrization::WrapBitmap(const GfxTL::AABox< GfxTL::Vector2Df > &bbox,
17 | float epsilon, bool *uwrap, bool *vwrap) const
18 | {
19 | if(bbox.Max()[0] - bbox.Min()[0] >= 2 * M_PI *
20 | ((m_torus->MajorRadius() < m_torus->MinorRadius() * 2) ?
21 | m_torus->MajorRadius() + m_torus->MinorRadius() : m_torus->MajorRadius()) - 2 * epsilon)
22 | *uwrap = true; // wrap around major component
23 | else
24 | *uwrap = false;
25 | if(bbox.Max()[1] - bbox.Min()[1] >= 2 * M_PI * m_torus->MinorRadius() - 2 * epsilon)
26 | *vwrap = true; // wrap around minor component
27 | else
28 | *vwrap = false;
29 | }
30 |
31 | size_t SimpleTorusParametrization::SerializedSize()
32 | {
33 | return sizeof(float);
34 | }
35 |
36 | void SimpleTorusParametrization::Serialize(std::ostream *o, bool binary) const
37 | {
38 | // for now only output placeholder for rotation of hcs
39 | float rot = 0;
40 | if(binary)
41 | o->write((char *)&rot, sizeof(rot));
42 | else
43 | *o << rot << " ";
44 | }
45 |
46 | void SimpleTorusParametrization::Deserialize(std::istream *i, bool binary)
47 | {
48 | // read the placeholder
49 | float rot;
50 | if(binary)
51 | i->read((char *)&rot, sizeof(rot));
52 | else
53 | *i >> rot;
54 | }
55 |
--------------------------------------------------------------------------------
/3rd_ransac/SpherePrimitiveShapeConstructor.cpp:
--------------------------------------------------------------------------------
1 | #include "SpherePrimitiveShapeConstructor.h"
2 | #include "SpherePrimitiveShape.h"
3 | #include "ScoreComputer.h"
4 | #include
5 |
6 | SpherePrimitiveShapeConstructor::SpherePrimitiveShapeConstructor(
7 | float maxSphereRadius)
8 | : m_maxSphereRadius(maxSphereRadius)
9 | {}
10 |
11 | size_t SpherePrimitiveShapeConstructor::Identifier() const
12 | {
13 | return 1;
14 | }
15 |
16 | unsigned int SpherePrimitiveShapeConstructor::RequiredSamples() const
17 | {
18 | // we use only 2pts with normals
19 | return 2;//4;
20 | }
21 |
22 | PrimitiveShape *SpherePrimitiveShapeConstructor::Construct(
23 | const MiscLib::Vector< Vec3f > &points,
24 | const MiscLib::Vector< Vec3f > &normals) const
25 | {
26 | Sphere sphere;
27 | if(!sphere.Init2(points[0], points[1], normals[0], normals[1]))//points[2], points[3]))
28 | return NULL;
29 | if(sphere.Radius() > m_maxSphereRadius)
30 | return NULL;
31 | return new SpherePrimitiveShape(sphere);
32 | }
33 |
34 | PrimitiveShape *SpherePrimitiveShapeConstructor::Construct(
35 | const MiscLib::Vector< Vec3f > &samples) const
36 | {
37 | Sphere sphere;
38 | if(!sphere.Init(samples))
39 | return NULL;
40 | return new SpherePrimitiveShape(sphere);
41 | }
42 |
43 | PrimitiveShape *SpherePrimitiveShapeConstructor::Deserialize(std::istream *i,
44 | bool binary) const
45 | {
46 | SpherePrimitiveShape *shape = new SpherePrimitiveShape();
47 | shape->Deserialize(i, binary);
48 | return shape;
49 | }
50 |
51 | size_t SpherePrimitiveShapeConstructor::SerializedSize() const
52 | {
53 | return Sphere::SerializedSize()
54 | + SpherePrimitiveShape::ParametrizationType::SerializedSize();
55 | }
56 |
--------------------------------------------------------------------------------
/3rd_ransac/SpherePrimitiveShapeConstructor.h:
--------------------------------------------------------------------------------
1 | #ifndef SPHEREPRIMITIVESHAPECONSTRUCTOR_HEADER
2 | #define SPHEREPRIMITIVESHAPECONSTRUCTOR_HEADER
3 | #include "PrimitiveShapeConstructor.h"
4 | #include
5 |
6 | #ifndef DLL_LINKAGE
7 | #define DLL_LINKAGE
8 | #endif
9 |
10 | class DLL_LINKAGE SpherePrimitiveShapeConstructor
11 | : public PrimitiveShapeConstructor
12 | {
13 | public:
14 | SpherePrimitiveShapeConstructor(float maxSphereRadius =
15 | std::numeric_limits< float >::infinity());
16 | size_t Identifier() const;
17 | unsigned int RequiredSamples() const;
18 | PrimitiveShape *Construct(const MiscLib::Vector< Vec3f > &points,
19 | const MiscLib::Vector< Vec3f > &normals) const;
20 | PrimitiveShape *Construct(const MiscLib::Vector< Vec3f > &samples) const;
21 | PrimitiveShape *Deserialize(std::istream *i, bool binary = true) const;
22 | size_t SerializedSize() const;
23 |
24 | private:
25 | float m_maxSphereRadius;
26 | };
27 |
28 | #endif
29 |
--------------------------------------------------------------------------------
/3rd_ransac/TorusPrimitiveShapeConstructor.cpp:
--------------------------------------------------------------------------------
1 | #include "TorusPrimitiveShapeConstructor.h"
2 | #include "TorusPrimitiveShape.h"
3 | #include "ScoreComputer.h"
4 | #include
5 |
6 | size_t TorusPrimitiveShapeConstructor::Identifier() const
7 | {
8 | return 4;
9 | }
10 |
11 | unsigned int TorusPrimitiveShapeConstructor::RequiredSamples() const
12 | {
13 | return 4;
14 | }
15 |
16 | PrimitiveShape *TorusPrimitiveShapeConstructor::Construct(
17 | const MiscLib::Vector< Vec3f > &points,
18 | const MiscLib::Vector< Vec3f > &normals) const
19 | {
20 | MiscLib::Vector< Vec3f > samples;
21 | for(size_t i = 0; i < points.size(); ++i)
22 | samples.push_back(points[i]);
23 | for(size_t i = 0; i < normals.size(); ++i)
24 | samples.push_back(normals[i]);
25 | return Construct(samples);
26 | }
27 |
28 | PrimitiveShape *TorusPrimitiveShapeConstructor::Construct(
29 | const MiscLib::Vector< Vec3f > &samples) const
30 | {
31 | Torus torus;
32 | if(!torus.Init(samples))
33 | return NULL;
34 | return new TorusPrimitiveShape(torus);
35 | }
36 |
37 | PrimitiveShape *TorusPrimitiveShapeConstructor::Deserialize(std::istream *i,
38 | bool binary) const
39 | {
40 | TorusPrimitiveShape *shape = new TorusPrimitiveShape();
41 | shape->Deserialize(i, binary);
42 | return shape;
43 | }
44 |
45 | size_t TorusPrimitiveShapeConstructor::SerializedSize() const
46 | {
47 | return Torus::SerializedSize() +
48 | TorusPrimitiveShape::ParametrizationType::SerializedSize();
49 | }
50 |
--------------------------------------------------------------------------------
/3rd_ransac/TorusPrimitiveShapeConstructor.h:
--------------------------------------------------------------------------------
1 | #ifndef TORUSPRIMITIVESHAPECONSTRUCTOR_HEADER
2 | #define TORUSPRIMITIVESHAPECONSTRUCTOR_HEADER
3 | #include "PrimitiveShapeConstructor.h"
4 |
5 | #ifndef DLL_LINKAGE
6 | #define DLL_LINKAGE
7 | #endif
8 |
9 | class DLL_LINKAGE TorusPrimitiveShapeConstructor
10 | : public PrimitiveShapeConstructor
11 | {
12 | public:
13 | size_t Identifier() const;
14 | unsigned int RequiredSamples() const;
15 | PrimitiveShape *Construct(const MiscLib::Vector< Vec3f > &points,
16 | const MiscLib::Vector< Vec3f > &normals) const;
17 | PrimitiveShape *Construct(const MiscLib::Vector< Vec3f > &samples) const;
18 | PrimitiveShape *Deserialize(std::istream *i, bool binary = true) const;
19 | size_t SerializedSize() const;
20 | };
21 |
22 | #endif
23 |
--------------------------------------------------------------------------------
/3rd_ransac/solve.cpp:
--------------------------------------------------------------------------------
1 | #ifndef _USE_MATH_DEFINES
2 | #define _USE_MATH_DEFINES
3 | #endif
4 | #include
5 | #include
6 |
7 | using namespace std;
8 |
9 | int dmat_solve ( int n, int rhs_num, double a[] )
10 | //******************************************************************************
11 | //
12 | // Purpose:
13 | //
14 | // DMAT_SOLVE uses Gauss-Jordan elimination to solve an N by N linear system.
15 | //
16 | // Discussion:
17 | //
18 | // The doubly dimensioned array A is treated as a one dimensional vector,
19 | // stored by COLUMNS. Entry A(I,J) is stored as A[I+J*N]
20 | //
21 | // Modified:
22 | //
23 | // 29 August 2003
24 | //
25 | // Author:
26 | //
27 | // John Burkardt
28 | //
29 | // Parameters:
30 | //
31 | // Input, int N, the order of the matrix.
32 | //
33 | // Input, int RHS_NUM, the number of right hand sides. RHS_NUM
34 | // must be at least 0.
35 | //
36 | // Input/output, double A[N*(N+RHS_NUM)], contains in rows and columns 1
37 | // to N the coefficient matrix, and in columns N+1 through
38 | // N+RHS_NUM, the right hand sides. On output, the coefficient matrix
39 | // area has been destroyed, while the right hand sides have
40 | // been overwritten with the corresponding solutions.
41 | //
42 | // Output, int DMAT_SOLVE, singularity flag.
43 | // 0, the matrix was not singular, the solutions were computed;
44 | // J, factorization failed on step J, and the solutions could not
45 | // be computed.
46 | //
47 | {
48 | double apivot;
49 | double factor;
50 | int i;
51 | int ipivot;
52 | int j;
53 | int k;
54 | double temp;
55 |
56 | for ( j = 0; j < n; j++ )
57 | {
58 | //
59 | // Choose a pivot row.
60 | //
61 | ipivot = j;
62 | apivot = a[j+j*n];
63 |
64 | for ( i = j; i < n; i++ )
65 | {
66 | if ( fabs ( apivot ) < fabs ( a[i+j*n] ) )
67 | {
68 | apivot = a[i+j*n];
69 | ipivot = i;
70 | }
71 | }
72 |
73 | if ( apivot == 0.0 )
74 | {
75 | return j;
76 | }
77 | //
78 | // Interchange.
79 | //
80 | for ( i = 0; i < n + rhs_num; i++ )
81 | {
82 | temp = a[ipivot+i*n];
83 | a[ipivot+i*n] = a[j+i*n];
84 | a[j+i*n] = temp;
85 | }
86 | //
87 | // A(J,J) becomes 1.
88 | //
89 | a[j+j*n] = 1.0;
90 | for ( k = j; k < n + rhs_num; k++ )
91 | {
92 | a[j+k*n] = a[j+k*n] / apivot;
93 | }
94 | //
95 | // A(I,J) becomes 0.
96 | //
97 | for ( i = 0; i < n; i++ )
98 | {
99 | if ( i != j )
100 | {
101 | factor = a[i+j*n];
102 | a[i+j*n] = 0.0;
103 | for ( k = j; k < n + rhs_num; k++ )
104 | {
105 | a[i+k*n] = a[i+k*n] - factor * a[j+k*n];
106 | }
107 | }
108 |
109 | }
110 |
111 | }
112 |
113 | return 0;
114 | }
115 | //******************************************************************************
116 |
--------------------------------------------------------------------------------
/3rd_ransac/version.txt:
--------------------------------------------------------------------------------
1 | version: 1.1
2 |
--------------------------------------------------------------------------------
/DemoWithTestData/License.txt:
--------------------------------------------------------------------------------
1 | License
2 |
3 | This work is licensed under a Creative Commons Attribution 4.0 International License.
4 | More information can be found here: https://creativecommons.org/licenses/by/4.0/
5 |
6 | ===========================================================================
7 |
8 | Please cite the following paper if you use the data/code (or part of it):
9 |
10 | "Manhattan-world Urban Reconstruction from Point Clouds". ECCV 2016.
11 | - Minglei Li (minglei_li@126.com),
12 | - Peter Wonka (pwonka@gmail.com),
13 | - Liangliang Nan (liangliang.nan@gmail.com)
14 |
15 | ===========================================================================
16 |
17 | Aug. 31, 2016
--------------------------------------------------------------------------------
/DemoWithTestData/example_1_pointcloud.ply:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LiangliangNan/ManhattanModeler/ef257690a2c3f4d36be430452db5bbb2d1bd54b0/DemoWithTestData/example_1_pointcloud.ply
--------------------------------------------------------------------------------
/DemoWithTestData/example_1_video.wmv:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LiangliangNan/ManhattanModeler/ef257690a2c3f4d36be430452db5bbb2d1bd54b0/DemoWithTestData/example_1_video.wmv
--------------------------------------------------------------------------------
/DemoWithTestData/example_2_pointcloud.ply:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LiangliangNan/ManhattanModeler/ef257690a2c3f4d36be430452db5bbb2d1bd54b0/DemoWithTestData/example_2_pointcloud.ply
--------------------------------------------------------------------------------
/DemoWithTestData/example_2_video.wmv:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LiangliangNan/ManhattanModeler/ef257690a2c3f4d36be430452db5bbb2d1bd54b0/DemoWithTestData/example_2_video.wmv
--------------------------------------------------------------------------------
/License.txt:
--------------------------------------------------------------------------------
1 | License
2 |
3 | This work is licensed under a Creative Commons Attribution 4.0 International License.
4 | More information can be found here: https://creativecommons.org/licenses/by/4.0/
5 |
6 | ===========================================================================
7 |
8 | Please cite the following paper if you use the data/code (or part of it):
9 |
10 | "Manhattan-world Urban Reconstruction from Point Clouds". ECCV 2016.
11 | - Minglei Li (minglei_li@126.com),
12 | - Peter Wonka (pwonka@gmail.com),
13 | - Liangliang Nan (liangliang.nan@gmail.com)
14 |
15 | ===========================================================================
16 |
17 | Aug. 31, 2016
--------------------------------------------------------------------------------
/ManhattanModeler.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 2013
4 | VisualStudioVersion = 12.0.31101.0
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "3rd_graphcut", "3rd_graphcut\3rd_graphcut.vcxproj", "{1D82ADDA-AD2C-4F27-BB96-3CBB111353C0}"
7 | EndProject
8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "3rd_qglviewer", "3rd_qglviewer\3rd_qglviewer.vcxproj", "{944083FE-23C5-3EDE-A305-0C342D1AF872}"
9 | EndProject
10 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "3rd_ransac", "3rd_ransac\3rd_ransac.vcxproj", "{0C634703-9FC6-4744-A944-A00C53CD6042}"
11 | EndProject
12 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ManhattanModeler", "ManhattanModeler\ManhattanModeler.vcxproj", "{D5DCB796-638E-405E-BE60-A779B1743C37}"
13 | EndProject
14 | Global
15 | GlobalSection(SubversionScc) = preSolution
16 | Svn-Managed = True
17 | Manager = AnkhSVN - Subversion Support for Visual Studio
18 | EndGlobalSection
19 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
20 | Debug|x64 = Debug|x64
21 | Release|x64 = Release|x64
22 | EndGlobalSection
23 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
24 | {1D82ADDA-AD2C-4F27-BB96-3CBB111353C0}.Debug|x64.ActiveCfg = Debug|x64
25 | {1D82ADDA-AD2C-4F27-BB96-3CBB111353C0}.Debug|x64.Build.0 = Debug|x64
26 | {1D82ADDA-AD2C-4F27-BB96-3CBB111353C0}.Release|x64.ActiveCfg = Release|x64
27 | {1D82ADDA-AD2C-4F27-BB96-3CBB111353C0}.Release|x64.Build.0 = Release|x64
28 | {944083FE-23C5-3EDE-A305-0C342D1AF872}.Debug|x64.ActiveCfg = Debug|x64
29 | {944083FE-23C5-3EDE-A305-0C342D1AF872}.Debug|x64.Build.0 = Debug|x64
30 | {944083FE-23C5-3EDE-A305-0C342D1AF872}.Release|x64.ActiveCfg = Release|x64
31 | {944083FE-23C5-3EDE-A305-0C342D1AF872}.Release|x64.Build.0 = Release|x64
32 | {0C634703-9FC6-4744-A944-A00C53CD6042}.Debug|x64.ActiveCfg = Debug|x64
33 | {0C634703-9FC6-4744-A944-A00C53CD6042}.Debug|x64.Build.0 = Debug|x64
34 | {0C634703-9FC6-4744-A944-A00C53CD6042}.Release|x64.ActiveCfg = Release|x64
35 | {0C634703-9FC6-4744-A944-A00C53CD6042}.Release|x64.Build.0 = Release|x64
36 | {D5DCB796-638E-405E-BE60-A779B1743C37}.Debug|x64.ActiveCfg = Debug|x64
37 | {D5DCB796-638E-405E-BE60-A779B1743C37}.Debug|x64.Build.0 = Debug|x64
38 | {D5DCB796-638E-405E-BE60-A779B1743C37}.Release|x64.ActiveCfg = Release|x64
39 | {D5DCB796-638E-405E-BE60-A779B1743C37}.Release|x64.Build.0 = Release|x64
40 | EndGlobalSection
41 | GlobalSection(SolutionProperties) = preSolution
42 | HideSolutionNode = FALSE
43 | EndGlobalSection
44 | GlobalSection(ExtensibilityGlobals) = postSolution
45 | QtVersion = 4.8.0
46 | EndGlobalSection
47 | GlobalSection(Qt) = preSolution
48 | Integration = True
49 | EndGlobalSection
50 | GlobalSection(Qt) = preSolution
51 | Integration = True
52 | EndGlobalSection
53 | GlobalSection(Qt) = preSolution
54 | Integration = True
55 | EndGlobalSection
56 | EndGlobal
57 |
--------------------------------------------------------------------------------
/ManhattanModeler/BoundingBox.cpp:
--------------------------------------------------------------------------------
1 |
2 | #include
3 | #include ".\boundingbox.h"
4 |
5 | CBoundingBox::CBoundingBox(void)
6 | {
7 | Reset();
8 | }
9 | CBoundingBox::CBoundingBox(float minx,float miny,float minz,float maxx,float maxy,float maxz)
10 | {
11 | Reset();
12 | m_vMin = CVector3D(minx,miny,minz);
13 | m_vMax = CVector3D(maxx,maxy,maxz);
14 | }
15 |
16 | CBoundingBox::CBoundingBox( const CBoundingBox & bb_ )
17 | {
18 | Reset();
19 | this->m_vMax = bb_.m_vMax;
20 | this->m_vMin = bb_.m_vMin;
21 | }
22 |
23 | CBoundingBox::~CBoundingBox(void)
24 | {
25 | }
26 |
27 | void CBoundingBox::Reset()
28 | {
29 | m_vMin[0] = m_vMin[1] = m_vMin[2] = 1e10;
30 | m_vMax[0] = m_vMax[1] = m_vMax[2] = -1e10;
31 | }
32 |
33 | void CBoundingBox::Push( float m_fVertex[3] )
34 | {
35 | for (int i = 0; i < 3; i++) {
36 | if (m_fVertex[i] < m_vMin[i])
37 | m_vMin[i] = m_fVertex[i];
38 | if (m_fVertex[i] > m_vMax[i])
39 | m_vMax[i] = m_fVertex[i];
40 | }
41 | }
42 |
43 | void CBoundingBox::Push( double m_dbVertex[3] )
44 | {
45 | for (int i = 0; i < 3; i++) {
46 | if (m_dbVertex[i] < m_vMin[i])
47 | m_vMin[i] = m_dbVertex[i];
48 | if (m_dbVertex[i] > m_vMax[i])
49 | m_vMax[i] = m_dbVertex[i];
50 | }
51 | }
52 |
53 | void CBoundingBox::Push( const CVector3D & v )
54 | {
55 | for (int i = 0; i < 3; i++) {
56 | if (v.pVec[i] < m_vMin[i])
57 | m_vMin[i] = v.pVec[i];
58 | if (v.pVec[i] > m_vMax[i])
59 | m_vMax[i] = v.pVec[i];
60 | }
61 | }
62 |
63 | CVector3D CBoundingBox::GetPosition()
64 | {
65 | return CVector3D(
66 | (m_vMin[0] + m_vMax[0]) / 2.0,
67 | (m_vMin[1] + m_vMax[1]) / 2.0,
68 | (m_vMin[2] + m_vMax[2]) / 2.0
69 | );
70 | }
71 |
72 | double CBoundingBox::GetLength()
73 | {
74 | double temp[3] = { m_vMax[0] - m_vMin[0], m_vMax[1] - m_vMin[1], m_vMax[2] - m_vMin[2] };
75 | return __max( temp[2], __max( temp[0], temp[1] ) );
76 | }
77 |
78 | double CBoundingBox::GetLength( int i )
79 | {
80 | return m_vMax[ i ] - m_vMin[ i ];
81 | }
82 |
83 | CVector3D CBoundingBox::GetCorner(int i, int j, int k)
84 | {
85 | CVector3D vPos = GetPosition();
86 | double dbLength = GetLength();
87 | return vPos + CVector3D(
88 | (i - 0.5) * dbLength,
89 | (j - 0.5) * dbLength,
90 | (k - 0.5) * dbLength
91 | );
92 | }
93 |
94 | double CBoundingBox::Diagonal()
95 | {
96 | return (m_vMax-m_vMin).length();
97 | }
98 |
99 | CVector3D CBoundingBox::centerPnt()
100 | {
101 | return (m_vMax+m_vMin)/2;
102 | }
103 |
--------------------------------------------------------------------------------
/ManhattanModeler/BoundingBox.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "CVector3D.h"
4 |
5 | class CBoundingBox
6 | {
7 | public:
8 | CBoundingBox(void);
9 | CBoundingBox(const CBoundingBox & bb_);
10 | CBoundingBox(float minx,float miny,float minz,float maxx,float maxy,float maxz);
11 | ~CBoundingBox(void);
12 |
13 | public:
14 | CVector3D m_vMin;
15 | CVector3D m_vMax;
16 |
17 | void Reset();
18 | void Push( float m_fVertex[3] );
19 | void Push( double m_dbVertex[3] );
20 | void Push( const CVector3D & v );
21 | CVector3D GetPosition();
22 | double GetLength();
23 | double GetLength( int i );
24 | CVector3D GetCorner(int i, int j, int k);
25 |
26 | double Diagonal();
27 | CVector3D centerPnt();
28 |
29 | void PrintInfo() {
30 | fprintf_s( stderr, "Bounding Box:\n\tFrom : ( %.2f, %.2f, %.2f )\n\tTo : ( %.2f, %.2f, %.2f )\n", m_vMin[0], m_vMin[1], m_vMin[2], m_vMax[0], m_vMax[1], m_vMax[2] );
31 | }
32 | };
33 |
--------------------------------------------------------------------------------
/ManhattanModeler/CCube.h:
--------------------------------------------------------------------------------
1 |
2 | //===========================================================================
3 | // This code implements the FittingBox method described in:
4 | //
5 | // Minglei Li, Peter Wonka, Liangliang Nan
6 | // "Manhattan-world Urban Reconstruction from Point Clouds"
7 | // ECCV'2016.
8 | //
9 | // E-Mail: minglei_li@126.com (Minglei Li)
10 | // pwonka@gmail.com (Peter Wonka)
11 | // liangliang.nan@gmail.com (Liangliang Nan)
12 | //
13 | // All rights reserved
14 | //===========================================================================
15 |
16 |
17 | #pragma once
18 |
19 | #include "math_types.h"
20 | #include "CPointCloud.h"
21 | #include "CPolyHedron.h"
22 | #include "draw_model.h"
23 |
24 | #include
25 |
26 | class CVertexGroup;
27 | class CPointCloud;
28 | class CCube
29 | {
30 | public:
31 | CCube (CPolyHedron* cp);
32 | ~CCube(void);
33 |
34 | public:
35 | CPointCloud * m_pc;
36 |
37 | CPolyHedron * m_CPolyHedron;
38 | typedef std::vector abox8Pnts;
39 | abox8Pnts m_v8Pnts; // 8 corners of a cube.
40 | std::vector m_v6Plns; // 6 planes of a cube.
41 | std::vector> m_6fc4corner; // 6 x 4 corner
42 |
43 | std::vector> m_v6facetVtxes; // store the points which located on 6 facets of each box.
44 |
45 |
46 | int m_numPntOnCube; // the number of points located on the cube. = num(m_v6facetVtxes)
47 | std::vector m_6CoverRate;
48 | int m_validGridNum;
49 | double m_score;
50 |
51 | int m_id; // when building a cube, give it an integer id.
52 | std::vector m_6neighborCubeId; // record the ids of neighbor cubes of this cube.
53 |
54 |
55 | public:
56 | void dist_pnts_on6facet(); // distribute points to cube square facets.
57 | void cal_6coverRate();
58 | void draw_facetPnts();
59 |
60 | private:
61 | void dist_6FacetCorner(); // distribute 8 corners to 6 facets.
62 |
63 | bool pntInFacet(std::vector & facet4corner, CVector3D & pnt);
64 | };
65 |
66 |
--------------------------------------------------------------------------------
/ManhattanModeler/CDlgAddPlane.cpp:
--------------------------------------------------------------------------------
1 |
2 | //===========================================================================
3 | // This code implements the FittingBox method described in:
4 | //
5 | // Minglei Li, Peter Wonka, Liangliang Nan
6 | // "Manhattan-world Urban Reconstruction from Point Clouds"
7 | // ECCV'2016.
8 | //
9 | // E-Mail: minglei_li@126.com (Minglei Li)
10 | // pwonka@gmail.com (Peter Wonka)
11 | // liangliang.nan@gmail.com (Liangliang Nan)
12 | //
13 | // All rights reserved
14 | //===========================================================================
15 |
16 |
17 |
18 | #include "CDlgAddPlane.h"
19 |
20 |
21 | CDlgAddPlane::CDlgAddPlane(QWidget *parent)
22 | {
23 | setupUi(this);
24 |
25 | parentWindow = (MainWindow*)parent;
26 | connect(pushButton, SIGNAL(clicked()), this, SLOT(accept()));
27 | }
28 |
29 |
30 | CDlgAddPlane::~CDlgAddPlane(void)
31 | {
32 | }
33 |
34 | void CDlgAddPlane::accept()
35 | {
36 | mx= this->lineEdit->text().toDouble();
37 | my= this->lineEdit_2->text().toDouble();
38 | mz= this->lineEdit_3->text().toDouble();
39 | nx= this->lineEdit_4->text().toDouble();
40 | ny= this->lineEdit_5->text().toDouble();
41 | nz= this->lineEdit_6->text().toDouble();
42 |
43 | this->parentWindow->runAddPln(mx, my, mz, nx, ny, nz);
44 |
45 | this->close();
46 | }
47 |
--------------------------------------------------------------------------------
/ManhattanModeler/CDlgAddPlane.h:
--------------------------------------------------------------------------------
1 |
2 | //===========================================================================
3 | // This code implements the FittingBox method described in:
4 | //
5 | // Minglei Li, Peter Wonka, Liangliang Nan
6 | // "Manhattan-world Urban Reconstruction from Point Clouds"
7 | // ECCV'2016.
8 | //
9 | // E-Mail: minglei_li@126.com (Minglei Li)
10 | // pwonka@gmail.com (Peter Wonka)
11 | // liangliang.nan@gmail.com (Liangliang Nan)
12 | //
13 | // All rights reserved
14 | //===========================================================================
15 |
16 |
17 |
18 | #pragma once
19 |
20 |
21 | #include
22 | #include "ui_dlgAddPln.h"
23 | #include "main_window.h"
24 |
25 | class CDlgAddPlane: public QDialog, public Ui::dlgAddPlane
26 | {
27 | public:
28 |
29 | Q_OBJECT
30 | public:
31 | CDlgAddPlane(QWidget *parent);
32 | ~CDlgAddPlane(void);
33 |
34 | private slots:
35 | void accept();
36 | private:
37 | MainWindow *parentWindow;
38 |
39 | double mx,my,mz;
40 | double nx,ny,nz;
41 | };
42 |
43 |
--------------------------------------------------------------------------------
/ManhattanModeler/CFittingBox.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 |
4 | #include "CVertexGroup.h"
5 |
6 | struct _pCoord{
7 | int xId;
8 | int yId;
9 | int zId;
10 | _pCoord(int px,int py, int pz)
11 | {xId = px; yId = py; zId = pz;}
12 | };
13 |
14 | class CPointCloud;
15 | class CFittingBox
16 | {
17 | public:
18 | CFittingBox(CPointCloud* pc);
19 | ~CFittingBox(void);
20 |
21 | int num_xPln, num_yPln, num_zPln;
22 |
23 | public:
24 | std::vector> vecBox8Pnts; // the result of fitting box procedure.
25 | std::vector> vecBox6Plns; // the result of fitting box procedure.
26 | std::vector<_pCoord> vecBoxCoord; // the coordinate of a box, i.e. xpln, ypln, zpln started from 0.
27 |
28 | public:
29 | bool fitBox_0(std::vector & vPtrPG); // without axis alignment.
30 | bool fitBox_1(std::vector & vPtrPG); // sort along axis, and fit all boxes.
31 | bool fitBox_2(std::vector & vPtrPG); // sort along axis, and only fit basic boxes.
32 |
33 | void mergeSimilarPlns(std::vector & vPtrPG);
34 | static void sortPlns(std::vector & vPG, std::vector & XvPln, std::vector & YvPln, std::vector & ZvPln);
35 |
36 | private:
37 | bool checkPlnNoCross(std::vector & boxp);
38 | void cal_vecBox8Pnts(std::vector> & tempVecBox6Plns, // input
39 | std::vector> & p_vecBox8Pnts, // result
40 | std::vector> & p_vecBox6Plns); // result
41 | private:
42 | CPointCloud *m_pc;
43 | };
44 |
--------------------------------------------------------------------------------
/ManhattanModeler/CMeshObj.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 |
5 | #include "CVector3D.h"
6 | #include "math_types.h"
7 |
8 | enum elemType
9 | {
10 | T_WALL=0,
11 | T_ROOF=1,
12 | };
13 |
14 | class CMeshObj
15 | {
16 | public:
17 | CMeshObj(void);
18 | ~CMeshObj(void);
19 |
20 | public:
21 | struct MeshVertex
22 | {
23 | CVector3D v;
24 | MeshVertex( const CVector3D & vv ) : v( vv ) { }
25 | MeshVertex() {}
26 | };
27 | struct MeshTriangle
28 | {
29 | int i[ 3 ];
30 | MeshTriangle( int i0, int i1, int i2 )
31 | {
32 | i[ 0 ] = i0;
33 | i[ 1 ] = i1;
34 | i[ 2 ] = i2;
35 | }
36 | MeshTriangle() {}
37 | };
38 |
39 | public:
40 | std::vector< MeshVertex > m_vecVertex;
41 |
42 | std::vector< MeshTriangle > m_vecTriangle; // Here, the index starts from 0. But attention. In obj formate file, vertex index starts from 1.
43 | std::vector> m_vecTriRoofIdx; // distinguish each roof patch.
44 |
45 | std::vector m_vecTriNrl;
46 | std::vector m_vecElemType;
47 | std::vector m_vecMeshMidPnt;
48 | std::vector m_contour;
49 |
50 | cgBbox3f bbox();
51 |
52 | public:
53 | void pushVecVertice(std::vector & pnts);
54 | void pushOneVertex(CVector3D & pnt);
55 | void PushOneFace(int i, int j, int k );
56 |
57 | static CMeshObj * loadFromObj(const std::string& file_name);
58 |
59 | void SaveToObj( const char * filename );
60 | void drawMesh(); // draw fit box model & Poisson model & model loaded from obj file
61 | void drawMeshObj(bool showNrl = false, bool rdmColor = false);// draw MRF polyhedron model
62 |
63 | void static combineTwoMeshObj( CMeshObj *&meshDst, CMeshObj *meshSrc );
64 |
65 |
66 | private:
67 | bool IsDegenrateFace( CMeshObj::MeshTriangle & f );
68 | };
69 |
--------------------------------------------------------------------------------
/ManhattanModeler/CScanVertex.cpp:
--------------------------------------------------------------------------------
1 | #include "CScanVertex.h"
2 |
3 | CScanVertex::CScanVertex(void): color_error(NULL),color_height(NULL),selected_(false)
4 | {
5 | _index = -1;
6 | }
7 |
8 | CScanVertex::~CScanVertex(void)
9 | {
10 | if (this->color_error)
11 | {
12 | delete this->color_error;
13 | this->color_error = NULL;
14 | }
15 | if (this->color_height)
16 | {
17 | delete this->color_height;
18 | this->color_height = NULL;
19 | }
20 | }
21 |
22 | CScanVertex::CScanVertex( CVector3D & pnt,CVector3D & nrl, Colorf & clr ): color_error(NULL),color_height(NULL),selected_(false)
23 | {
24 | point_ = pnt;
25 | normal_ = nrl;
26 | color_ = clr;
27 | }
28 | CScanVertex::CScanVertex(CScanVertex & vtx): color_error(NULL),color_height(NULL),selected_(false)
29 | {
30 | point_ = vtx.point_;
31 | normal_= vtx.normal_;
32 | color_ = vtx.color_;
33 | selected_ = vtx.selected_;
34 | }
35 |
36 |
37 | void CScanVertex::setColor( double r,double g,double b,double a /*=1*/ )
38 | {
39 | color_ = Colorf(r,g,b,a);
40 | }
41 |
42 |
--------------------------------------------------------------------------------
/ManhattanModeler/CScanVertex.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "CVector3D.h"
4 | #include "color.h"
5 |
6 | #include "math_types.h"
7 |
8 | class CScanVertex
9 | {
10 | public:
11 | CScanVertex(void);
12 | CScanVertex(CVector3D & pnt,CVector3D & nrl, Colorf & clr);
13 | CScanVertex(CScanVertex & vtx);
14 | ~CScanVertex(void);
15 | public:
16 | CVector3D point_ ;
17 | CVector3D normal_;
18 | Colorf color_ ;
19 | Colorf * color_error;
20 | Colorf * color_height;
21 |
22 | double error; // indicate the error from the point to the reconstructed surface, querying by AABB tree.
23 | bool selected_ ;
24 | int _index; // this is used while building minimum spanning tree.
25 | public:
26 | void setColor(double r,double g,double b,double a =1) ;
27 |
28 | };
29 |
--------------------------------------------------------------------------------
/ManhattanModeler/CVector3D.cpp:
--------------------------------------------------------------------------------
1 |
2 | #include ".\CVector3D.h"
3 |
4 | CVector3D& CVector3D::operator=(const CVector3D& v)
5 | {
6 | pVec[0] = v.pVec[0]; pVec[1] = v.pVec[1]; pVec[2] = v.pVec[2];
7 | return (*this);
8 | }
9 | bool CVector3D::operator==(const CVector3D& v)
10 | {
11 | if (pVec[0] == v.pVec[0] && pVec[1] == v.pVec[1] && pVec[2] == v.pVec[2])
12 | {
13 | return true;
14 | }
15 | else
16 | {
17 | return false;
18 | }
19 | }
20 | CVector3D& CVector3D::operator+=(const CVector3D& v)
21 | {
22 | pVec[0] += v.pVec[0]; pVec[1] += v.pVec[1]; pVec[2] += v.pVec[2];
23 | return (*this);
24 | }
25 | CVector3D& CVector3D::operator-=(const CVector3D& v)
26 | {
27 | pVec[0] -= v.pVec[0]; pVec[1] -= v.pVec[1]; pVec[2] -= v.pVec[2];
28 | return (*this);
29 | }
30 | CVector3D& CVector3D::operator*=(double u)
31 | {
32 | pVec[0] *= u; pVec[1] *= u; pVec[2] *= u;
33 | return (*this);
34 | }
35 | CVector3D& CVector3D::operator/=(double u)
36 | {
37 | if (abs(u) > 1e-10)
38 | {pVec[0] /= u; pVec[1] /= u; pVec[2] /= u;}
39 | return(*this);
40 | }
41 | CVector3D& CVector3D::operator^=(const CVector3D& v)
42 | {
43 | double xx = pVec[1]*v.pVec[2] - pVec[2]*v.pVec[1];
44 | double yy = pVec[2]*v.pVec[0] - pVec[0]*v.pVec[2];
45 | double zz = pVec[0]*v.pVec[1] - pVec[1]*v.pVec[0];
46 | pVec[0] = xx; pVec[1] = yy; pVec[2] = zz;
47 | return (*this);
48 | }
49 |
50 |
51 | CVector3D operator+(const CVector3D& lv, const CVector3D& rv)
52 | {
53 | CVector3D rel = lv;
54 | rel += rv;
55 | return rel;
56 | }
57 |
58 |
59 | CVector3D operator-(const CVector3D& lv, const CVector3D& rv)
60 | {
61 | CVector3D rel = lv;
62 | rel -= rv;
63 | return rel;
64 | }
65 |
66 | CVector3D operator*(const double u, const CVector3D& rv)
67 | {
68 | CVector3D rel = rv;
69 | rel *= u;
70 | return rel;
71 | }
72 |
73 | CVector3D operator*(const CVector3D& lv, const double u)
74 | {
75 | CVector3D rel = lv;
76 | rel *= u;
77 | return rel;
78 | }
79 |
80 | CVector3D operator/(const CVector3D& lv, const double u)
81 | {
82 | CVector3D rel = lv;
83 | rel /= u;
84 | return rel;
85 | }
86 |
87 | double operator*(const CVector3D& lv, const CVector3D& rv)
88 | {
89 | return lv.pVec[0]*rv.pVec[0] + lv.pVec[1]*rv.pVec[1] + lv.pVec[2]*rv.pVec[2];
90 | }
91 |
92 | CVector3D operator^(const CVector3D& lv, const CVector3D& rv)
93 | {
94 | CVector3D rel = lv;
95 | rel ^= rv;
96 | return rel;
97 | }
98 |
99 | const CVector3D CVector3D::INFINITE_VECTOR3D = CVector3D( 1e300, 1e300, 1e300 );
--------------------------------------------------------------------------------
/ManhattanModeler/CVector3D.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 | #include
5 | #include
6 |
7 | #define DOUBLE_TOLERANCE 1e-10
8 |
9 | class CVector3D
10 | {
11 | public:
12 | CVector3D(void) { pVec[0] = pVec[1] = pVec[2] = 0.0; }
13 | CVector3D(double x, double y, double z) { pVec[0] = x; pVec[1] = y; pVec[2] = z; }
14 | CVector3D(double xx[3]) { pVec[0] = xx[0]; pVec[1] = xx[1], pVec[2] = xx[2]; }
15 | CVector3D(const CVector3D & v) { pVec[0] = v.pVec[0]; pVec[1] = v.pVec[1]; pVec[2] = v.pVec[2]; }
16 | ~CVector3D(void) {}
17 |
18 | public :
19 | double pVec[3];
20 |
21 | // operator
22 | double x_(){return pVec[0];}
23 | double y_(){return pVec[1];}
24 | double z_(){return pVec[2];}
25 |
26 | double length() { return sqrt(pVec[0] * pVec[0] + pVec[1] * pVec[1] + pVec[2] * pVec[2]); }
27 | double length2() { return pVec[0] * pVec[0] + pVec[1] * pVec[1] + pVec[2] * pVec[2]; }
28 | double normalize() { double len = length(); if (std::abs(len) > DOUBLE_TOLERANCE) {pVec[0]/=len;pVec[1]/=len;pVec[2]/=len;} return len; }
29 | bool IsInfinite() { return ( pVec[0] == 1e300 && pVec[1] == 1e300 && pVec[2] == 1e300 ); }
30 | CVector3D XY() { return CVector3D( pVec[0], pVec[1], 0.0 ); }
31 |
32 | double & operator[]( const int i ) { return pVec[i]; }
33 |
34 | CVector3D& operator=(const CVector3D& v);
35 | CVector3D& operator+=(const CVector3D& v);
36 | CVector3D& operator-=(const CVector3D& v);
37 | CVector3D& operator*=(double u);
38 | CVector3D& operator/=(double u);
39 | CVector3D& operator^=(const CVector3D& v);
40 | bool operator==(const CVector3D& v);
41 |
42 | friend CVector3D operator+(const CVector3D& lv, const CVector3D& rv);
43 | friend CVector3D operator-(const CVector3D& lv, const CVector3D& rv);
44 | friend CVector3D operator*(const double u, const CVector3D& rv);
45 | friend CVector3D operator*(const CVector3D& lv, const double u);
46 | friend CVector3D operator/(const CVector3D& lv, const double u);
47 | friend double operator*(const CVector3D& lv, const CVector3D& rv);
48 | friend CVector3D operator^(const CVector3D& lv, const CVector3D& rv);
49 |
50 | public:
51 | static const CVector3D INFINITE_VECTOR3D;
52 | };
53 |
--------------------------------------------------------------------------------
/ManhattanModeler/CVertexGroup.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 | #include "math_types.h"
5 | #include "CScanVertex.h"
6 | #include "BoundingBox.h"
7 |
8 | class CVertexGroup: public std::vector
9 | {
10 | public:
11 | CVertexGroup();
12 | CVertexGroup(std::vector * vVetexs);
13 | ~CVertexGroup();
14 | public:
15 | CVector3D m_midPnt; // planar center point
16 | cgPlane3f m_cgPlane; // plane
17 | Colorf m_color;
18 | bool m_toshow;
19 | CBoundingBox m_bbox;
20 |
21 | std::vector m_pnts; /// this vector storages the original points.
22 |
23 | public:
24 | void resetBBox();
25 | void drawGroup(unsigned int fast =1);
26 |
27 | void mergeGroup(CVertexGroup * anotherGroup);
28 | void mergeGroup(std::vector * anotherGroup);
29 | void updateMidPnt();
30 | void clearProjection();
31 |
32 | // to fit the plane from the vector "m_pnts", e.g. refresh the plane model parameters.
33 | int refitPln_least_squares();
34 |
35 | // if the plane model has been modified, all projection vertices should be calculated again.
36 | void refreshProjectionVtx();
37 |
38 | // if a vertex is close to a plane, add it to the vector "m_pnts" and add its projection to this vertexGroup.
39 | // errorThreshold is the maximum distance from the point to the plane.
40 | bool check_add( CScanVertex * vtx, double suqareDistThresh, double nrlThreshold);
41 | };
42 |
--------------------------------------------------------------------------------
/ManhattanModeler/CoordTransf.h:
--------------------------------------------------------------------------------
1 |
2 | //===========================================================================
3 | // This code implements the FittingBox method described in:
4 | //
5 | // Minglei Li, Peter Wonka, Liangliang Nan
6 | // "Manhattan-world Urban Reconstruction from Point Clouds"
7 | // ECCV'2016.
8 | //
9 | // E-Mail: minglei_li@126.com (Minglei Li)
10 | // pwonka@gmail.com (Peter Wonka)
11 | // liangliang.nan@gmail.com (Liangliang Nan)
12 | //
13 | // All rights reserved
14 | //===========================================================================
15 |
16 |
17 | #pragma once
18 |
19 | //
20 | #include "math_global.h"
21 |
22 |
23 | class CPointCloud;
24 | class CVector3D;
25 | class CVertexGroup;
26 | class CCoordTransf
27 | {
28 | public:
29 | CCoordTransf(void);
30 | ~CCoordTransf(void);
31 | private:
32 | void rotateSinglePnt( CVector3D & m_vecPoint, double cos_theta, double sin_theta, CoordTranferMode mode);
33 | void rotateSinglePnt( CVector3D & m_vecPoint, double theta,CoordTranferMode mode);
34 | void transBackSingPnt( CVector3D & m_vecPoint, double cos_theta, double sin_theta, CoordTranferMode mode);
35 | void transBackSingPnt( CVector3D & m_vecPoint, double theta, CoordTranferMode mode);
36 | public:
37 | void translatePntCloud(CPointCloud *pc, const double tx, const double ty, const double tz, const double pScale = 1.0);// x0 + tx; y0 + ty; z0 +tz.
38 | void rotatePntCloud( CPointCloud & pc, double radian_theta, CoordTranferMode mode );
39 | void transBackPntCloud( CPointCloud & pc, double radian_theta, CoordTranferMode mode );
40 | void transGroupPC( CVertexGroup & pcGroup, double radian_theta, CoordTranferMode mode );
41 | void transBackGroupPC( CVertexGroup & pcGroup, double radian_theta, CoordTranferMode mode );
42 | };
43 |
--------------------------------------------------------------------------------
/ManhattanModeler/DlgFittingBox.cpp:
--------------------------------------------------------------------------------
1 | #include "DlgFittingBox.h"
2 | #include "Parameters.h"
3 |
4 | DlgFittingBox::DlgFittingBox(QWidget *parent)
5 | {
6 | setupUi(this);
7 |
8 | parentWindow = (MainWindow*)parent;
9 | connect(pushButton, SIGNAL(clicked()), this, SLOT(accept()));
10 | }
11 |
12 | DlgFittingBox::~DlgFittingBox(void)
13 | {
14 | }
15 |
16 | void DlgFittingBox::accept()
17 | {
18 | lml_param::threshold_Paral= this->line_parall->text().toFloat();
19 | lml_param::threshold_vertl= this->line_vertical->text().toFloat();
20 | lml_param::threshold_merge= this->line_merge->text().toFloat();
21 |
22 | this->parentWindow->runFittingBox();
23 |
24 | this->close();
25 | }
26 |
--------------------------------------------------------------------------------
/ManhattanModeler/DlgFittingBox.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 | #include "ui_dlgFittingBox.h"
5 | #include "main_window.h"
6 |
7 | class DlgFittingBox: public QDialog, public Ui::frmFittingBox
8 | {
9 | public:
10 |
11 | Q_OBJECT
12 | public:
13 | DlgFittingBox(QWidget *parent);
14 | ~DlgFittingBox(void);
15 |
16 | private slots:
17 | void accept();
18 | private:
19 | MainWindow *parentWindow;
20 | };
21 |
--------------------------------------------------------------------------------
/ManhattanModeler/DlgransacParam.cpp:
--------------------------------------------------------------------------------
1 | #include "DlgransacParam.h"
2 | #include "Parameters.h"
3 |
4 | CDlg_ransacParam::CDlg_ransacParam(QWidget *parent)
5 | {
6 | setupUi(this);
7 |
8 | parentWindow = (MainWindow*)parent;
9 | connect(btnRANSAC, SIGNAL(clicked()), this, SLOT(accept()));
10 |
11 | //this->setResult(QDialog::Rejected);
12 | }
13 |
14 | CDlg_ransacParam::~CDlg_ransacParam(void)
15 | {
16 | }
17 |
18 | void CDlg_ransacParam::accept()
19 | {
20 | lml_param::ransac_bitmap_resolution = this->line_ransac_bitmap->text().toDouble();
21 | lml_param::ransac_normalThresh = this->line_ransac_nrlThresh->text().toDouble();
22 | lml_param::ransac_minimum_support = this->line_ransac_minimum->text().toDouble();
23 | lml_param::ransac_probability = this->line_ransac_probability->text().toDouble();
24 | lml_param::ransac_distance_threshold= this->line_ransac_distance->text().toDouble();
25 | //this->setResult(QDialog::Accepted);
26 | this->done(QDialog::Accepted);
27 | }
28 |
--------------------------------------------------------------------------------
/ManhattanModeler/DlgransacParam.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 | #include "ui_ransacParam.h"
5 | #include "main_window.h"
6 |
7 | class CDlg_ransacParam: public QDialog, public Ui::DlgRANSAC
8 | {
9 | public:
10 |
11 | Q_OBJECT
12 |
13 | public:
14 | CDlg_ransacParam(QWidget *parent=0);
15 | ~CDlg_ransacParam(void);
16 |
17 | private slots:
18 | void accept();
19 | private:
20 | MainWindow *parentWindow;
21 | };
22 |
--------------------------------------------------------------------------------
/ManhattanModeler/ManhattanModeler.rc:
--------------------------------------------------------------------------------
1 | // Microsoft Visual C++ generated resource script.
2 | //
3 |
4 |
5 | #define IDI_ICON_MAIN 101
6 |
7 | IDI_ICON_MAIN ICON DISCARDABLE "Resources/icon.ico"
8 |
9 |
10 |
11 | /////////////////////////////////////////////////////////////////////////////
12 |
--------------------------------------------------------------------------------
/ManhattanModeler/Parameters.cpp:
--------------------------------------------------------------------------------
1 |
2 | //===========================================================================
3 | // This code implements the FittingBox method described in:
4 | //
5 | // Minglei Li, Peter Wonka, Liangliang Nan
6 | // "Manhattan-world Urban Reconstruction from Point Clouds"
7 | // ECCV'2016.
8 | //
9 | // E-Mail: minglei_li@126.com (Minglei Li)
10 | // pwonka@gmail.com (Peter Wonka)
11 | // liangliang.nan@gmail.com (Liangliang Nan)
12 | //
13 | // All rights reserved
14 | //===========================================================================
15 |
16 |
17 | #include "Parameters.h"
18 | #include
19 | namespace lml_param
20 | {
21 |
22 | int lml_param::ransac_minimum_support = 100;
23 | double lml_param::ransac_distance_threshold = 0.1;
24 | double lml_param::ransac_bitmap_resolution = 0.4;
25 | double lml_param::ransac_normalThresh = 0.2;
26 |
27 | int lml_param::ransac_minimum_support2 = 300;
28 | double lml_param::douransac_distance_threshold2 = 0.1;
29 | double lml_param::ransac_bitmap_resolution2 = 0.4;
30 | double lml_param::ransac_probability = 0.001;
31 |
32 | double lml_param::threshold_Paral =0.965; // sin(75?
33 | double lml_param::threshold_vertl =0.258; // >75 degree. cos(75?
34 | double lml_param::threshold_merge = 0.1;
35 |
36 | double lml_param::optim_lambda = 0.1;
37 |
38 | int lml_param::sample_pnt_per_m2 = 0;
39 | double lml_param::sample_add_noise = 0.1;
40 | int lml_param::showPointSize = 2;
41 |
42 | double lml_param::gridWidth= 0.35;
43 | double lml_param::GroundZ=-35.5;
44 | double lml_param::DeltaZ = 1.2;
45 |
46 | bool lml_param::hideCamera = false;
47 | bool lml_param::hideGrid = false;
48 | bool lml_param::hideRegionRANSAC = false;
49 | bool lml_param::hideBounding = true;
50 | bool lml_param::hidePolyhedron = false;
51 | bool lml_param::hidePoisson = false;
52 | bool lml_param::showNormal = false;
53 | bool lml_param::showPHWirframe = false;
54 | bool lml_param::rdmColor = true;
55 | bool lml_param::smoothShading = true;
56 |
57 | bool lml_param::shift1= false;
58 | bool lml_param::shift2= false;
59 |
60 | double lml_param::neighborRadius = 0.1;
61 |
62 | int lml_param::SLIC_num = 200;
63 | int lml_param::SLIC_Compactness = 10;
64 |
65 | double lml_param::clrBarMax = 1.0;
66 | double lml_param::clrBarMin = 0;
67 |
68 | double lml_param::regionMRF_dataT1=4;
69 | double lml_param::regionMRF_dataT2=2;
70 | double lml_param::regionMRF_dataT3=7;
71 | float lml_param::regionMRF_smoothT1 = 1.5;
72 |
73 | double lml_param::roofMRF_smoothT1=8;
74 |
75 | double lml_param::Poisson_depth = 7;
76 | double lml_param::Poisson_solverDivide = 8;
77 | double lml_param::Poisson_IsoDivide = 8;
78 | double lml_param::Poisson_MinDepth = 5;
79 | double lml_param::Poisson_scale = 1.1;
80 | double lml_param::Poisson_accuracy = 0.001;
81 | double lml_param::Poisson_pointweight = 4;
82 |
83 | double lml_param::contourTracingParam = 1;
84 |
85 | // control openGL view
86 | bool lml_param::lighting = true;
87 | bool lml_param::isTransparent = true;
88 | bool lml_param::is_drawCornerAxis = true;
89 |
90 | double lml_param::cameraScale = 0.1;
91 | double lml_param::NrlLength = 0.2;
92 | // control openGL view
93 | }
--------------------------------------------------------------------------------
/ManhattanModeler/Parameters.h:
--------------------------------------------------------------------------------
1 |
2 | //===========================================================================
3 | // This code implements the FittingBox method described in:
4 | //
5 | // Minglei Li, Peter Wonka, Liangliang Nan
6 | // "Manhattan-world Urban Reconstruction from Point Clouds"
7 | // ECCV'2016.
8 | //
9 | // E-Mail: minglei_li@126.com (Minglei Li)
10 | // pwonka@gmail.com (Peter Wonka)
11 | // liangliang.nan@gmail.com (Liangliang Nan)
12 | //
13 | // All rights reserved
14 | //===========================================================================
15 |
16 |
17 |
18 |
19 | #ifndef PARAM_H_
20 | #define PARAM_H_
21 |
22 | namespace lml_param
23 | {
24 | // RANSAC
25 | extern int ransac_minimum_support;
26 | extern double ransac_distance_threshold;
27 | extern double ransac_bitmap_resolution;
28 | extern double ransac_normalThresh;
29 | extern int ransac_minimum_support2;
30 | extern double douransac_distance_threshold2;
31 | extern double ransac_bitmap_resolution2;
32 | extern double ransac_probability;
33 |
34 | //fit box
35 | extern double threshold_Paral;
36 | extern double threshold_vertl;
37 | extern double threshold_merge;
38 |
39 | extern double optim_lambda; // used for optimization
40 |
41 | // point cloud
42 | extern int sample_pnt_per_m2;
43 | extern double sample_add_noise;// add noise to the sampling point. this parameter indicates the "mean error"
44 | extern int showPointSize;
45 |
46 | extern double gridWidth;
47 | extern double GroundZ;
48 | extern double DeltaZ;
49 |
50 | extern bool hideCamera;
51 | extern bool hideGrid;
52 | extern bool hideRegionRANSAC;
53 | extern bool hideBounding;
54 | extern bool hidePolyhedron;
55 | extern bool showNormal;
56 | extern bool showPHWirframe;
57 | extern bool rdmColor;
58 | extern bool hidePoisson;
59 |
60 | extern bool shift1; // used flexible for some shift states.
61 | extern bool shift2; // used flexible for some shift states.
62 |
63 | //
64 | extern double neighborRadius;
65 |
66 | // Poisson reconstruction & Octree
67 | extern double Poisson_depth;
68 | extern double Poisson_solverDivide;
69 | extern double Poisson_IsoDivide;
70 | extern double Poisson_MinDepth;
71 | extern double Poisson_scale;
72 | extern double Poisson_accuracy;
73 | extern double Poisson_pointweight;
74 |
75 | //
76 |
77 | // parameters used in super-pixel segmentation.
78 | extern int SLIC_num;//Desired number of super-pixels.
79 | extern int SLIC_Compactness;//Compactness factor. use a value ranging from 10 to 40 depending on your needs. Default is 10
80 |
81 | extern double clrBarMax;
82 | extern double clrBarMin;
83 |
84 | extern double regionMRF_dataT1;
85 | extern double regionMRF_dataT2;
86 | extern double regionMRF_dataT3 ;
87 | extern float regionMRF_smoothT1;
88 |
89 | extern double roofMRF_smoothT1;
90 | extern double roofMRF_smoothT2;
91 |
92 | extern double contourTracingParam;
93 |
94 | // control openGL view
95 | extern bool lighting;
96 | extern bool smoothShading;
97 | extern bool isTransparent;
98 | extern bool is_drawCornerAxis;
99 |
100 | extern double cameraScale;
101 | extern double NrlLength;
102 | // control openGL view
103 | }
104 | #endif
--------------------------------------------------------------------------------
/ManhattanModeler/PlyLoad.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 | #include
4 | #include "rply.h"
5 |
6 | class CPointCloud;
7 | class CVector3D;
8 | class CScanVertex;
9 |
10 | class CPlyLoad
11 | {
12 | public:
13 | CPlyLoad(void);
14 | ~CPlyLoad(void);
15 | void loadPly(const char* filename,CPointCloud * pcPtr);
16 | private:
17 | static int color_cb(p_ply_argument argument);
18 | static int vertex_cb(p_ply_argument argument);
19 | static int normal_cb(p_ply_argument argument);
20 | static int face_cb(p_ply_argument argument);
21 | int get_color_data(p_ply_argument argument);
22 | int get_vertex_data(p_ply_argument argument);
23 | int get_normal_data(p_ply_argument argument);
24 | int get_face_data(p_ply_argument argument);
25 | void check_for_Elements(p_ply ply);
26 | static CPlyLoad* plyload(p_ply_argument argument);
27 |
28 | std::vector vVextex_;
29 | double xyz_[3] ;
30 | double normal_[3];
31 | double rgb_[3] ;
32 | static int *idx3;
33 | std::vector> faceIdx;
34 | std::vector idxx;
35 | bool hasFaces;
36 |
37 | };
--------------------------------------------------------------------------------
/ManhattanModeler/ProgressBar.cpp:
--------------------------------------------------------------------------------
1 | #include "ProgressBar.h"
2 |
3 | #include
4 |
5 |
6 | Progress* Progress::instance_ = NULL ;
7 |
8 | Progress::Progress() :
9 | client_(NULL),
10 | level_(0),
11 | canceled_(false)
12 | {
13 | }
14 |
15 | Progress::~Progress()
16 | {
17 | }
18 |
19 | void Progress::push()
20 | {
21 | level_++ ;
22 | if(level_ == 1)
23 | {
24 | clear_canceled() ;
25 | }
26 | }
27 |
28 | void Progress::pop()
29 | {
30 | assert(level_ > 0) ;
31 | level_-- ;
32 | }
33 |
34 | void Progress::notify(int new_val)
35 | {
36 | if(client_ != NULL && level_ < 3)
37 | {
38 | client_->notify_progress(new_val) ;
39 | }
40 | }
41 |
42 | Progress* Progress::instance()
43 | {
44 | if(instance_ == NULL)
45 | {
46 | instance_ = new Progress ;
47 | }
48 | return instance_ ;
49 | }
50 |
51 |
52 | //_________________________________________________________
53 |
54 |
55 | ProgressClient::~ProgressClient() {
56 | if (Progress::instance())
57 | delete Progress::instance();
58 | }
59 |
60 | //_________________________________________________________
61 |
62 |
63 | ProgressLogger::ProgressLogger( int max_val /*= 100*/, bool quiet /*= false*/ ): max_val_(max_val), quiet_(quiet)
64 | {
65 | cur_val_ = 0 ;
66 | cur_percent_ = 0 ;
67 | Progress::instance()->push() ;
68 | if(!quiet_)
69 | {
70 | Progress::instance()->notify(0) ;
71 | }
72 | }
73 | void ProgressLogger::reset(int max_val)
74 | {
75 | max_val_ = max_val ;
76 | reset() ;
77 | }
78 |
79 | ProgressLogger::~ProgressLogger()
80 | {
81 | Progress::instance()->notify(100) ;
82 | Progress::instance()->pop() ;
83 | Progress::instance()->notify(0);
84 | }
85 |
86 | void ProgressLogger::next()
87 | {
88 | update() ;
89 | cur_val_++ ;
90 | }
91 |
92 | void ProgressLogger::notify(int new_val)
93 | {
94 | cur_val_ = new_val ;
95 | update() ;
96 | }
97 |
98 | template
99 | inline T ogf_max(T x1, T x2)
100 | {
101 | return x1 > x2 ? x1 : x2;
102 | }
103 |
104 | template
105 | inline T ogf_min(T x1, T x2) {
106 | return x1 < x2 ? x1 : x2;
107 | }
108 |
109 | void ProgressLogger::update()
110 | {
111 | int percent = cur_val_ * 100 / ogf_max(1, max_val_-1) ;
112 | if(percent != cur_percent_)
113 | {
114 | cur_percent_ = percent ;
115 | if(!quiet_)
116 | {
117 | Progress::instance()->notify(ogf_min(cur_percent_, 100)) ;
118 | }
119 | }
120 | }
121 |
122 |
--------------------------------------------------------------------------------
/ManhattanModeler/ProgressBar.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 |
5 |
6 | class ProgressClient ;
7 |
8 | class Progress
9 | {
10 | public:
11 | Progress() ;
12 | virtual ~Progress() ;
13 | virtual void notify(int new_val) ;
14 | static Progress* instance() ;
15 | void set_client(ProgressClient* c) { client_ = c ; }
16 | void push() ;
17 | void pop() ;
18 | void cancel() { canceled_ = true ; }
19 | void clear_canceled() { canceled_ = false ; }
20 | bool is_canceled() const { return canceled_ ; }
21 | private:
22 | static Progress* instance_ ;
23 | ProgressClient* client_ ;
24 | int level_ ;
25 | bool canceled_ ;
26 | } ;
27 |
28 | //_________________________________________________________
29 |
30 | class ProgressClient
31 | {
32 | public:
33 | virtual void notify_progress(int new_val) = 0;
34 | virtual ~ProgressClient() ;
35 | } ;
36 |
37 | //_________________________________________________________
38 |
39 | class ProgressLogger
40 | {
41 | public:
42 | ProgressLogger(int max_val = 100, bool quiet = false) ;
43 | virtual ~ProgressLogger() ;
44 | virtual void notify(int new_val) ;
45 | virtual void next() ;
46 | bool is_canceled() const
47 | {
48 | return Progress::instance()->is_canceled() ;
49 | }
50 | void reset() { notify(0) ; }
51 | void reset(int max_val) ;
52 |
53 | protected:
54 | virtual void update() ;
55 |
56 | private:
57 | int max_val_ ;
58 | int cur_val_ ;
59 | int cur_percent_ ;
60 | bool quiet_ ;
61 | } ;
62 |
63 |
--------------------------------------------------------------------------------
/ManhattanModeler/Resources/ManhattanModeler.qrc:
--------------------------------------------------------------------------------
1 |
2 |
3 | exit.png
4 | fileopen.png
5 | filesave.png
6 | fullscreen.png
7 | home.png
8 | lighton.png
9 | manipulation.png
10 | snap_shot.png
11 | transparent.png
12 | triangulation.png
13 |
14 |
15 |
--------------------------------------------------------------------------------
/ManhattanModeler/Resources/exit.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LiangliangNan/ManhattanModeler/ef257690a2c3f4d36be430452db5bbb2d1bd54b0/ManhattanModeler/Resources/exit.png
--------------------------------------------------------------------------------
/ManhattanModeler/Resources/fileopen.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LiangliangNan/ManhattanModeler/ef257690a2c3f4d36be430452db5bbb2d1bd54b0/ManhattanModeler/Resources/fileopen.png
--------------------------------------------------------------------------------
/ManhattanModeler/Resources/filesave.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LiangliangNan/ManhattanModeler/ef257690a2c3f4d36be430452db5bbb2d1bd54b0/ManhattanModeler/Resources/filesave.png
--------------------------------------------------------------------------------
/ManhattanModeler/Resources/fullscreen.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LiangliangNan/ManhattanModeler/ef257690a2c3f4d36be430452db5bbb2d1bd54b0/ManhattanModeler/Resources/fullscreen.png
--------------------------------------------------------------------------------
/ManhattanModeler/Resources/home.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LiangliangNan/ManhattanModeler/ef257690a2c3f4d36be430452db5bbb2d1bd54b0/ManhattanModeler/Resources/home.png
--------------------------------------------------------------------------------
/ManhattanModeler/Resources/lighton.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LiangliangNan/ManhattanModeler/ef257690a2c3f4d36be430452db5bbb2d1bd54b0/ManhattanModeler/Resources/lighton.png
--------------------------------------------------------------------------------
/ManhattanModeler/Resources/manipulation.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LiangliangNan/ManhattanModeler/ef257690a2c3f4d36be430452db5bbb2d1bd54b0/ManhattanModeler/Resources/manipulation.png
--------------------------------------------------------------------------------
/ManhattanModeler/Resources/snap_shot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LiangliangNan/ManhattanModeler/ef257690a2c3f4d36be430452db5bbb2d1bd54b0/ManhattanModeler/Resources/snap_shot.png
--------------------------------------------------------------------------------
/ManhattanModeler/Resources/transparent.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LiangliangNan/ManhattanModeler/ef257690a2c3f4d36be430452db5bbb2d1bd54b0/ManhattanModeler/Resources/transparent.png
--------------------------------------------------------------------------------
/ManhattanModeler/Resources/triangulation.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LiangliangNan/ManhattanModeler/ef257690a2c3f4d36be430452db5bbb2d1bd54b0/ManhattanModeler/Resources/triangulation.png
--------------------------------------------------------------------------------
/ManhattanModeler/counted.cpp:
--------------------------------------------------------------------------------
1 |
2 | #include "counted.h"
3 |
4 |
5 | Counted::~Counted() {
6 | assert(nb_refs_ == 0) ;
7 | }
8 |
9 | void Counted::ref(const Counted* counted) {
10 | if(counted != nil) {
11 | counted->ref() ;
12 | }
13 | }
14 |
15 | void Counted::unref(const Counted* counted) {
16 | if(counted != nil) {
17 | counted->unref() ;
18 | }
19 | }
20 |
21 |
22 |
--------------------------------------------------------------------------------
/ManhattanModeler/counted.h:
--------------------------------------------------------------------------------
1 |
2 | #ifndef _COUNTED_H_
3 | #define _COUNTED_H_
4 |
5 | #include "basic_types.h"
6 | #include "smart_pointer.h"
7 | #include
8 |
9 |
10 | //____________________________________________________________________________
11 |
12 | /**
13 | * This is the base class to be used for objects having
14 | * "reference count" memory management. They can be
15 | * referred to by using SmartPointer, calling ref()
16 | * and unref() when necessary.
17 | * @see SmartPointer
18 | */
19 |
20 | class Counted {
21 |
22 | public:
23 | Counted() ;
24 | virtual ~Counted() ;
25 |
26 | void ref() const ;
27 | void unref() const ;
28 | bool is_shared() const ;
29 |
30 | static void ref(const Counted* counted) ;
31 | static void unref(const Counted* counted) ;
32 |
33 | protected:
34 | private:
35 | int nb_refs_ ;
36 | } ;
37 |
38 | //____________________________________________________________________________
39 |
40 | inline Counted::Counted() : nb_refs_(0) {
41 | }
42 |
43 | inline void Counted::ref() const {
44 | Counted* non_const_this = (Counted *)this ;
45 | non_const_this->nb_refs_++ ;
46 | }
47 |
48 | inline void Counted::unref() const {
49 | Counted* non_const_this = (Counted *)this ;
50 | non_const_this->nb_refs_-- ;
51 |
52 | assert(nb_refs_ >= 0) ;
53 |
54 | if(nb_refs_ == 0) {
55 | delete this ;
56 | }
57 | }
58 |
59 | inline bool Counted::is_shared() const {
60 | return (nb_refs_ > 1) ;
61 | }
62 |
63 |
64 | #endif
65 |
--------------------------------------------------------------------------------
/ManhattanModeler/dlgFittingBox.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | frmFittingBox
4 |
5 |
6 |
7 | 0
8 | 0
9 | 180
10 | 120
11 |
12 |
13 |
14 |
15 | 180
16 | 120
17 |
18 |
19 |
20 |
21 | 180
22 | 120
23 |
24 |
25 |
26 | Form
27 |
28 |
29 |
30 |
31 | 120
32 | 30
33 | 50
34 | 20
35 |
36 |
37 |
38 | 0.258
39 |
40 |
41 |
42 |
43 |
44 | 10
45 | 56
46 | 91
47 | 23
48 |
49 |
50 |
51 | merge Similar Plane
52 |
53 |
54 |
55 |
56 |
57 | 10
58 | 10
59 | 82
60 | 20
61 |
62 |
63 |
64 | Parallal thresh.
65 |
66 |
67 |
68 |
69 |
70 | 120
71 | 7
72 | 50
73 | 20
74 |
75 |
76 |
77 | 0.966
78 |
79 |
80 |
81 |
82 |
83 | 120
84 | 54
85 | 50
86 | 20
87 |
88 |
89 |
90 | 0.2
91 |
92 |
93 |
94 |
95 |
96 | 10
97 | 33
98 | 82
99 | 20
100 |
101 |
102 |
103 | Vertical thresh.
104 |
105 |
106 |
107 |
108 |
109 | 70
110 | 90
111 | 41
112 | 23
113 |
114 |
115 |
116 | Run
117 |
118 |
119 |
120 |
121 |
122 |
123 |
--------------------------------------------------------------------------------
/ManhattanModeler/dlg_ransac_detection_parameters.cpp:
--------------------------------------------------------------------------------
1 | #include "dlg_ransac_detection_parameters.h"
2 | #include "../algorithm/ransac_detector.h"
3 | #include "../geometry/geometry_global.h"
4 |
5 |
6 | #include
7 | #include
8 |
9 |
10 |
11 | CDlgParameterControl::CDlgParameterControl(QWidget *parent)
12 | : QDialog(parent)
13 | {
14 | setupUi(this);
15 |
16 | default_min_support_ = QString("%1").arg(Geom::ransac_minimum_support);
17 | default_distance_threshold_ = QString("%1").arg(Geom::ransac_distance_threshold);
18 | default_bitmap_resolution_ = QString("%1").arg(Geom::ransac_bitmap_resolution);
19 |
20 | lineEditMinimumSupport->setValidator(new QIntValidator(10, 1000000, this));
21 | lineEditDistanceThreshold->setValidator(new QDoubleValidator(0.00001, 1.0, 5, this));
22 | lineEditBitmapResolution->setValidator(new QDoubleValidator(0.00001, 1.0, 5, this));
23 |
24 | reset();
25 |
26 | connect(resetButton, SIGNAL(clicked()), this, SLOT(reset()));
27 | connect(applyButton, SIGNAL(clicked()), this, SLOT(apply()));
28 | connect(okButton, SIGNAL(clicked()), this, SLOT(apply()));
29 | connect(okButton, SIGNAL(clicked()), this, SLOT(accept()));
30 | }
31 |
32 | CDlgParameterControl::~CDlgParameterControl()
33 | {
34 |
35 | }
36 |
37 |
38 | void CDlgParameterControl::apply()
39 | {
40 | Geom::ransac_minimum_support = lineEditMinimumSupport->text().toUInt();
41 | Geom::ransac_distance_threshold = lineEditDistanceThreshold->text().toDouble();
42 | Geom::ransac_bitmap_resolution = lineEditBitmapResolution->text().toDouble();
43 | }
44 |
45 | void CDlgParameterControl::reset()
46 | {
47 | lineEditMinimumSupport->setText(default_min_support_);
48 | lineEditDistanceThreshold->setText(default_distance_threshold_);
49 | lineEditBitmapResolution->setText(default_bitmap_resolution_);
50 | }
51 |
--------------------------------------------------------------------------------
/ManhattanModeler/dlg_ransac_detection_parameters.h:
--------------------------------------------------------------------------------
1 | #ifndef DLGRANSACDETECTIONPARAMETERS_H
2 | #define DLGRANSACDETECTIONPARAMETERS_H
3 |
4 | #include
5 | #include "ui_dlg_param_control.h"
6 |
7 | class CDlgParameterControl : public QDialog, public Ui::CDlgParamControl
8 | {
9 | Q_OBJECT
10 |
11 | public:
12 | CDlgParameterControl(QWidget *parent = 0);
13 | ~CDlgParameterControl();
14 |
15 | private slots:
16 | void apply();
17 | void reset();
18 |
19 | private:
20 | QString default_min_support_;
21 | QString default_distance_threshold_;
22 | QString default_bitmap_resolution_;
23 | };
24 |
25 | #endif // DLGRANSACDETECTIONPARAMETERS_H
26 |
--------------------------------------------------------------------------------
/ManhattanModeler/draw_model.h:
--------------------------------------------------------------------------------
1 |
2 | #ifndef _POINT_SET_DRAW_MODE_H_
3 | #define _POINT_SET_DRAW_MODE_H_
4 |
5 |
6 | enum DrawMode {
7 | DM_INITIAL_POINTS,
8 | DM_RANSAC_GROUPS,
9 | DM_CANDICATE_BOXES,
10 | DM_OPTIMIZE_BOXES,
11 | DM_FOOT_GRID,
12 | DM_MESH
13 | };
14 |
15 | #endif
--------------------------------------------------------------------------------
/ManhattanModeler/fitBoxes.h:
--------------------------------------------------------------------------------
1 |
2 | //===========================================================================
3 | // This code implements the FittingBox method described in:
4 | //
5 | // Minglei Li, Peter Wonka, Liangliang Nan
6 | // "Manhattan-world Urban Reconstruction from Point Clouds"
7 | // ECCV'2016.
8 | //
9 | // E-Mail: minglei_li@126.com (Minglei Li)
10 | // pwonka@gmail.com (Peter Wonka)
11 | // liangliang.nan@gmail.com (Liangliang Nan)
12 | //
13 | // All rights reserved
14 | //===========================================================================
15 |
16 |
17 | // box structure used after fitting boxes.
18 | #pragma once
19 |
20 | #include "math_types.h"
21 | #include "CPointCloud.h"
22 | #include "CPolyHedron.h"
23 | #include "draw_model.h"
24 |
25 | #include "CFittingBox.h"
26 |
27 | #include
28 | #include "CCube.h"
29 |
30 | class CVertexGroup;
31 | class CBoundingBox;
32 | class CCubeBoxes: public std::vector
33 | {
34 | public:
35 | CCubeBoxes();
36 | CCubeBoxes(CPointCloud * pc,CFittingBox * fb);
37 | ~CCubeBoxes();
38 | public:
39 | CPointCloud * m_pc;
40 | CBoundingBox m_bbox;
41 |
42 | CPolyHedron * m_finalPhModel; // the final merged model. using bool option to merger m_vCPolyhedron.
43 | std::vector m_boxOverlap; // denote if each pair boxes are overlapped. if there are n boxes, this vector contains n*n elements.
44 |
45 | private:
46 | std::vector<_pCoord> m_vecBoxCoord;
47 | int m_numX,m_numY,m_numZ; // denote how many rows, columns, roofs of boxes
48 |
49 | private:
50 | std::vector> m_vecBox8pnts; // its size is box number, a vector contains all detected boxes, each has 8 points.
51 |
52 | std::vector> m_vecBox6Plns;// its size is equal to box number,each item has 6 pointGroup.
53 |
54 | public:
55 | void drawFitBoxes(DrawMode drawmodel);
56 | void drawViewScore();
57 |
58 | void graphcutClassify();
59 |
60 | private:
61 | void buildCubeFrom8Pnt();
62 | void identifyCubeNeighbor();
63 | void cal_cubeScore(); // for each cube, calculate its facet cover rate.
64 |
65 | QString genIthName(int i, const char * str); // generate the variable name, e.g. x0, x1, x2, ...
66 |
67 | void mergeUnionPolyhedron();
68 | void convert_to_exact_polyhedron(std::vector & v8Pnts, cgNef_polyhedron_3 &outNefPH);
69 | };
70 |
--------------------------------------------------------------------------------
/ManhattanModeler/ioFile.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 | #include
4 |
5 | #include "CPointCloud.h"
6 | //#include "CVertexGroup.h"
7 |
8 |
9 | namespace lml_IO
10 | {
11 | std::string get_filename_extension(const std::string file_name);
12 | void read_model_file(std::string & filename);
13 | //bool read_Polyhedron_From_OFF(const char* filename, cgPolyhedron & ph);
14 | void load_blab_to_PCGroup(const std::string& file_name, std::vector & groups) ;
15 | bool write_blab_From_RANSAC(const char* file_name, std::vector & groups);
16 | //void write_fitbox_From_Fitbox( const char* filename , CFitBoxes * m_fitBoxes );
17 | //bool write_OFF_From_Polyhedron(const char* filename, cgPolyhedron & ph);
18 | void load_PC_From_xyzn(CPointCloud *& pc, const char * filename);
19 | }
--------------------------------------------------------------------------------
/ManhattanModeler/logger.cpp:
--------------------------------------------------------------------------------
1 | #include "logger.h"
2 | #include
3 | #include
4 |
5 | LoggerClient* Logger::client_ = NULL;
6 |
7 |
8 | void Logger::initSet(LoggerClient *c)
9 | {
10 | client_ = c;
11 | }
12 |
13 |
14 | LoggerClient& Logger::output(const std::string& msg) {
15 | if (client_ == NULL) {
16 | std::cout << "Logger is NOT initialized!" << std::endl;
17 | return *client_;
18 | }
19 |
20 | client_->output(msg);
21 | return *client_;
22 | }
23 |
24 | std::string Logger::endl() {
25 | if (client_ == NULL) {
26 | std::cout << "Logger is NOT initialized!" << std::endl;
27 | return "";
28 | }
29 |
30 | return ("\n");
31 | }
32 |
33 | std::string Logger::convDouble2Str(double val)
34 | {
35 | std::ostringstream sso;
36 | sso<
4 | #include "logger_client.h"
5 |
6 | class Logger
7 | {
8 | public:
9 | static void initSet(LoggerClient* c);
10 | static LoggerClient& output(const std::string& msg = "") ;
11 | static std::string endl();
12 |
13 | static std::string convDouble2Str(double val);
14 | static std::string convInt2Str (int val);
15 |
16 | private:
17 | static LoggerClient* client_;
18 | };
19 |
--------------------------------------------------------------------------------
/ManhattanModeler/logger_client.cpp:
--------------------------------------------------------------------------------
1 | #include "logger_client.h"
2 |
3 | LoggerClient& LoggerClient::operator<<(int v)
4 | {
5 | output(v);
6 | return *this;
7 | }
8 |
9 | LoggerClient& LoggerClient::operator<<(unsigned int v)
10 | {
11 | output(int(v));
12 | return *this;
13 | }
14 |
15 | LoggerClient& LoggerClient::operator<<(float v) {
16 | output(v);
17 | return *this;
18 | }
19 |
20 | LoggerClient& LoggerClient::operator<<(double v) {
21 | output(v);
22 | return *this;
23 | }
24 |
25 |
26 | LoggerClient& LoggerClient::operator<<(const char* x) {
27 | output(std::string(x));
28 | return *this;
29 | }
30 |
31 | LoggerClient& LoggerClient::operator<<(const std::string& x) {
32 | output(x);
33 | return *this;
34 | }
35 |
--------------------------------------------------------------------------------
/ManhattanModeler/logger_client.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 |
5 |
6 | class LoggerClient
7 | {
8 | public:
9 | LoggerClient() {}
10 |
11 | virtual ~LoggerClient() {}
12 |
13 | virtual LoggerClient* output(const std::string& msg) = 0;
14 | virtual LoggerClient* output(int v) = 0;
15 | virtual LoggerClient* output(double v) = 0;
16 |
17 | LoggerClient& operator<<(int v) ;
18 | LoggerClient& operator<<(unsigned int v) ;
19 | LoggerClient& operator<<(float v) ;
20 | LoggerClient& operator<<(double v) ;
21 | LoggerClient& operator<<(const char* x) ;
22 | LoggerClient& operator<<(const std::string& msg) ;
23 | } ;
--------------------------------------------------------------------------------
/ManhattanModeler/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include "main_window.h"
9 |
10 |
11 | int main(int argc, char **argv)
12 | {
13 | srand(time(0));
14 | QApplication app(argc, argv);
15 |
16 | MainWindow win;
17 | win.show();
18 |
19 | return app.exec();
20 | };
21 |
--------------------------------------------------------------------------------
/ManhattanModeler/math_global.cpp:
--------------------------------------------------------------------------------
1 | #include "math_global.h"
2 | #include
3 | #include
4 |
5 |
6 |
7 | namespace Global {
8 |
9 | Colorf facet_color = Colorf(1.0f, 0.67f, 0.5f, 1.0f);
10 |
11 |
12 | float normalize(cgVector3f& v) {
13 | float len = std::sqrt(v.squared_length());
14 | if (len != 0.0f)
15 | v = v / len;
16 | return len;
17 | }
18 |
19 | float length_of(const cgVector3f& v) {
20 | return std::sqrt(v.squared_length());
21 | }
22 |
23 | cgBbox3f bbox_of(const std::vector& points) {
24 | // axis-aligned bounding box of 3D points
25 |
26 | return CGAL::bounding_box(points.begin(), points.end()).bbox();
27 | }
28 |
29 | }
--------------------------------------------------------------------------------
/ManhattanModeler/math_global.h:
--------------------------------------------------------------------------------
1 | // geometry_global.h
2 | #ifndef _MATH_GLOBAL_H_
3 | #define _MATH_GLOBAL_H_
4 |
5 |
6 | #include "math_types.h"
7 | #include "color.h"
8 |
9 | #define MATH_FLOAT_PI 3.14159265359
10 |
11 | enum CoordTranferMode
12 | {
13 | TR_XY, // around Z axis
14 | TR_YZ, // around X axis
15 | TR_ZX // around y axis
16 | };
17 |
18 | namespace Global {
19 |
20 | extern Colorf facet_color;
21 |
22 |
23 | //////////////////////////////////////////////////////////////////////////
24 |
25 |
26 | float normalize(cgVector3f& v) ;
27 | float length_of(const cgVector3f& v);
28 |
29 | cgBbox3f bbox_of(const std::vector& points);
30 |
31 | } ;
32 |
33 |
34 | #endif
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/ManhattanModeler/math_types.cpp:
--------------------------------------------------------------------------------
1 | #include "math_types.h"
2 |
3 | #include
4 |
5 | #ifndef M_PI
6 | #define M_PI 3.14159265358979323846f
7 | #endif
8 |
9 | namespace Geom
10 | {
11 |
12 | bool point_in_polygon( const cgPoint2f& p, const cgPolygon2f& polygon )
13 | {
14 | bool bIsInside = false;
15 | size_t n = (int)polygon.size();
16 |
17 | for (size_t i=0, j=n-1; i p.x())
28 | bIsInside = !bIsInside;
29 | }
30 | }
31 | return bIsInside;
32 | }
33 |
34 | bool point_in_polygon( const cgPoint2f& p, const std::vector& polygon )
35 | {
36 | bool bIsInside = false;
37 | size_t n = (int)polygon.size();
38 |
39 | for (size_t i=0, j=n-1; i p.x())
49 | bIsInside = !bIsInside;
50 | }
51 | }
52 | return bIsInside;
53 | }
54 |
55 | cgBbox2f bbox_of( const std::vector& points )
56 | {
57 | return CGAL::bounding_box(points.begin(), points.end()).bbox();
58 | }
59 |
60 | }
--------------------------------------------------------------------------------
/ManhattanModeler/pgm_io.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | /******************************************************************************
4 | * Function: read_pgm_image
5 | * Purpose: This function reads in an image in PGM format. The image can be
6 | * read in from either a file or from standard input. The image is only read
7 | * from standard input when infilename = NULL. Because the PGM format includes
8 | * the number of columns and the number of rows in the image, these are read
9 | * from the file. Memory to store the image is allocated in this function.
10 | * All comments in the header are discarded in the process of reading the
11 | * image. Upon failure, this function returns 0, upon sucess it returns 1.
12 | ******************************************************************************/
13 | int read_pgm_image(char *infilename, unsigned char **image, int *rows,int *cols);
14 | /******************************************************************************
15 | * Function: write_pgm_image
16 | * Purpose: This function writes an image in PGM format. The file is either
17 | * written to the file specified by outfilename or to standard output if
18 | * outfilename = NULL. A comment can be written to the header if coment != NULL.
19 | ******************************************************************************/
20 | int write_pgm_image(char *outfilename, unsigned char *image, int rows, int cols, char *comment, int maxval);
21 | /******************************************************************************
22 | * Function: read_ppm_image
23 | * Purpose: This function reads in an image in PPM format. The image can be
24 | * read in from either a file or from standard input. The image is only read
25 | * from standard input when infilename = NULL. Because the PPM format includes
26 | * the number of columns and the number of rows in the image, these are read
27 | * from the file. Memory to store the image is allocated in this function.
28 | * All comments in the header are discarded in the process of reading the
29 | * image. Upon failure, this function returns 0, upon sucess it returns 1.
30 | ******************************************************************************/
31 | int read_ppm_image(char *infilename, unsigned char **image_red,
32 | unsigned char **image_grn, unsigned char **image_blu, int *rows,
33 | int *cols);
34 | /******************************************************************************
35 | * Function: write_ppm_image
36 | * Purpose: This function writes an image in PPM format. The file is either
37 | * written to the file specified by outfilename or to standard output if
38 | * outfilename = NULL. A comment can be written to the header if coment != NULL.
39 | ******************************************************************************/
40 | int write_ppm_image(char *outfilename, unsigned char *image_red,
41 | unsigned char *image_grn, unsigned char *image_blu, int rows,
42 | int cols, char *comment, int maxval);
--------------------------------------------------------------------------------
/ManhattanModeler/plyIO.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/LiangliangNan/ManhattanModeler/ef257690a2c3f4d36be430452db5bbb2d1bd54b0/ManhattanModeler/plyIO.h
--------------------------------------------------------------------------------
/ManhattanModeler/ransac_detector.h:
--------------------------------------------------------------------------------
1 |
2 | #pragma once
3 |
4 | #include "CPointCloud.h"
5 | class RansacDetector
6 | {
7 | RansacDetector(void);
8 | ~RansacDetector(void);
9 | public:
10 | static unsigned int ransac_apply( CPointCloud * pntCloud, std::vector & pntGroup /*, CPointCloud * pntCloudRemaind */);
11 |
12 | };
13 |
14 |
15 |
--------------------------------------------------------------------------------
/ManhattanModeler/select_tool.h:
--------------------------------------------------------------------------------
1 | #ifndef _SELECT_TOOL_H_
2 | #define _SELECT_TOOL_H_
3 |
4 | #include "tool3d.h"
5 |
6 | #include
7 | #include
8 |
9 |
10 |
11 | namespace Tl {
12 |
13 | // Different selection modes
14 | enum SelectMode {
15 | SM_ADD,
16 | SM_REMOVE,
17 | SM_NONE
18 | };
19 |
20 |
21 | enum SelectMethod {
22 | SM_HIT,
23 | SM_RECTANGLE,
24 | SM_LASSO
25 | };
26 |
27 | enum SelectButton {
28 | SBT_LEFT,
29 | SBT_RIGHT,
30 | SBT_BOTH
31 | };
32 |
33 |
34 | class SelectTool : public Tool3D
35 | {
36 | public:
37 | SelectTool(PaintCanvas* canvas) ;
38 | virtual ~SelectTool() ;
39 |
40 | virtual void press(QMouseEvent *e) ;
41 | virtual void move(QMouseEvent *e) ;
42 | virtual void release(QMouseEvent *e) ;
43 |
44 | virtual void draw() const ;
45 |
46 | const std::vector& get_selected_object_indices() const ;
47 | const std::vector& get_highlighted_object_indices() const ;
48 |
49 | SelectMethod select_method() const { return select_method_; }
50 | void set_select_method(SelectMethod method) { select_method_ = method; }
51 |
52 | SelectButton select_button() const { return select_button_; }
53 | void set_select_button(SelectButton bt) { select_button_ = bt; }
54 |
55 | // NOTE: very important, you must call this function in you constructor
56 | void initialize_select_buffer() ; // set the buffer size
57 |
58 | protected:
59 | void set_select_buffer_size(size_t size);
60 |
61 | virtual void draw_with_names() const = 0;
62 | virtual size_t needed_buffer_size() const = 0;
63 |
64 | virtual void unselect_all() = 0;
65 | virtual void unhighlight_all() = 0;
66 |
67 | void select(const QPoint& point);
68 | void highlight(const QPoint& point);
69 |
70 | void begin_selection(const QPoint& point);
71 | void end_selection(const QPoint& point);
72 | virtual void make_selection(bool b = true) = 0;
73 |
74 | void begin_highlight(const QPoint& point);
75 | void end_highlight(const QPoint& point);
76 | virtual void make_highlight() = 0;
77 |
78 | virtual void drag(QMouseEvent *e) ;
79 | virtual void reset() {}
80 |
81 |
82 | protected:
83 | void draw_selection_rectangle() const ;
84 |
85 | protected:
86 | int hit_resolution_; // in pixels
87 | int select_region_width_;
88 | int select_region_height_;
89 | size_t select_buffer_size_;
90 | //std::vector select_buffer_;
91 | unsigned int* select_buffer_;
92 |
93 | bool multi_select_;
94 |
95 | SelectMode select_mode_;
96 | SelectMethod select_method_;
97 | SelectButton select_button_;
98 |
99 | QPoint mouse_pressed_pos_;
100 | QPoint mouse_moving_pos_;
101 |
102 | // Current rectangular selection
103 | QRect rectangle_;
104 |
105 | std::vector selected_object_indices_;
106 | std::vector highlighted_object_indices_;
107 | } ;
108 | }
109 |
110 |
111 |
112 | #endif
113 |
--------------------------------------------------------------------------------
/ManhattanModeler/simpleWidget.cpp:
--------------------------------------------------------------------------------
1 | #include "simpleWidget.h"
2 |
3 | #include "Parameters.h"
4 |
5 | simpleWidget::simpleWidget( QWidget *parent /*= 0*/ )
6 | {
7 | setupUi();
8 |
9 | connect(m_pushBtn, SIGNAL(clicked()), this, SLOT(onDlgBtnClick()));
10 | }
11 |
12 | simpleWidget::~simpleWidget(void)
13 | {
14 | }
15 |
16 | void simpleWidget::setupUi()
17 | {
18 | m_label = new QLabel(this);
19 | m_label->setText(QString("point size:"));
20 | m_label->setObjectName(QString::fromUtf8("label_1"));
21 | m_label->setGeometry(20,10,45,21);
22 |
23 | m_pushBtn = new QPushButton(this);
24 | m_pushBtn->setObjectName(QString::fromUtf8("pushButton"));
25 | m_pushBtn->setGeometry(QRect(50, 40, 75, 23));
26 | m_pushBtn->setText(QString("set"));
27 |
28 | m_lineEdit = new QLineEdit(this);
29 | m_lineEdit->setObjectName(QString::fromUtf8("lineEdit"));
30 | m_lineEdit->setGeometry(QRect(80, 10, 61, 20));
31 | m_lineEdit->setText(QString("2"));
32 |
33 | }
34 | void simpleWidget::onDlgBtnClick( void )
35 | {
36 | int num = m_lineEdit->text().toUInt();
37 | lml_param::showPointSize = num;
38 |
39 | this->done(QDialog::Accepted);
40 | }
41 |
42 |
--------------------------------------------------------------------------------
/ManhattanModeler/simpleWidget.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 |
4 | #include
5 | #include
6 | #include
7 | #include
8 |
9 | class simpleWidget: public QDialog
10 | {
11 | Q_OBJECT
12 |
13 | public:
14 | simpleWidget( QWidget *parent = 0 );
15 | ~simpleWidget(void);
16 |
17 | private slots:
18 | void onDlgBtnClick( void );
19 |
20 |
21 | private:
22 | void setupUi();
23 |
24 | private:
25 | QLabel *m_label;
26 | QPushButton *m_pushBtn;
27 | QLineEdit *m_lineEdit;
28 |
29 |
30 | };
--------------------------------------------------------------------------------
/ManhattanModeler/smart_pointer.h:
--------------------------------------------------------------------------------
1 |
2 | #ifndef _SMART_POINTER_H_
3 | #define _SMART_POINTER_H_
4 |
5 | #include "basic_types.h"
6 |
7 | #include
8 |
9 |
10 | //____________________________________________________________________________
11 |
12 | /**
13 | * Automatic memory management using reference counting.
14 | * This class can be used with classes inheriting
15 | * the Counted class.
16 | * @see Counted
17 | */
18 |
19 | template
20 | class SmartPointer
21 | {
22 |
23 | public:
24 | SmartPointer() ;
25 | SmartPointer(T* ptr) ;
26 | SmartPointer(const SmartPointer& rhs) ;
27 | ~SmartPointer() ;
28 |
29 | SmartPointer& operator=(T* ptr) ;
30 | SmartPointer& operator=(const SmartPointer& rhs) ;
31 |
32 | /**
33 | * Makes the current instance a nil pointer ("forgets" the
34 | * current reference). 'p.forget();' is a shorthand for
35 | * 'p = nil;'
36 | */
37 | void forget() ;
38 |
39 | T* operator->() const ;
40 | T& operator*() const ;
41 | operator T*() const ;
42 |
43 | /**
44 | * 'if(p.is_nil()) {...}' is a shorthand for 'if(p == nil) {...}'
45 | */
46 | bool is_nil() const ;
47 |
48 | T* get() { return pointer_; }
49 | const T* get() const { return pointer_; }
50 |
51 | protected:
52 | private:
53 | T* pointer_ ;
54 | } ;
55 |
56 | //____________________________________________________________________________
57 |
58 | template inline
59 | SmartPointer::SmartPointer() : pointer_(nil) {
60 | }
61 |
62 | template inline
63 | SmartPointer::SmartPointer(T* ptr) : pointer_(ptr) {
64 | T::ref(pointer_) ;
65 | }
66 |
67 | template inline
68 | SmartPointer::SmartPointer(
69 | const SmartPointer& rhs
70 | ) : pointer_(rhs) {
71 | T::ref(pointer_) ;
72 | }
73 |
74 | template inline
75 | SmartPointer::~SmartPointer() {
76 | T::unref(pointer_) ;
77 | }
78 |
79 | template inline
80 | SmartPointer& SmartPointer::operator=(T* ptr) {
81 | if(ptr != pointer_) {
82 | T::unref(pointer_) ;
83 | pointer_ = ptr ;
84 | T::ref(pointer_) ;
85 | }
86 | return *this ;
87 | }
88 |
89 | template inline
90 | SmartPointer& SmartPointer::operator=(const SmartPointer& rhs) {
91 | T* rhs_p = rhs ;
92 | if(rhs_p != pointer_) {
93 | T::unref(pointer_) ;
94 | pointer_ = rhs_p ;
95 | T::ref(pointer_) ;
96 | }
97 | return *this ;
98 | }
99 |
100 | template inline
101 | void SmartPointer::forget() {
102 | T::unref(pointer_) ;
103 | pointer_ = nil ;
104 | }
105 |
106 | template inline
107 | T* SmartPointer::operator->() const {
108 | assert(pointer_ != nil) ;
109 | return pointer_ ;
110 | }
111 |
112 | template inline
113 | T& SmartPointer::operator*() const {
114 | assert(pointer_ != nil) ;
115 | return *pointer_ ;
116 | }
117 |
118 | template inline
119 | SmartPointer::operator T*() const {
120 | return pointer_ ;
121 | }
122 |
123 | template inline
124 | bool SmartPointer::is_nil() const {
125 | return (pointer_ == nil) ;
126 | }
127 |
128 |
129 | #endif
130 |
--------------------------------------------------------------------------------
/ManhattanModeler/tool3D.cpp:
--------------------------------------------------------------------------------
1 |
2 | #include "tool3d.h"
3 | #include "paint_canvas.h"
4 |
5 |
6 | #include
7 |
8 |
9 | namespace Tl {
10 |
11 | Tool3D::Tool3D(PaintCanvas* canvas)
12 | : canvas_(canvas)
13 | , left_button_down_(false)
14 | , right_button_down_(false)
15 | , middle_button_down_(false)
16 | {
17 | }
18 |
19 | PaintCanvas* Tool3D::canvas() const {
20 | return canvas_ ;
21 | }
22 |
23 | void Tool3D::set_canvas(PaintCanvas* canvas) {
24 | canvas_ = canvas ;
25 | }
26 |
27 | void Tool3D::status(const std::string& value) {
28 | std::cout << value << "TODO: prompt user in status bar" << std::endl;
29 | // status_message() ;
30 | }
31 |
32 | cgLine3f Tool3D::get_mouse_line_in3DSpace(const QPoint& mouse) const
33 | {
34 | QPoint pos = mouse;
35 | cgPoint3f p_near = canvas()->unProjectionOf(pos.x(), pos.y(), 0.0f);
36 | cgPoint3f p_far = canvas()->unProjectionOf(pos.x(), pos.y(), 1.0f);
37 |
38 | return cgLine3f(p_near, p_far);
39 | }
40 | cgSegment3f Tool3D::get_mouse_segment_in3DSpace(const QPoint& mouse) const
41 | {
42 | QPoint pos = mouse;
43 | cgPoint3f p_near = canvas()->unProjectionOf(pos.x(), pos.y(), 0.0f);
44 | cgPoint3f p_far = canvas()->unProjectionOf(pos.x(), pos.y(), 1.0f);
45 |
46 | return cgSegment3f(p_near, p_far);
47 | }
48 |
49 | cgVector3f Tool3D::get_view_direction_in_3d_space(const QPoint& mouse) const
50 | {
51 | cgLine3f line = get_mouse_line_in3DSpace(mouse);
52 | cgVector3f dir = -line.to_vector();
53 | float len = std::sqrt(dir.squared_length());
54 | if (len != 0.0f)
55 | dir = dir / len;
56 | return dir;
57 | }
58 |
59 | cgPoint3f Tool3D::get_intersect_point(const cgPlane3f& plane, const QPoint& mouse, bool& success) const
60 | {
61 | cgLine3f line = get_mouse_line_in3DSpace(mouse);
62 |
63 | CGAL::Object obj = CGAL::intersection(line, plane);
64 | if (const cgPoint3f * point = CGAL::object_cast(&obj)) {
65 | success = true;
66 | return *point;
67 | } else {
68 | success = false;
69 | return cgPoint3f(0.0f, 0.0f, 0.0f);
70 | }
71 | }
72 |
73 |
74 | bool Tool3D::pnt_selected(const cgPoint3f& pnt, const QPoint& mouse, const float threshSqr, float & zDist) const
75 | {
76 | zDist = 1e6;
77 | QPoint pos = mouse;
78 | cgPoint3f p_near = canvas()->unProjectionOf(pos.x(), pos.y(), 0.0f);
79 | cgPoint3f p_far = canvas()->unProjectionOf(pos.x(), pos.y(), 1.0f);
80 | cgSegment3f line = cgSegment3f(p_near, p_far);
81 | FT distSqr = CGAL::squared_distance(pnt,line);
82 | if (distSqr>threshSqr)
83 | return false;
84 | else
85 | {
86 | cgVector3f v1 = pnt - p_near;
87 | cgVector3f v2 = p_far - p_near;
88 | zDist = v1*v2;
89 | return true;
90 | }
91 | }
92 |
93 |
94 |
95 | //////////////////////////////////////////////////////////////////////////
96 |
97 |
98 | EmptyTool3D::EmptyTool3D(PaintCanvas* canvas)
99 | : Tool3D(canvas)
100 | {
101 | }
102 |
103 |
104 | }
--------------------------------------------------------------------------------
/ManhattanModeler/tool3D.h:
--------------------------------------------------------------------------------
1 | #ifndef _TOOL3D_H_
2 | #define _TOOL3D_H_
3 |
4 | #include "counted.h"
5 | #include "math_types.h"
6 |
7 | #include
8 |
9 | class Object ;
10 | class PaintCanvas;
11 | class QMouseEvent;
12 | class VertexGroup;
13 |
14 | namespace Tl {
15 |
16 |
17 | class Tool3D: public Counted
18 | {
19 | public:
20 | Tool3D(PaintCanvas* canvas) ;
21 |
22 | virtual ~Tool3D() {}
23 |
24 | public:
25 | virtual void press(QMouseEvent *e) = 0;
26 | virtual void release(QMouseEvent *e) = 0;
27 | virtual void move(QMouseEvent *e) = 0;
28 | virtual void reset() = 0;
29 |
30 | virtual void draw() const = 0;
31 |
32 | virtual void status(const std::string& value);
33 |
34 | public:
35 | virtual PaintCanvas* canvas() const;
36 | virtual void set_canvas(PaintCanvas* canvas);
37 |
38 | cgLine3f get_mouse_line_in3DSpace(const QPoint& mouse) const ;
39 | cgSegment3f get_mouse_segment_in3DSpace(const QPoint& mouse) const;
40 | // NOTE: pointing to the outside of the screen
41 | cgVector3f get_view_direction_in_3d_space(const QPoint& mouse) const ;
42 |
43 | cgPoint3f get_intersect_point(const cgPlane3f& plane, const QPoint& mouse, bool& success) const;
44 | // check whether a point is selected on the mouse pos. zDist reflects (!=) the depth to the device-window.
45 | bool pnt_selected(const cgPoint3f& pnt, const QPoint& mouse, const float threshSqr, float & zDist) const;
46 |
47 | protected:
48 | PaintCanvas* canvas_ ;
49 |
50 | bool left_button_down_;
51 | bool right_button_down_;
52 | bool middle_button_down_;
53 | } ;
54 |
55 | //________________________________________________________________
56 |
57 | class EmptyTool3D : public Tool3D
58 | {
59 | public:
60 | EmptyTool3D(PaintCanvas* canvas) ;
61 | virtual ~EmptyTool3D() {}
62 |
63 | public:
64 | virtual void press(QMouseEvent *) {}
65 | virtual void release(QMouseEvent *) {}
66 | virtual void move(QMouseEvent *) {}
67 | virtual void reset() {}
68 |
69 | virtual void draw() const {}
70 | } ;
71 |
72 | }
73 |
74 |
75 | typedef SmartPointer Tool3D_var ;
76 |
77 |
78 | #endif
79 |
--------------------------------------------------------------------------------
/ManhattanModeler/tool_manager3d.cpp:
--------------------------------------------------------------------------------
1 |
2 | #include "tool_manager3d.h"
3 | #include "../3rd_qglviewer/qglviewer.h"
4 | #include "CPointCloud.h"
5 |
6 | using namespace Tl;
7 |
8 | ToolManager3D::ToolManager3D(PaintCanvas* canvas)
9 | : canvas_(canvas)
10 | {
11 | set_tool(TOOL_EMPTY);
12 | }
13 |
14 | ToolManager3D::~ToolManager3D()
15 | {
16 | }
17 |
18 |
19 | void ToolManager3D::set_tool(ToolName name)
20 | {
21 | ToolMap::iterator it = tools_.find(name) ;
22 | if(it == tools_.end())
23 | {
24 | Tool3D* tool = create_new_tool(name);
25 | if (tool != NULL)
26 | {
27 | tools_[name] = tool;
28 | }
29 | }
30 |
31 | it = tools_.find(name);
32 | if(it == tools_.end())
33 | {
34 | current_tool_ = nil ;
35 | current_tool_name_ = TOOL_EMPTY;
36 | return ;
37 | }
38 | current_tool_ = it->second ;
39 | current_tool_name_ = name;
40 | }
41 |
42 |
43 | Tl::Tool3D* ToolManager3D::prepare_tool(Tl::ToolName name)
44 | {
45 | ToolMap::iterator it = tools_.find(name) ;
46 | if(it == tools_.end())
47 | {
48 | Tool3D* tool = create_new_tool(name);
49 | if (tool != nil)
50 | {
51 | tools_[name] = tool;
52 | return tool;
53 | }
54 | }
55 |
56 | it = tools_.find(name) ;
57 | if(it == tools_.end())
58 | {
59 | current_tool_ = nil ;
60 | current_tool_name_ = TOOL_EMPTY;
61 | return nil;
62 | }
63 | return it->second ;
64 | }
65 |
66 |
67 | void ToolManager3D::status(const std::string& value)
68 | {
69 | std::cout << value << "TODO: prompt user in status bar" << std::endl;
70 | // status_message() ;
71 | }
72 |
73 | PaintCanvas* ToolManager3D::canvas() const
74 | {
75 | return canvas_ ;
76 | }
77 |
78 |
79 | void ToolManager3D::clear()
80 | {
81 | tools_.clear();
82 | current_tool_ = NULL;
83 |
84 | current_tool_name_ = TOOL_EMPTY;
85 | }
86 |
87 | void ToolManager3D::set_canvas(PaintCanvas* canvas)
88 | {
89 | canvas_ = canvas ;
90 | }
91 |
92 | Tool3D* ToolManager3D::create_new_tool(Tl::ToolName name)
93 | {
94 | Tool3D* tool = nil;
95 | switch (name)
96 | {
97 | case TOOL_EMPTY:
98 | tool = new EmptyTool3D(canvas_);
99 | break;
100 |
101 | default:
102 | break;
103 | }
104 |
105 | return tool;
106 | }
107 |
108 |
109 | void ToolManager3D::set_select_method(Tl::SelectMethod method)
110 | {
111 | SelectTool* tool = dynamic_cast(current_tool_);
112 | if (tool)
113 | tool->set_select_method(method);
114 | }
115 |
116 | void ToolManager3D::set_select_button(Tl::SelectButton button)
117 | {
118 | SelectTool* tool = dynamic_cast