├── .gitignore ├── Makefile ├── base ├── detection.cc ├── detection.h ├── file_io.h ├── floorplan.cc ├── floorplan.h ├── geometry.h ├── imageProcess │ ├── line.cc.cpp │ ├── line.h │ ├── line3.cc.cpp │ ├── line3.h │ ├── lineExtracter.cc.cpp │ ├── lineExtracter.h │ ├── lineOrganizer.cc.cpp │ ├── lineOrganizer.h │ ├── morphological_operation.cc │ ├── morphological_operation.h │ ├── patch2d.cc.cpp │ ├── patch2d.h │ ├── patch2dOptimizer.cc.beforelmdif.bin │ ├── patch2dOptimizer.cc.cpp │ ├── patch2dOptimizer.h │ ├── patch2dTrack.cc.cpp │ ├── patch2dTrack.h │ ├── patch2dTracker.cc.cpp │ └── patch2dTracker.h ├── indoor_polygon.cc ├── indoor_polygon.h ├── kdtree │ ├── KDtree.cc │ ├── KDtree.h │ └── mempool.h ├── mrf │ ├── BP-S.h │ ├── GCoptimization.h │ ├── ICM.h │ ├── LinkedBlockList.h │ ├── MaxProdBP.h │ ├── TRW-S.h │ ├── block.h │ ├── energy.h │ ├── graph.h │ ├── mrf.h │ ├── regions-new.h │ └── typeTruncatedQuadratic2D.h ├── numeric │ ├── convert.sh │ ├── cooMat.h │ ├── denseMat.h │ ├── euler.h │ ├── mat.h │ ├── mat2.h │ ├── mat3.h │ ├── mat4.h │ ├── mylapack.cc │ ├── mylapack.h │ ├── qr.h │ ├── sparseMat.h │ ├── sparseMatAlgebra.h │ ├── sparseMatSolve.h │ ├── sphericalHarmonics.h │ ├── vec.h │ ├── vec2.h │ ├── vec3.h │ └── vec4.h ├── panorama.cc ├── panorama.h ├── point_cloud.cc └── point_cloud.h ├── delete_files.sh ├── main_process ├── Makefile ├── object_detection │ ├── CMakeLists.txt │ ├── generate_object_icons.cc │ ├── generate_object_icons.h │ └── generate_object_icons_cli.cc ├── object_refinement │ ├── CMakeLists.txt │ ├── MRF │ │ ├── BP-S.cpp │ │ ├── BP-S.h │ │ ├── GCoptimization.cpp │ │ ├── GCoptimization.h │ │ ├── ICM.cpp │ │ ├── ICM.h │ │ ├── LinkedBlockList.cpp │ │ ├── LinkedBlockList.h │ │ ├── MaxProdBP.cpp │ │ ├── MaxProdBP.h │ │ ├── TRW-S.cpp │ │ ├── TRW-S.h │ │ ├── block.h │ │ ├── energy.h │ │ ├── graph.cpp │ │ ├── graph.h │ │ ├── maxflow.cpp │ │ ├── mrf.cpp │ │ ├── mrf.h │ │ ├── regions-maxprod.cpp │ │ ├── regions-new.h │ │ └── typeTruncatedQuadratic2D.h │ ├── SLIC │ │ ├── SLIC.cpp │ │ └── SLIC.h │ ├── depth_filling.cpp │ ├── depth_filling.h │ ├── object_refinement.cpp │ ├── object_refinement.h │ └── object_refinement_cali.cpp ├── object_segmentation │ ├── CMakeLists.txt │ ├── object_segmentation.cc │ ├── object_segmentation.h │ └── object_segmentation_cli.cc └── texture │ ├── CMakeLists.txt │ ├── color_point_cloud_cli.cc │ ├── generate_texture.cc │ ├── generate_texture.h │ ├── generate_texture_floorplan.cc │ ├── generate_texture_floorplan.h │ ├── generate_texture_floorplan_cli.cc │ ├── generate_texture_indoor_polygon.cc │ ├── generate_texture_indoor_polygon.h │ ├── generate_texture_indoor_polygon_cli.cc │ ├── generate_thumbnail_cli.cc │ ├── run.sh │ ├── synthesize.cc │ └── synthesize.h ├── not_used ├── floorplan │ ├── CMakeLists.txt │ ├── generate_floorplan_cli.cc │ ├── old │ │ ├── floorplan.h.bak │ │ ├── floorplan_generation_cli.cc │ │ ├── floorplan_util.cc │ │ ├── floorplan_util.h │ │ └── sample.cc │ ├── polygon_triangulation2.cc │ └── polygon_triangulation2.h ├── segmentation │ ├── CMakeLists.txt │ ├── data.cc │ ├── data.h │ ├── evidence.cc │ ├── evidence.h │ ├── segmentation.cc │ ├── segmentation.h │ └── segmentation_cli.cc └── segmentation_old │ ├── Makefile │ ├── data.h │ ├── door_detection.cc │ ├── door_detection.h │ ├── door_detection_cli │ ├── door_detection_cli.cc │ ├── door_detection_cli.sh │ ├── dynamic_programming.cc │ ├── dynamic_programming.h │ ├── evidence.cc │ ├── evidence.h │ ├── libMRF.a │ ├── preprocess.cc │ ├── preprocess.h │ ├── preprocess_cli.cc │ ├── reconstruct_2d.cc │ ├── reconstruct_2d.h │ ├── reconstruct_2d.robust.cc │ ├── reconstruct_2d_direct_gradient_fail.cc │ ├── refine_segmentation.cc │ ├── refine_segmentation.h │ ├── refine_segmentation_cli │ ├── refine_segmentation_cli.cc │ ├── transform.cc │ ├── transform.h │ └── transform_cli.cc ├── post_process ├── Makefile ├── collada │ ├── CMakeLists.txt │ ├── indoor_polygon_to_dae_cli.cc │ └── ming │ │ ├── FloorPlanInRhino3D.py │ │ ├── ToDraw.py │ │ ├── ToDraw_red.py │ │ ├── blueprint_poly.txt │ │ ├── blueprint_poly_red.txt │ │ └── innerwall_poly.txt ├── evaluation │ ├── CMakeLists.txt │ ├── evaluate.cc │ ├── evaluate.h │ ├── evaluate_cli.cc │ ├── prepare_poisson_cli.cc │ └── run_synthetic.sh └── synthetic │ ├── CMakeLists.txt │ └── generate_synthetic_data_cli.cc ├── pre_process ├── Makefile ├── calibration │ ├── CMakeLists.txt │ ├── align_images.cc │ ├── align_images.h │ ├── align_images_cli.cc │ ├── align_panorama_to_depth_cli.cc │ ├── alignment.m │ ├── alignment_batch.m │ ├── depthmap_refiner.cc │ ├── depthmap_refiner.h │ ├── generate_depthmaps_cli.cc │ ├── render_ply_to_panorama_cli.cc │ ├── simple_read_ply.m │ ├── transformation.cc │ └── transformation.h └── stitch_panorama │ ├── CMakeLists.txt │ ├── stitch_panorama.cc │ ├── stitch_panorama.h │ └── stitch_panorama_cli.cc ├── run.sh ├── run_texture_for_poisson_vgcut.sh ├── script.sh └── viewer ├── .qmake.stash ├── blend_fshader.glsl ├── blend_vshader.glsl ├── configuration.h ├── floorplan_renderer.cc ├── floorplan_renderer.h ├── indoor_polygon_renderer.cc ├── indoor_polygon_renderer.h ├── main_widget.cc ├── main_widget.h ├── main_widget_render.cc ├── main_widget_util.cc ├── main_widget_util.h ├── navigation.cc ├── navigation.h ├── object_renderer.cc ├── object_renderer.h ├── panel_renderer.cc ├── panel_renderer.h ├── panorama_fshader.glsl ├── panorama_renderer.cc ├── panorama_renderer.h ├── panorama_vshader.glsl ├── polygon_renderer.cc ├── polygon_renderer.h ├── shaders.qrc ├── texture ├── kitchen.jpg ├── sheep.png ├── tile.png ├── tile2.png ├── tile3.jpg └── tile4.jpg ├── view_parameters.cc ├── view_parameters.h ├── viewer.cc └── viewer.pro /.gitignore: -------------------------------------------------------------------------------- 1 | *.cmake 2 | *.png 3 | *~ 4 | *# 5 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | cd pre_process; make 3 | cd main_process; make 4 | cd post_process; make 5 | cd viewer; qmake viewer.pro; make 6 | 7 | clean: 8 | cd pre_process; make clean 9 | cd main_process; make clean 10 | cd post_process; make clean 11 | cd viewer; make clean 12 | -------------------------------------------------------------------------------- /base/detection.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "detection.h" 4 | 5 | using namespace Eigen; 6 | using namespace std; 7 | 8 | namespace structured_indoor_modeling { 9 | 10 | istream& operator >>(istream& istr, Detection& detection) { 11 | string header,temp; 12 | istr >> header 13 | >> detection.panorama 14 | >> detection.us[0] >> detection.us[1] 15 | >> detection.vs[0] >> detection.vs[1]; 16 | int num_names; 17 | istr >> num_names; 18 | detection.names.resize(num_names); 19 | for (int i = 0; i < num_names; ++i) 20 | istr >> detection.names[i]; 21 | istr >> detection.score; 22 | 23 | if (header == "DETECTION_WITH_ICON" || header == "DETECTION_WITH_ICON_AND_POLYGON") { 24 | istr >> detection.room >> detection.object; 25 | for (int a = 0; a < 3; ++a) { 26 | for (int i = 0; i < 2; ++i) { 27 | istr >> detection.ranges[a][i]; 28 | } 29 | } 30 | } 31 | if(header == "DETECTION_WITH_ICON_AND_POLYGON"){ 32 | istr >> temp; 33 | int v_num, e_num; 34 | istr >> v_num >> e_num; 35 | detection.vlist.resize(v_num); 36 | detection.elist.resize(e_num); 37 | for(int vid=0; vid> detection.vlist[vid][0] >> detection.vlist[vid][1]; 39 | for(int eid=0; eid> detection.elist[eid][0] >> detection.elist[eid][1] >> detection.elist[eid][2]; 41 | } 42 | return istr; 43 | } 44 | 45 | ostream& operator <<(ostream& ostr, const Detection& detection) { 46 | ostr << "DETECTION_WITH_ICON_AND_POLYGON" << endl 47 | << detection.panorama << endl 48 | << detection.us[0] << ' ' << detection.us[1] << endl 49 | << detection.vs[0] << ' ' << detection.vs[1] << endl 50 | << (int)detection.names.size(); 51 | for (int i = 0; i < (int)detection.names.size(); ++i) 52 | ostr << ' ' << detection.names[i]; 53 | ostr << endl 54 | << detection.score << endl 55 | << detection.room << ' ' << detection.object << endl; 56 | for (int a = 0; a < 3; ++a) 57 | ostr << detection.ranges[a][0] << ' ' << detection.ranges[a][1] << endl; 58 | ostr << "POLYGON" <>(istream& istr, vector& detections) { 68 | string header; 69 | int num_detections; 70 | istr >> header >> num_detections; 71 | detections.clear(); 72 | detections.resize(num_detections); 73 | for (int d = 0; d < num_detections; ++d) 74 | istr >> detections[d]; 75 | 76 | return istr; 77 | } 78 | 79 | ostream& operator <<(ostream& ostr, const vector& detections) { 80 | ostr << "DETECTIONS" << endl 81 | << (int)detections.size() << endl; 82 | for (const auto& detection : detections) 83 | ostr << detection << endl; 84 | 85 | return ostr; 86 | } 87 | 88 | } // namespace structured_indoor_modeling 89 | 90 | -------------------------------------------------------------------------------- /base/detection.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | namespace structured_indoor_modeling { 10 | 11 | // Object detection is defined by the panorama image id and the 12 | // bounding box inside it. Bounding box coordinates (c0, c1, c2, c3) 13 | // are given by the ratio (u,v) whose values range from 0 to 1. A 14 | // bounding box may cross the right and left borders of an 15 | // image. Therefore, c1.u could be smaller than c0.u. 16 | // 17 | // To avoid redundancy, the bounding box coordinates are given by 4 18 | // numbers. The left and the right "u" values. The top and the bottom 19 | // "v" values. 20 | // 21 | // Panorama image 22 | // (0,0) (1.0) 23 | // +------------------------+ 24 | // | | 25 | // | | 26 | // | c0 c1 | 27 | // | +----+ | 28 | // | | | | 29 | // | +----+ | 30 | // | c3 c2 | 31 | // +------------------------+ 32 | // (0,1) (1,1) 33 | // 34 | // 35 | // 36 | struct Detection { 37 | Detection() { 38 | panorama = -1; 39 | us[0] = us[1] = 0.0; 40 | vs[0] = vs[1] = 0.0; 41 | score = 0.0; 42 | 43 | room = -1; 44 | object = -1; 45 | for (int a = 0; a < 3; ++a) 46 | ranges[a][0] = ranges[a][1] = 0.0; 47 | } 48 | 49 | //---------------------------------------------------------------------- 50 | // Input of the pipeline (or output of the RCNN). 51 | //---------------------------------------------------------------------- 52 | int panorama; 53 | // Left and right u values. us[0] could be smaller than us[1]. 54 | Eigen::Vector2d us; 55 | // Top and bottom v values. vs[0] is always saller than vs[1]. 56 | Eigen::Vector2d vs; 57 | 58 | // Output of the object detector. Name and the detection score. 59 | std::vector names; 60 | double score; 61 | 62 | // Associated icon information. 63 | int room; 64 | int object; 65 | // Bounding box in the floorplan coordinate. 66 | Eigen::Vector2d ranges[3]; 67 | 68 | //polygon representation 69 | std::vector vlist; 70 | std::vector elist; 71 | }; 72 | 73 | std::istream& operator >>(std::istream& istr, Detection& detection); 74 | std::ostream& operator <<(std::ostream& ostr, const Detection& detection); 75 | std::istream& operator >>(std::istream& istr, std::vector& detections); 76 | std::ostream& operator <<(std::ostream& ostr, const std::vector& detections); 77 | 78 | } // namespace structured_indoor_modeling 79 | -------------------------------------------------------------------------------- /base/geometry.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace structured_indoor_modeling { 6 | 7 | struct Triangle { 8 | // Vertex indices. 9 | Eigen::Vector3i indices; 10 | // Texture image index. 11 | int image_index; 12 | // UV coordinate. 13 | Eigen::Vector2d uvs[3]; 14 | }; 15 | 16 | inline std::istream& operator>>(std::istream& istr, Triangle& triangle) { 17 | for (int i = 0; i < 3; ++i) { 18 | istr >> triangle.indices[i]; 19 | } 20 | istr >> triangle.image_index; 21 | for (int i = 0; i < 3; ++i) { 22 | istr >> triangle.uvs[i][0] >> triangle.uvs[i][1]; 23 | } 24 | return istr; 25 | } 26 | 27 | inline std::ostream& operator<<(std::ostream& ostr, const Triangle& triangle) { 28 | for (int i = 0; i < 3; ++i) { 29 | ostr << triangle.indices[i] << ' '; 30 | } 31 | ostr << triangle.image_index << ' '; 32 | for (int i = 0; i < 3; ++i) { 33 | ostr << triangle.uvs[i][0] << ' ' << triangle.uvs[i][1] << ' '; 34 | } 35 | ostr << std::endl; 36 | return ostr; 37 | } 38 | 39 | // std::istream& operator>>(std::istream& istr, Triangle& triangle); 40 | // std::ostream& operator<<(std::ostream& ostr, const Triangle& triangle); 41 | 42 | } // namespace structured_indoor_modeling 43 | -------------------------------------------------------------------------------- /base/imageProcess/line.cc.cpp: -------------------------------------------------------------------------------- 1 | #include "line.h" 2 | 3 | using namespace std; 4 | using namespace ImageProcess; 5 | 6 | std::istream& operator>>(std::istream& istr, ImageProcess::Cline& line) { 7 | std::string header; 8 | istr >> header; 9 | istr >> line.m_abc >> line.m_endPoints[0] >> line.m_endPoints[1]; 10 | return istr; 11 | }; 12 | 13 | std::ostream& operator<<(std::ostream& ostr, const ImageProcess::Cline& line) { 14 | ostr << "LINE" << std::endl 15 | << line.m_abc << ' ' 16 | << line.m_endPoints[0] << ' ' 17 | << line.m_endPoints[1] << std::endl; 18 | return ostr; 19 | }; 20 | 21 | Vec3f Cline::grad2dir(const Vec3f& grad) { 22 | return Vec3f(grad[1], -grad[0], 0.0f); 23 | } 24 | -------------------------------------------------------------------------------- /base/imageProcess/line.h: -------------------------------------------------------------------------------- 1 | #ifndef IMAGEPROCESS_LINE_H 2 | #define IMAGEPROCESS_LINE_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | namespace ImageProcess { 10 | 11 | class Cline { 12 | public: 13 | Cline(void) { m_tmp = 0; }; 14 | virtual ~Cline() {}; 15 | 16 | // ax + by + c = 0. 17 | Vec3f m_abc; 18 | 19 | // Two end points 20 | Vec3f m_endPoints[2]; 21 | 22 | // Temporary 23 | float m_tmp; 24 | float m_tmp2; 25 | int m_itmp; 26 | 27 | static Vec3f grad2dir(const Vec3f& grad); 28 | protected: 29 | }; 30 | }; 31 | 32 | std::istream& operator>>(std::istream& istr, 33 | ImageProcess::Cline& line); 34 | std::ostream& operator<<(std::ostream& ostr, 35 | const ImageProcess::Cline& line); 36 | 37 | #endif //IMAGEPROCESS_LINE_H 38 | -------------------------------------------------------------------------------- /base/imageProcess/line3.h: -------------------------------------------------------------------------------- 1 | #ifndef IMAGEPROCESS_LINE3_H 2 | #define IMAGEPROCESS_LINE3_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include "line.h" 8 | 9 | namespace ImageProcess { 10 | 11 | class Cline3; 12 | typedef boost::shared_ptr Pline3; 13 | 14 | class Cline3 { 15 | public: 16 | Cline3(void); 17 | virtual ~Cline3(); 18 | 19 | inline Vec4f getCoord(const float x) const{ 20 | return m_origin + x * m_direction; 21 | }; 22 | 23 | static Vec4f unproject(const Vec3f& lhs, const Cline& rhs, 24 | const Image::Cphoto& photo0, 25 | const Image::Cphoto& photo1); 26 | 27 | static float getPos(const Vec3f& iorg, const Vec3f& idir, const Vec3f& icoord); 28 | 29 | static int isClose(const Cline3& lhs, const Cline3& rhs, 30 | const float threshold); 31 | 32 | //---------------------------------------------------------------------- 33 | void init(const std::vector& coords, 34 | const std::vector& ids); 35 | 36 | // Compute a projection of a coordinate onto a line (ignore ranges) 37 | Vec4f snap(const Vec4f& coord) const; 38 | 39 | // Set m_vimages 40 | void setVimages(void); 41 | 42 | // Set m_oranges 43 | void setOranges(void); 44 | 45 | //---------------------------------------------------------------------- 46 | // For octree 47 | int checkBox(const Vec3f& mmin, const Vec3f& mmax) const; 48 | float error(const Vec4f& coord) const; 49 | 50 | // Any point on a line is represented by m_origin + x * m_direction 51 | // Origin 52 | Vec4f m_origin; 53 | // Direction 54 | Vec4f m_direction; 55 | 56 | // Final range 57 | std::vector m_range; 58 | 59 | // For each image, inside ranges, and associated line ids 60 | std::vector > m_ranges; 61 | 62 | // A set of visible images (should be consistent with m_ranges) 63 | std::vector m_vimages; 64 | 65 | // Intersection between m_range and m_ranges 66 | // (startrange, lastrange, edgeid) 67 | std::vector > m_oranges; 68 | 69 | // Average color on both sides 70 | Vec3f m_color0; 71 | Vec3f m_color1; 72 | 73 | // How good the 3d line is (integration of visible images + range) 74 | float m_score; 75 | 76 | protected: 77 | }; 78 | }; 79 | 80 | std::istream& operator>>(std::istream& istr, 81 | ImageProcess::Cline3& line); 82 | std::ostream& operator<<(std::ostream& ostr, 83 | const ImageProcess::Cline3& line); 84 | 85 | #endif // IMAGEPROCESS_LINE3_H 86 | -------------------------------------------------------------------------------- /base/imageProcess/lineExtracter.h: -------------------------------------------------------------------------------- 1 | #ifndef IMAGEPROCESS_LINEEXTRACTER_H 2 | #define IMAGEPROCESS_LINEEXTRACTER_H 3 | 4 | #include 5 | #include "line.h" 6 | #include 7 | 8 | namespace ImageProcess { 9 | class ClineExtracter { 10 | public: 11 | ClineExtracter(void); 12 | virtual ~ClineExtracter(); 13 | 14 | void extract(Image::Cimage& eImage, const int level, const float minLen); 15 | 16 | void write(const std::string& file) const; 17 | 18 | std::vector m_lines; 19 | 20 | protected: 21 | void BDF(void); 22 | void smooth(void); 23 | void nonMaxSuppress(void); 24 | 25 | void extractLines(Image::Cimage& eImage); 26 | void extractLine(Image::Cimage& eImage, Cline& line); 27 | 28 | void getInOut(Image::Cimage& eImage, const Cline& line, 29 | std::vector& inout) const; 30 | 31 | void fillIn(const int scanwhich, std::vector& inout) const; 32 | 33 | void removeEdge(Image::Cimage& eImage, const Cline& line); 34 | 35 | int theta2cell(const float theta) const; 36 | float cell2theta(const int cell) const; 37 | int rho2cell(const float rho) const; 38 | float cell2rho(const int cell) const; 39 | 40 | // Votes 41 | std::vector > m_votes; 42 | // temporary 43 | std::vector > m_tmp; 44 | 45 | // Removed pixel map 46 | std::vector > > m_removed; 47 | 48 | // Units for the voting space 49 | float m_thetaUnit; 50 | float m_rhoUnit; 51 | // Width and height of the voting space (theta, rho) 52 | int m_thetaWidth; 53 | int m_rhoHeight; 54 | int m_rhoOffset; 55 | 56 | // level 57 | int m_level; 58 | // Width and height of the image 59 | int m_width; 60 | int m_height; 61 | Vec2f m_center; 62 | 63 | // Thresholds 64 | // Gap allowed in a line segment 65 | int m_gap; 66 | // Minimum length of a line segment allowed 67 | float m_minLen; 68 | 69 | 70 | 71 | //void squareFilter(Image::Cimage& eImage); 72 | void boxFilter(Image::Cimage& eImage); 73 | void gaussFilter(Image::Cimage& eImage); 74 | }; 75 | }; 76 | #endif // IMAGEPROCESS_LINEEXTRACTER_H 77 | -------------------------------------------------------------------------------- /base/imageProcess/lineOrganizer.cc.cpp: -------------------------------------------------------------------------------- 1 | #include "lineOrganizer.h" 2 | #include 3 | #include 4 | 5 | using namespace Image; 6 | using namespace ImageProcess; 7 | using namespace std; 8 | 9 | ClineOrganizer::ClineOrganizer(const Image::CphotoSet& photoSet) 10 | : m_photoSet(photoSet) { 11 | } 12 | 13 | ClineOrganizer::~ClineOrganizer() { 14 | } 15 | 16 | void ClineOrganizer::init(const int num, const std::string prefix, 17 | const int level) { 18 | m_num = num; 19 | m_prefix = prefix; 20 | m_level = level; 21 | 22 | m_lines.resize(m_num); 23 | for (int image = 0; image < m_num; ++image) { 24 | char buffer[1024]; 25 | sprintf(buffer, "%slines/%04d.line", m_prefix.c_str(), image); 26 | 27 | ifstream ifstr; 28 | ifstr.open(buffer); 29 | if (!ifstr.is_open()) { 30 | cerr << "No line file: " << buffer << endl; 31 | continue; 32 | } 33 | 34 | string header; 35 | int num; 36 | ifstr >> header >> num; 37 | m_lines[image].resize(num); 38 | for (int i = 0; i < num; ++i) 39 | ifstr >> m_lines[image][i]; 40 | 41 | ifstr.close(); 42 | } 43 | 44 | const float scale = 0x0001 << m_level; 45 | // Set limages 46 | m_limages.resize(m_num); 47 | for (int image = 0; image < m_num; ++image) { 48 | const int width = m_photoSet.getWidth(image, m_level); 49 | const int height = m_photoSet.getHeight(image, m_level); 50 | m_limages[image].resize(height); 51 | for (int y = 0; y < height; ++y) { 52 | m_limages[image][y].resize(width); 53 | for (int x = 0; x < width; ++x) 54 | m_limages[image][y][x] = 0; 55 | } 56 | 57 | for (int i = 0; i < (int)m_lines[image].size(); ++i) { 58 | const Vec3f p0 = m_lines[image][i].m_endPoints[0] / scale; 59 | const Vec3f p1 = m_lines[image][i].m_endPoints[1] / scale; 60 | Vec3f ray = p1 - p0; 61 | const float len = norm(ray); 62 | const int samplenum = max(2, (int)ceil(len)); 63 | const float unit = len / samplenum; 64 | ray = ray * (unit / len); 65 | Vec3f pos = p0; 66 | for (int j = 0; j <= samplenum; ++j) { 67 | const int ix = (int)floor(pos[0] + 0.5f); 68 | const int iy = (int)floor(pos[1] + 0.5f); 69 | if (ix < 1 || width - 1 <= ix || iy < 1 || height - 1 <= iy) 70 | continue; 71 | 72 | m_limages[image][iy][ix] = 1; 73 | /* 74 | m_limages[image][iy][ix - 1] = 1; 75 | m_limages[image][iy][ix + 1] = 1; 76 | m_limages[image][iy - 1][ix] = 1; 77 | m_limages[image][iy + 1][ix] = 1; 78 | */ 79 | pos += ray; 80 | } 81 | } 82 | 83 | /* 84 | ofstream ofstr; 85 | char buffer[1024]; 86 | sprintf(buffer, "l%04d.pgm", image); 87 | ofstr.open(buffer); 88 | ofstr << "P2" << endl 89 | << width << ' ' << height << endl 90 | << 255 << endl; 91 | for (int y = 0; y < height; ++y) 92 | for (int x = 0; x < width; ++x) 93 | if (m_limages[image][y][x]) 94 | ofstr << 255 << ' '; 95 | else 96 | ofstr << 0 << ' '; 97 | ofstr.close(); 98 | */ 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /base/imageProcess/lineOrganizer.h: -------------------------------------------------------------------------------- 1 | #ifndef IMAGEPROCESS_LINEORGANIZER_H 2 | #define IMAGEPROCESS_LINEORGANIZER_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | namespace ImageProcess { 10 | class ClineOrganizer { 11 | public: 12 | ClineOrganizer(const Image::CphotoSet& photoSet); 13 | virtual ~ClineOrganizer(); 14 | 15 | void init(const int num, const std::string prefix, 16 | const int level); 17 | 18 | std::vector > > m_limages; 19 | std::vector > m_lines; 20 | 21 | protected: 22 | int m_num; 23 | int m_level; 24 | std::string m_prefix; 25 | const Image::CphotoSet& m_photoSet; 26 | 27 | }; 28 | }; 29 | #endif // IMAGEPROCESS_LINEORGANIZER_H 30 | -------------------------------------------------------------------------------- /base/imageProcess/morphological_operation.h: -------------------------------------------------------------------------------- 1 | #ifndef IMAGE_PROCESS_MORPHOLOGICAL_OPERATION_H_ 2 | #define IMAGE_PROCESS_MORPHOLOGICAL_OPERATION_H_ 3 | 4 | #include 5 | 6 | namespace image_process { 7 | 8 | void Erode(const int width, const int height, const int kernel_width, 9 | std::vector* mask); 10 | 11 | void Erode(const int width, const int height, const int kernel_width, const int kernel_height, 12 | const std::vector& kernel, std::vector* mask); 13 | 14 | void Dilate(const int width, const int height, const int kernel_width, 15 | std::vector* mask); 16 | 17 | void Dilate(const int width, const int height, const int kernel_width, const int kernel_height, 18 | const std::vector& kernel, std::vector* mask); 19 | 20 | void Open(const int width, const int height, const int kernel_width, 21 | std::vector* mask); 22 | 23 | void Open(const int width, const int height, const int kernel_width, const int kernel_height, 24 | const std::vector& kernel, std::vector* mask); 25 | 26 | void Close(const int width, const int height, const int kernel_width, 27 | std::vector* mask); 28 | 29 | void Close(const int width, const int height, const int kernel_width, const int kernel_height, 30 | const std::vector& kernel, std::vector* mask); 31 | 32 | 33 | } // namespace image_process 34 | 35 | #endif // IMAGE_PROCESS_MORPHOLOGICAL_OPERATION_H_ 36 | -------------------------------------------------------------------------------- /base/imageProcess/patch2d.cc.cpp: -------------------------------------------------------------------------------- 1 | #include "patch2d.h" 2 | #include 3 | 4 | using namespace ImageProcess; 5 | using namespace std; 6 | 7 | Cpatch2d::Cpatch2d(void) { 8 | m_center = Vec2f(); 9 | m_xaxis = Vec2f(1.0f, 0.0f); 10 | m_yaxis = Vec2f(0.0f, 1.0f); 11 | m_score = 2.0f; 12 | 13 | m_id = -1; 14 | m_num = -1; 15 | } 16 | 17 | Cpatch2d::~Cpatch2d() { 18 | } 19 | 20 | void Cpatch2d::lift(float& z, Vec3f& r0, Vec3f& r1) const{ 21 | lift(m_xaxis, m_yaxis, z, r0, r1); 22 | } 23 | 24 | // A is multiplied from the left hand side 25 | void Cpatch2d::lift(const Mat2f& A, float& z, 26 | Vec3f& r0, Vec3f& r1) const { 27 | lift(A * m_xaxis, A * m_yaxis, z, r0, r1); 28 | } 29 | 30 | void Cpatch2d::lift(const Vec2f& xaxis, const Vec2f& yaxis, 31 | float& z, Vec3f& r0, Vec3f& r1) { 32 | // Frobeneous norm 33 | const float AF2 = norm2(xaxis) + norm2(yaxis); 34 | const float AF4 = AF2 * AF2; 35 | const float det = xaxis[0] * yaxis[1] - xaxis[1] * yaxis[0]; 36 | const float det2 = det * det; 37 | 38 | // b_4ac is guaranteed to be non-negative. 39 | const float b_4ac = max(0.0f, AF4 - 4 * det2); 40 | z = sqrt(max(0.0f, (AF2 - sqrt(b_4ac)) / (2 * det2))); 41 | 42 | r0[0] = xaxis[0] * z; r0[1] = xaxis[1] * z; 43 | r0[2] = sqrt(max(0.0f, 1.0f - (r0[0] * r0[0] + r0[1] * r0[1]))); 44 | 45 | r1[0] = yaxis[0] * z; r1[1] = yaxis[1] * z; 46 | r1[2] = sqrt(max(0.0f, 1.0f - (r1[0] * r1[0] + r1[1] * r1[1]))); 47 | 48 | // Make sure that the dot product between r0 and r1 is 0. 49 | //???????? 50 | if (r0[0] * r1[0] + r0[1] * r1[1] > 0.0) 51 | //r0[2] = -r0[2]; 52 | r1[2] = -r1[2]; 53 | 54 | } 55 | 56 | std::istream& ImageProcess::operator>>(std::istream& istr, Cpatch2d& rhs) { 57 | string header; 58 | istr >> header; 59 | if (header != "PATCH2D") { 60 | cerr << "Header is not PATCH2D: " << header << endl; 61 | exit (1); 62 | } 63 | istr >> rhs.m_center >> rhs.m_xaxis >> rhs.m_yaxis >> rhs.m_score; 64 | return istr; 65 | } 66 | 67 | std::ostream& ImageProcess::operator<<(std::ostream& ostr, Cpatch2d& rhs) { 68 | ostr << "PATCH2D" << endl 69 | << rhs.m_center << endl 70 | << rhs.m_xaxis << ' ' << rhs.m_yaxis << ' ' << rhs.m_score << endl; 71 | return ostr; 72 | } 73 | -------------------------------------------------------------------------------- /base/imageProcess/patch2d.h: -------------------------------------------------------------------------------- 1 | #ifndef IMAGEPROCESS_PATCH2D_H 2 | #define IMAGEPROCESS_PATCH2D_H 3 | 4 | #include "../numeric/vec3.h" 5 | #include "../numeric/mat2.h" 6 | #include 7 | 8 | namespace ImageProcess { 9 | 10 | class Cpatch2d { 11 | public: 12 | Cpatch2d(void); 13 | virtual ~Cpatch2d(); 14 | 15 | // Get 2d global coordinate from a local one 16 | inline Vec2f getGlobal(const Vec2f& local) const; 17 | // Get 2d local coordinate from a global one 18 | inline Vec2f getLocal(const Vec2f& global) const; 19 | 20 | // center 21 | Vec2f m_center; 22 | // x and y axes 23 | Vec2f m_xaxis; 24 | Vec2f m_yaxis; 25 | 26 | // score 27 | // 2.0 means failure 28 | float m_score; 29 | 30 | // id 31 | int m_id; 32 | // number of neighbors 33 | int m_num; 34 | // speed 35 | float m_speed; 36 | 37 | inline int isTracked(void) const{ 38 | if (m_score == 2.0) 39 | return 0; 40 | else 41 | return 1; 42 | }; 43 | 44 | inline float det(void) const{ 45 | return m_xaxis[0] * m_yaxis[1] - m_xaxis[1] * m_yaxis[0]; 46 | }; 47 | 48 | // 2-fold ambiguity is obtained by flipping the sign of the third 49 | // elements of r0 and r1, respectively. 50 | void lift(float& z, Vec3f& r0, Vec3f& r1) const; 51 | // A is multiplied from the left hand side 52 | void lift(const Mat2f& A, float& z, Vec3f& r0, Vec3f& r1) const; 53 | protected: 54 | static void lift(const Vec2f& xaxis, const Vec2f& yaxis, 55 | float& z, Vec3f& r0, Vec3f& r1); 56 | }; 57 | 58 | std::istream& operator>>(std::istream& istr, Cpatch2d& rhs); 59 | std::ostream& operator<<(std::ostream& ostr, Cpatch2d& rhs); 60 | 61 | Vec2f Cpatch2d::getGlobal(const Vec2f& local) const { 62 | return local[0] * m_xaxis + local[1] * m_yaxis + m_center; 63 | }; 64 | 65 | Vec2f Cpatch2d::getLocal(const Vec2f& global) const { 66 | const Vec2f ans = global - m_center; 67 | Mat2f mat(m_xaxis[0], m_yaxis[0], m_xaxis[1], m_yaxis[1]); 68 | Mat2f imat; 69 | invert(imat, mat); 70 | return imat * ans; 71 | }; 72 | 73 | }; 74 | 75 | #endif // IMAGEPROCESS_PATCH2D_H 76 | 77 | -------------------------------------------------------------------------------- /base/imageProcess/patch2dTrack.cc.cpp: -------------------------------------------------------------------------------- 1 | #include "patch2dTrack.h" 2 | 3 | using namespace std; 4 | using namespace ImageProcess; 5 | 6 | Cpatch2dTrack::Cpatch2dTrack(void) { 7 | } 8 | 9 | Cpatch2dTrack::~Cpatch2dTrack() { 10 | } 11 | 12 | void Cpatch2dTrack::resize(const int fnum) { 13 | m_fnum = fnum; 14 | m_patch2ds.resize(m_fnum); 15 | } 16 | 17 | std::istream& ImageProcess::operator>>(std::istream& istr, Cpatch2dTrack& rhs) { 18 | string header; 19 | istr >> header; 20 | if (header != "PATCH2DTRACK") { 21 | cerr << "Header is not PATCH2DTRACK: " << header << endl; 22 | exit (1); 23 | } 24 | 25 | int fnum; 26 | istr >> fnum; 27 | rhs.resize(fnum); 28 | 29 | for (int f = 0; f < fnum; ++f) 30 | istr >> rhs.m_patch2ds[f]; 31 | return istr; 32 | } 33 | 34 | std::ostream& ImageProcess::operator<<(std::ostream& ostr, Cpatch2dTrack& rhs) { 35 | ostr << "PATCH2DTRACK" << endl 36 | << (int)rhs.m_patch2ds.size() << endl; 37 | for (int f = 0; f < (int)rhs.m_patch2ds.size(); ++f) 38 | ostr << rhs.m_patch2ds[f] << flush; 39 | return ostr; 40 | } 41 | -------------------------------------------------------------------------------- /base/imageProcess/patch2dTrack.h: -------------------------------------------------------------------------------- 1 | #ifndef IMAGEPROCESS_PATCH2DTRACK_H 2 | #define IMAGEPROCESS_PATCH2DTRACK_H 3 | 4 | #include 5 | #include 6 | #include "../numeric/vec2.h" 7 | #include "../numeric/mat2.h" 8 | #include "patch2d.h" 9 | 10 | namespace ImageProcess { 11 | 12 | class Cpatch2dTrack { 13 | public: 14 | Cpatch2dTrack(void); 15 | virtual ~Cpatch2dTrack(); 16 | 17 | void resize(const int fnum); 18 | 19 | // Get 2d global coordinate from a local one 20 | inline Vec2f getGlobal(const int frame, const Vec2f& local) const; 21 | // Get 2d local coordinate from a global one 22 | inline Vec2f getLocal(const int frame, const Vec2f& global) const; 23 | 24 | std::vector m_patch2ds; 25 | 26 | int m_fnum; 27 | 28 | protected: 29 | 30 | }; 31 | 32 | std::istream& operator>>(std::istream& istr, Cpatch2dTrack& rhs); 33 | std::ostream& operator<<(std::ostream& ostr, Cpatch2dTrack& rhs); 34 | 35 | Vec2f Cpatch2dTrack::getGlobal(const int frame, const Vec2f& local) const { 36 | return m_patch2ds[frame].getGlobal(local); 37 | }; 38 | 39 | Vec2f Cpatch2dTrack::getLocal(const int frame, const Vec2f& global) const { 40 | return m_patch2ds[frame].getLocal(global); 41 | }; 42 | 43 | }; 44 | 45 | #endif // IMAGEPROCESS_PATCH2DTRACK_H 46 | -------------------------------------------------------------------------------- /base/imageProcess/patch2dTracker.h: -------------------------------------------------------------------------------- 1 | #ifndef IMAGEPROCESS_PATCH2DTRACKER_H 2 | #define IMAGEPROCESS_PATCH2DTRACKER_H 3 | 4 | #include 5 | #include 6 | #include "patch2dTrack.h" 7 | #include "patch2dOptimizer.h" 8 | #include "../image/movie.h" 9 | 10 | namespace ImageProcess { 11 | 12 | class Cpatch2dTracker { 13 | public: 14 | Cpatch2dTracker(void); 15 | virtual ~Cpatch2dTracker(); 16 | 17 | virtual void init(const std::string prefix, 18 | const int firstFrame, const int lastFrame, 19 | const int refFrame, const int maxLevel, 20 | const int margin, const int usedetect, 21 | const float inccThreshold); 22 | 23 | virtual void run(void); 24 | // Filter out tracks which success rate is below passratio. 25 | virtual void filter(const float passratio = 1.0f); 26 | void write(void); 27 | 28 | inline Cpatch2d& getPatch2d(const int index, 29 | const int frame) { 30 | return m_patch2dTracks[index].m_patch2ds[frame]; 31 | } 32 | 33 | inline const Cpatch2d& getPatch2d(const int index, 34 | const int frame) const { 35 | return m_patch2dTracks[index].m_patch2ds[frame]; 36 | } 37 | 38 | protected: 39 | void optimize(const int id, 40 | const Cpatch2d& pre, Cpatch2d& cur, 41 | const Image::Cimage& preimage, 42 | const Image::Cimage& curimage); 43 | 44 | void readKey(const std::string file); 45 | 46 | void tighten(void); 47 | 48 | // A set of tracks 49 | std::vector m_patch2dTracks; 50 | // Affine tracker engine 51 | Cpatch2dOptimizer m_patch2dOptimizer; 52 | // Image sequence 53 | Image::Cmovie m_movie; 54 | 55 | // prefix to the data folder 56 | std::string m_prefix; 57 | 58 | // threshold 59 | float m_inccThreshold; 60 | 61 | // how many search area 62 | int m_margin; 63 | 64 | // current frame num 65 | int m_fnum; 66 | // frame number 67 | int m_firstFrame; 68 | int m_lastFrame; 69 | int m_refFrame; 70 | // max level 71 | int m_maxLevel; 72 | // half size 73 | int m_halfsize; 74 | 75 | // Threads 76 | pthread_rwlock_t m_rwlock; 77 | int m_count; 78 | 79 | void runThread(void); 80 | static void* runThreadTmp(void*arg); 81 | 82 | friend std::istream& operator>>(std::istream& istr, Cpatch2dTracker& rhs); 83 | friend std::ostream& operator<<(std::ostream& ostr, Cpatch2dTracker& rhs); 84 | }; 85 | 86 | std::istream& operator>>(std::istream& istr, Cpatch2dTracker& rhs); 87 | std::ostream& operator<<(std::ostream& ostr, Cpatch2dTracker& rhs); 88 | 89 | }; 90 | 91 | #endif //IMAGEPROCESS_PATCH2DTRACKER_H 92 | -------------------------------------------------------------------------------- /base/indoor_polygon.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include "geometry.h" 7 | 8 | namespace structured_indoor_modeling { 9 | 10 | struct Segment { 11 | enum Type { 12 | FLOOR, 13 | CEILING, 14 | WALL, 15 | DOOR 16 | }; 17 | 18 | enum Normal { 19 | PositiveX, 20 | NegativeX, 21 | PositiveY, 22 | NegativeY, 23 | PositiveZ, 24 | NegativeZ, 25 | Other 26 | }; 27 | 28 | Type type; 29 | // Room number. 30 | int floor_info; 31 | int ceiling_info; 32 | // For wall (room, wall). 33 | Eigen::Vector2i wall_info; 34 | // For door (room0, wall0, room1, wall1). 35 | Eigen::Vector4i door_info; 36 | 37 | Normal normal; 38 | std::vector vertices; 39 | std::vector triangles; 40 | }; 41 | 42 | class IndoorPolygon { 43 | public: 44 | IndoorPolygon(); 45 | IndoorPolygon(const std::string& filename); 46 | 47 | void InitFromBinaryPly(const std::string& filename); 48 | void InitFromAsciiPly(const std::string& filename); 49 | 50 | int GetNumSegments() const { return segments.size(); } 51 | const Segment& GetSegment(const int segment) const { return segments[segment]; } 52 | Segment& GetSegment(const int segment) { return segments[segment]; } 53 | 54 | Eigen::Vector3d ManhattanToGlobal(const Eigen::Vector3d& manhattan) const; 55 | Eigen::Vector3d GlobalToManhattan(const Eigen::Vector3d& global) const; 56 | 57 | private: 58 | void InitFromRawMeshData(const std::vector& vertices, 59 | const std::vector& triangles); 60 | 61 | Eigen::Matrix4d manhattan_to_global; 62 | Eigen::Matrix4d global_to_manhattan; 63 | std::vector segments; 64 | 65 | friend std::istream& operator>>(std::istream& istr, IndoorPolygon& indoor_polygon); 66 | friend std::ostream& operator<<(std::ostream& ostr, const IndoorPolygon& indoor_polygon); 67 | }; 68 | 69 | std::istream& operator>>(std::istream& istr, Segment& segment); 70 | std::ostream& operator<<(std::ostream& ostr, const Segment& segment); 71 | std::istream& operator>>(std::istream& istr, IndoorPolygon& indoor_polygon); 72 | std::ostream& operator<<(std::ostream& ostr, const IndoorPolygon& indoor_polygon); 73 | 74 | } // namespace structured_indoor_modeling 75 | -------------------------------------------------------------------------------- /base/kdtree/KDtree.h: -------------------------------------------------------------------------------- 1 | #ifndef KDTREE_H 2 | #define KDTREE_H 3 | /* 4 | Szymon Rusinkiewicz 5 | Princeton University 6 | 7 | KDtree.h 8 | A K-D tree for points, with limited capabilities (find nearest point to 9 | a given point, or to a ray). 10 | 11 | Note that in order to be generic, this *doesn't* use Vecs and the like... 12 | */ 13 | 14 | #include 15 | 16 | class KDtree { 17 | private: 18 | class Node; 19 | Node *root; 20 | void build(const float *ptlist, int n); 21 | 22 | public: 23 | // Compatibility function for closest-compatible-point searches 24 | struct CompatFunc 25 | { 26 | virtual bool operator () (const float *p) const = 0; 27 | virtual ~CompatFunc() {} // To make the compiler shut up 28 | }; 29 | 30 | // Constructor from an array of points 31 | KDtree(const float *ptlist, int n) 32 | { build(ptlist, n); } 33 | 34 | // Constructor from a vector of points 35 | template KDtree(const std::vector &v) 36 | { build((const float *) &v[0], v.size() / 3); } 37 | 38 | // Destructor - recursively frees the tree 39 | ~KDtree(); 40 | 41 | // The queries: returns closest point to a point or a ray, 42 | // provided it's within sqrt(maxdist2) and is compatible 43 | const float *closest_to_pt(const float *p, 44 | float maxdist2 = 0.0f, 45 | const CompatFunc *iscompat = NULL) const; 46 | const float *closest_to_ray(const float *p, const float *dir, 47 | float maxdist2 = 0.0f, 48 | const CompatFunc *iscompat = NULL) const; 49 | 50 | // Find the k nearest neighbors 51 | void find_k_closest_to_pt(std::vector &knn, 52 | int k, 53 | const float *p, 54 | float maxdist2 = 0.0f, 55 | const CompatFunc *iscompat = NULL) const; 56 | }; 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /base/kdtree/mempool.h: -------------------------------------------------------------------------------- 1 | #ifndef MEMPOOL_H 2 | #define MEMPOOL_H 3 | /* 4 | Szymon Rusinkiewicz 5 | Princeton University 6 | 7 | mempool.h 8 | Replacement memory management for a class using a memory pool. 9 | 10 | Sample usage: 11 | class MyClass { 12 | private: 13 | static PoolAlloc memPool; 14 | public: 15 | void *operator new(size_t n) { return memPool.alloc(n); } 16 | void operator delete(void *p, size_t n) { memPool.free(p,n); } 17 | // ... 18 | }; 19 | 20 | PoolAlloc MyClass::memPool(sizeof(MyClass)); 21 | 22 | Does *no* error checking. 23 | Make sure sizeof(MyClass) is larger than sizeof(void *). 24 | Based on the description of the Pool class in _Effective C++_ by Scott Meyers. 25 | */ 26 | 27 | #include 28 | #include 29 | 30 | #define POOL_MEMBLOCK 4088 31 | 32 | 33 | class PoolAlloc { 34 | private: 35 | size_t itemsize; 36 | void *freelist; 37 | void grow_freelist() 38 | { 39 | size_t n = POOL_MEMBLOCK / itemsize; 40 | freelist = ::operator new(n * itemsize); 41 | for (size_t i = 0; i < n-1; i++) 42 | *(void **)((char *)freelist + itemsize*i) = 43 | (char *)freelist + itemsize*(i+1); 44 | *(void **)((char *)freelist + itemsize*(n-1)) = 0; 45 | } 46 | 47 | public: 48 | PoolAlloc(size_t size) : itemsize(size), freelist(0) {} 49 | void *alloc(size_t n) 50 | { 51 | if (n != itemsize) 52 | return ::operator new(n); 53 | if (!freelist) 54 | grow_freelist(); 55 | void *next = freelist; 56 | freelist = *(void **)next; 57 | return next; 58 | } 59 | void free(void *p, size_t n) 60 | { 61 | if (!p) 62 | return; 63 | else if (n != itemsize) 64 | ::operator delete(p); 65 | else { 66 | *(void **)p = freelist; 67 | freelist = p; 68 | } 69 | } 70 | void sort_freelist() 71 | { 72 | if (!freelist) 73 | return; 74 | std::vector v; 75 | void *p; 76 | for (p = freelist; *(void **)p; p = *(void **)p) 77 | v.push_back(p); 78 | std::sort(v.begin(), v.end()); 79 | p = freelist = v[0]; 80 | for (size_t i = 1; i < v.size(); i++) { 81 | *(void **)p = v[i]; 82 | p = *(void **)p; 83 | } 84 | *(void **)p = NULL; 85 | } 86 | }; 87 | 88 | #endif 89 | -------------------------------------------------------------------------------- /base/mrf/BP-S.h: -------------------------------------------------------------------------------- 1 | #ifndef __BPS_H__ 2 | #define __BPS_H__ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "mrf.h" 9 | 10 | 11 | class BPS : public MRF{ 12 | public: 13 | typedef CostVal REAL; 14 | 15 | BPS(int width, int height, int nLabels, EnergyFunction *eng); 16 | BPS(int nPixels, int nLabels,EnergyFunction *eng); 17 | ~BPS(); 18 | void setNeighbors(int /*pix1*/, int /*pix2*/, CostVal /*weight*/){printf("Not implemented"); exit(1);} 19 | Label getLabel(int pixel){return(m_answer[pixel]);}; 20 | void setLabel(int pixel,Label label){m_answer[pixel] = label;}; 21 | Label* getAnswerPtr(){return(m_answer);}; 22 | void clearAnswer(); 23 | void setParameters(int /*numParam*/, void * /*param*/){printf("No optional parameters to set"); exit(1);} 24 | EnergyVal smoothnessEnergy(); 25 | EnergyVal dataEnergy(); 26 | 27 | protected: 28 | void setData(DataCostFn dcost); 29 | void setData(CostVal* data); 30 | void setSmoothness(SmoothCostGeneralFn cost); 31 | void setSmoothness(CostVal* V); 32 | void setSmoothness(int smoothExp,CostVal smoothMax, CostVal lambda); 33 | void setCues(CostVal* hCue, CostVal* vCue); 34 | void Allocate(); 35 | void initializeAlg(); 36 | void optimizeAlg(int nIterations); 37 | 38 | private: 39 | 40 | enum 41 | { 42 | NONE, 43 | L1, 44 | L2, 45 | FIXED_MATRIX, 46 | GENERAL, 47 | BINARY, 48 | } m_type; 49 | 50 | CostVal m_smoothMax; // used only if 51 | CostVal m_lambda; // m_type == L1 or m_type == L2 52 | 53 | Label *m_answer; 54 | CostVal *m_V; // points to array of size nLabels^2 (if type==FIXED_MATRIX) or of size nEdges*nLabels^2 (if type==GENERAL) 55 | CostVal *m_D; 56 | CostVal *m_DBinary; // valid if type == BINARY 57 | CostVal *m_horzWeights; 58 | CostVal *m_vertWeights; 59 | CostVal *m_horzWeightsBinary; 60 | CostVal *m_vertWeightsBinary; 61 | DataCostFn m_dataFn; 62 | SmoothCostGeneralFn m_smoothFn; 63 | bool m_needToFreeV; 64 | bool m_needToFreeD; 65 | 66 | REAL* m_messages; // size of one message: N = 1 if m_type == BINARY, N = K otherwise 67 | // message between edges (x,y)-(x+1,y): m_messages+(2*x+2*y*m_width)*N 68 | // message between edges (x,y)-(x,y+1): m_messages+(2*x+2*y*m_width+1)*N 69 | 70 | int m_messageArraySizeInBytes; 71 | 72 | void optimize_GRID_L1(int nIterations); 73 | void optimize_GRID_L2(int nIterations); 74 | void optimize_GRID_FIXED_MATRIX(int nIterations); 75 | void optimize_GRID_GENERAL(int nIterations); 76 | void optimize_GRID_BINARY(int nIterations); 77 | }; 78 | 79 | #endif /* __BPS_H__ */ 80 | -------------------------------------------------------------------------------- /base/mrf/ICM.h: -------------------------------------------------------------------------------- 1 | #ifndef __ICM_H__ 2 | #define __ICM_H__ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "mrf.h" 9 | #include "LinkedBlockList.h" 10 | 11 | 12 | class ICM : public MRF{ 13 | public: 14 | ICM(int width, int height, int nLabels, EnergyFunction *eng); 15 | ICM(int nPixels, int nLabels,EnergyFunction *eng); 16 | ~ICM(); 17 | void setNeighbors(int pix1, int pix2, CostVal weight); 18 | Label getLabel(int pixel){return(m_answer[pixel]);}; 19 | void setLabel(int pixel,Label label){m_answer[pixel] = label;}; 20 | Label* getAnswerPtr(){return(m_answer);}; 21 | void clearAnswer(); 22 | void setParameters(int /*numParam*/, void * /*param*/){printf("No optional parameters to set"); exit(1);} 23 | EnergyVal smoothnessEnergy(); 24 | EnergyVal dataEnergy(); 25 | 26 | protected: 27 | void setData(DataCostFn dcost); 28 | void setData(CostVal* data); 29 | void setSmoothness(SmoothCostGeneralFn cost); 30 | void setSmoothness(CostVal* V); 31 | void setSmoothness(int smoothExp,CostVal smoothMax, CostVal lambda); 32 | void setCues(CostVal* hCue, CostVal* vCue); 33 | void initializeAlg(); 34 | void optimizeAlg(int nIterations); 35 | 36 | private: 37 | Label *m_answer; 38 | CostVal *m_V; 39 | CostVal *m_D; 40 | CostVal *m_horizWeights; 41 | CostVal *m_vertWeights; 42 | DataCostFn m_dataFn; 43 | SmoothCostGeneralFn m_smoothFn; 44 | bool m_needToFreeV; 45 | 46 | typedef struct NeighborStruct{ 47 | int to_node; 48 | CostVal weight; 49 | } Neighbor; 50 | 51 | LinkedBlockList *m_neighbors; 52 | }; 53 | 54 | 55 | #endif /* __ICM_H__ */ 56 | 57 | 58 | -------------------------------------------------------------------------------- /base/mrf/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 unsigned 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 | -------------------------------------------------------------------------------- /base/mrf/MaxProdBP.h: -------------------------------------------------------------------------------- 1 | #ifndef __MAXPRODBP_H__ 2 | #define __MAXPRODBP_H__ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "mrf.h" 9 | #include "LinkedBlockList.h" 10 | #include "regions-new.h" 11 | 12 | #define FloatType float 13 | #define FLOATTYPE float 14 | class MaxProdBP; 15 | 16 | class MaxProdBP : public MRF{ 17 | public: 18 | MaxProdBP(int width, int height, int nLabels, EnergyFunction *eng); 19 | MaxProdBP(int nPixels, int nLabels,EnergyFunction *eng); 20 | ~MaxProdBP(); 21 | void setNeighbors(int pix1, int pix2, CostVal weight); 22 | Label getLabel(int pixel){return(m_answer[pixel]);}; 23 | void setLabel(int pixel,Label label){m_answer[pixel] = label;}; 24 | Label* getAnswerPtr(){return(m_answer);}; 25 | void clearAnswer(); 26 | void setParameters(int , void *){printf("No optional parameters to set");} 27 | EnergyVal smoothnessEnergy(); 28 | EnergyVal dataEnergy(); 29 | EnergyFunction *getEnergyFunction(); 30 | int getWidth(); 31 | int getHeight(); 32 | FLOATTYPE *getScratchMatrix(); 33 | int getNLabels(); 34 | bool varWeights(); 35 | void setExpScale(int expScale); 36 | friend void getPsiMat(OneNodeCluster &cluster, FLOATTYPE *&destMatrix, 37 | int r, int c, MaxProdBP *mrf, int direction, FLOATTYPE &var_weight); 38 | 39 | InputType getSmoothType(); 40 | FLOATTYPE getExpV(int i); 41 | FLOATTYPE *getExpV(); 42 | 43 | CostVal getHorizWeight(int r, int c); 44 | CostVal getVertWeight(int r, int c); 45 | 46 | 47 | CostVal m_lambda; 48 | CostVal m_smoothMax; 49 | int m_smoothExp; 50 | 51 | enum //Borrowed from BP-S.h by vnk 52 | { 53 | NONE, 54 | L1, 55 | L2, 56 | FIXED_MATRIX, 57 | GENERAL, 58 | BINARY, 59 | } m_type; 60 | 61 | protected: 62 | void setData(DataCostFn dcost); 63 | void setData(CostVal* data); 64 | void setSmoothness(SmoothCostGeneralFn cost); 65 | void setSmoothness(CostVal* V); 66 | void setSmoothness(int smoothExp,CostVal smoothMax, CostVal lambda); 67 | void setCues(CostVal* hCue, CostVal* vCue); 68 | void initializeAlg(); 69 | void BPinitializeAlg(); 70 | void optimizeAlg(int nIterations); 71 | 72 | private: 73 | Label *m_answer; 74 | CostVal *m_V; 75 | CostVal *m_D; 76 | CostVal *m_horizWeights; 77 | CostVal *m_vertWeights; 78 | FLOATTYPE m_exp_scale; 79 | DataCostFn m_dataFn; 80 | SmoothCostGeneralFn m_smoothFn; 81 | bool m_needToFreeV; 82 | FLOATTYPE *m_scratchMatrix; 83 | FLOATTYPE *m_ExpData; 84 | FLOATTYPE *m_message_chunk; 85 | OneNodeCluster *nodeArray; 86 | typedef struct NeighborStruct { 87 | int to_node; 88 | CostVal weight; 89 | } Neighbor; 90 | 91 | LinkedBlockList *m_neighbors; 92 | }; 93 | 94 | 95 | #endif /* __ICM_H__ */ 96 | 97 | 98 | -------------------------------------------------------------------------------- /base/mrf/TRW-S.h: -------------------------------------------------------------------------------- 1 | #ifndef __TRWS_H__ 2 | #define __TRWS_H__ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "mrf.h" 9 | 10 | 11 | class TRWS : public MRF{ 12 | public: 13 | typedef double REAL; 14 | 15 | TRWS(int width, int height, int nLabels, EnergyFunction *eng); 16 | TRWS(int nPixels, int nLabels,EnergyFunction *eng); 17 | ~TRWS(); 18 | void setNeighbors(int /*pix1*/, int /*pix2*/, CostVal /*weight*/){printf("Not implemented"); exit(1);} 19 | Label getLabel(int pixel){return(m_answer[pixel]);}; 20 | void setLabel(int pixel,Label label){m_answer[pixel] = label;}; 21 | Label* getAnswerPtr(){return(m_answer);}; 22 | void clearAnswer(); 23 | void setParameters(int /*numParam*/, void * /*param*/){printf("No optional parameters to set"); exit(1);} 24 | EnergyVal smoothnessEnergy(); 25 | EnergyVal dataEnergy(); 26 | double lowerBound() { return (double)m_lowerBound; } 27 | 28 | // For general smoothness functions, this code tries to cache all function values in an array 29 | // for efficiency. To prevent this, call the following function before calling initialize(): 30 | void dontCacheSmoothnessCosts() {m_allocateArrayForSmoothnessCostFn = false;} 31 | 32 | protected: 33 | void setData(DataCostFn dcost); 34 | void setData(CostVal* data); 35 | void setSmoothness(SmoothCostGeneralFn cost); 36 | void setSmoothness(CostVal* V); 37 | void setSmoothness(int smoothExp,CostVal smoothMax, CostVal lambda); 38 | void setCues(CostVal* hCue, CostVal* vCue); 39 | void Allocate(); 40 | void initializeAlg(); 41 | void optimizeAlg(int nIterations); 42 | 43 | private: 44 | 45 | enum 46 | { 47 | NONE, 48 | L1, 49 | L2, 50 | FIXED_MATRIX, 51 | GENERAL, 52 | BINARY, 53 | } m_type; 54 | 55 | CostVal m_smoothMax; // used only if 56 | CostVal m_lambda; // m_type == L1 or m_type == L2 57 | 58 | Label *m_answer; 59 | CostVal *m_V; // points to array of size nLabels^2 (if type==FIXED_MATRIX) or of size nEdges*nLabels^2 (if type==GENERAL) 60 | CostVal *m_D; 61 | CostVal *m_DBinary; // valid if type == BINARY 62 | CostVal *m_horzWeights; 63 | CostVal *m_vertWeights; 64 | CostVal *m_horzWeightsBinary; 65 | CostVal *m_vertWeightsBinary; 66 | DataCostFn m_dataFn; 67 | SmoothCostGeneralFn m_smoothFn; 68 | bool m_needToFreeV; 69 | bool m_needToFreeD; 70 | 71 | REAL* m_messages; // size of one message: N = 1 if m_type == BINARY, N = K otherwise 72 | // message between edges (x,y)-(x+1,y): m_messages+(2*x+2*y*m_width)*N 73 | // message between edges (x,y)-(x,y+1): m_messages+(2*x+2*y*m_width+1)*N 74 | 75 | int m_messageArraySizeInBytes; 76 | 77 | REAL m_lowerBound; 78 | 79 | void optimize_GRID_L1(int nIterations); 80 | void optimize_GRID_L2(int nIterations); 81 | void optimize_GRID_FIXED_MATRIX(int nIterations); 82 | void optimize_GRID_GENERAL(int nIterations); 83 | void optimize_GRID_BINARY(int nIterations); 84 | }; 85 | 86 | #endif /* __TRWS_H__ */ 87 | -------------------------------------------------------------------------------- /base/mrf/regions-new.h: -------------------------------------------------------------------------------- 1 | // (C) 2002 Marshall Tappen, MIT AI Lab 2 | 3 | #ifndef _reg_h 4 | #define _reg_h 5 | 6 | #define FLOATTYPE float 7 | #define UP 0 8 | #define DOWN 1 9 | #define LEFT 2 10 | #define RIGHT 3 11 | #include "MaxProdBP.h" 12 | 13 | class MaxProdBP; 14 | class OneNodeCluster 15 | { 16 | public: 17 | OneNodeCluster(); 18 | 19 | //static const int UP = 0, DOWN = 1, LEFT = 2, RIGHT = 3; 20 | static int numStates; 21 | 22 | FLOATTYPE *receivedMsgs[4], 23 | *nextRoundReceivedMsgs[4], 24 | *localEv; 25 | 26 | 27 | // FLOATTYPE *psi[4]; 28 | void ComputeMsgRight(FLOATTYPE *msgDest, int r, int c, MaxProdBP *mrf); 29 | void ComputeMsgUp(FLOATTYPE *msgDest, int r, int c, MaxProdBP *mrf); 30 | 31 | void ComputeMsgLeft(FLOATTYPE *msgDest, int r, int c, MaxProdBP *mrf); 32 | 33 | void ComputeMsgDown(FLOATTYPE *msgDest, int r, int c, MaxProdBP *mrf); 34 | 35 | void getBelief(FLOATTYPE *beliefVec); 36 | int getBeliefMaxInd(); 37 | 38 | int msgChange(FLOATTYPE thresh); 39 | 40 | void deliverMsgs(); 41 | 42 | }; 43 | 44 | void initOneNodeMsgMem(OneNodeCluster *nodeArray, FLOATTYPE *memChunk, const int numNodes, 45 | const int msgChunkSize); 46 | 47 | void computeMessagesUpDown(OneNodeCluster *nodeArray, const int numCols, const int numRows, 48 | const int currCol, const FLOATTYPE alpha, MaxProdBP *mrf); 49 | void computeMessagesLeftRight(OneNodeCluster *nodeArray, const int numCols, const int numRows, 50 | const int currRow, const FLOATTYPE alpha, MaxProdBP *mrf); 51 | 52 | void computeOneNodeMessagesPeriodic(OneNodeCluster *nodeTopArray, OneNodeCluster *nodeBotArray, 53 | const int numCols, const FLOATTYPE alpha); 54 | 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /base/mrf/typeTruncatedQuadratic2D.h: -------------------------------------------------------------------------------- 1 | #ifndef __AJALSOQJAJSDFASD_H__ 2 | #define __AJALSOQJAJSDFASD_H__ 3 | 4 | #include 5 | 6 | // This file is a stub, to make TRWS compile. 7 | 8 | 9 | struct TypeTruncatedQuadratic2D 10 | { 11 | typedef double REAL; 12 | 13 | struct Edge 14 | { 15 | void DistanceTransformL2(int /*K*/, int /*stride*/, REAL /*alpha*/, REAL* /*source*/, REAL* /*dest*/, 16 | int* /*parabolas*/, int* /*intersections*/) 17 | { 18 | printf("\n\ 19 | +-------------------------------------------------------------+\n\ 20 | | In order to run TRW-S with truncted L2 terms, |\n\ 21 | | you need to download the implementation from |\n\ 22 | | http://www.adastral.ucl.ac.uk/~vnk/papers/TRW-S.html |\n\ 23 | | and copy file typeTruncatedQuadratic2D.h |\n\ 24 | | to the main directory (i.e. replace the existing file) |\n\ 25 | +-------------------------------------------------------------+\n\ 26 | "); 27 | exit(1); 28 | } 29 | }; 30 | }; 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /base/numeric/convert.sh: -------------------------------------------------------------------------------- 1 | mv mylapack.cc.cpp mylapack.cc 2 | -------------------------------------------------------------------------------- /base/numeric/cooMat.h: -------------------------------------------------------------------------------- 1 | #ifndef NUMERIC_COOMAT_H 2 | #define NUMERIC_COOMAT_H 3 | 4 | #include 5 | #include "mat.h" 6 | 7 | template 8 | class CcooMat: public Cmat { 9 | public: 10 | CcooMat(void); 11 | CcooMat(const int row, const int col); 12 | virtual ~CcooMat(); 13 | 14 | void dealloc(void); 15 | 16 | //---------------------------------------------------------------------- 17 | // get and set functions 18 | //---------------------------------------------------------------------- 19 | T get(const int i, const int j) const; 20 | void set(const int i, const int j, const T rhs, const int nocheck = 0); 21 | 22 | //---------------------------------------------------------------------- 23 | // member variables 24 | //---------------------------------------------------------------------- 25 | std::vector m_val; 26 | std::vector m_rowind; 27 | std::vector m_colind; 28 | }; 29 | 30 | template 31 | CcooMat::CcooMat(void): Cmat() { 32 | }; 33 | 34 | template 35 | CcooMat::CcooMat(const int row, const int col): Cmat(row, col) { 36 | }; 37 | 38 | template 39 | CcooMat::~CcooMat() { 40 | }; 41 | 42 | // deallocater 43 | template 44 | void CcooMat::dealloc(void) { 45 | std::vector().swap(m_val); 46 | std::vector().swap(m_rowind); 47 | std::vector().swap(m_colind); 48 | 49 | m_row = 0; m_col = 0; 50 | }; 51 | 52 | // set 53 | template 54 | T CcooMat::get(const int i, const int j) const { 55 | for (int e = 0; e < m_val.size(); ++e) { 56 | if (m_rowind[e] == i && m_colind[e] == j) 57 | return m_val[e]; 58 | } 59 | return 0.0; 60 | }; 61 | 62 | template 63 | void CcooMat::set(const int i, const int j, const T rhs, const int nocheck) { 64 | // when setting 0 65 | const int nnz = (int)m_val.size(); 66 | 67 | if (rhs == 0.0) { 68 | // if you find (i,j), remove it from the array 69 | for (int e = 0; e < nnz; ++e) { 70 | if (m_rowind[e] == i && m_colind[e] == j) { 71 | m_val[e] = m_val[nnz - 1]; 72 | m_rowind[e] = m_rowind[nnz - 1]; 73 | m_colind[e] = m_colind[nnz - 1]; 74 | 75 | m_val.resize(nnz - 1); 76 | m_rowind.resize(nnz - 1); 77 | m_colind.resize(nnz - 1); 78 | 79 | return; 80 | } 81 | } 82 | } 83 | // when setting non-zero value 84 | else { 85 | if (nocheck == 0) { 86 | // when you find (i,j) overwrite the value 87 | for (int e = 0; e < nnz; ++e) { 88 | if (m_rowind[e] == i && m_colind[e] == j) { 89 | m_val[e] = rhs; 90 | return; 91 | } 92 | } 93 | } 94 | 95 | // if no (i,j), add it to the array 96 | m_val.push_back(rhs); 97 | m_rowind.push_back(i); 98 | m_colind.push_back(j); 99 | } 100 | }; 101 | 102 | template 103 | void coo2csr(const CcooMat& coomat, CsparseMat& csrmat) { 104 | // free memory 105 | csrmat.dealloc(); 106 | 107 | // copy element of the base matrix class 108 | const int row = coomat.m_row; 109 | const int col = coomat.m_col; 110 | const int nnz = (int)coomat.m_val.size(); 111 | 112 | csrmat.m_row = row; csrmat.m_col = col; 113 | 114 | // allocate memory 115 | csrmat.m_val.resize(nnz); 116 | csrmat.m_colind.resize(nnz); 117 | csrmat.m_rowind.resize(row + 1); 118 | 119 | // [table[0] table[1] ...] is equal to m_col 120 | std::vector > table; 121 | table.resize(row); 122 | for (int e = 0; e < nnz; ++e) 123 | table[coomat.m_rowind[e]].push_back(coomat.m_colind[e]); 124 | // sort each array 125 | for (int i = 0; i < (int)table.size(); ++i) 126 | sort(table[i].begin(), table[i].end()); 127 | 128 | // set m_row 129 | csrmat.m_rowind[0] = 0; 130 | for (int i = 1; i < csrmat.m_row + 1; ++i) 131 | csrmat.m_rowind[i] = csrmat.m_rowind[i-1] + (int)table[i-1].size(); 132 | 133 | // go through each element and set values 134 | for (int e = 0; e < nnz; ++e) { 135 | const int& row = coomat.m_rowind[e]; 136 | const int offset = lower_bound(table[row].begin(), table[row].end(), 137 | coomat.m_colind[e]) - table[row].begin(); 138 | 139 | const int pos = csrmat.m_rowind[row] + offset; 140 | csrmat.m_val[pos] = coomat.m_val[e]; 141 | csrmat.m_colind[pos] = coomat.m_colind[e]; 142 | } 143 | }; 144 | 145 | #endif // COOMAT_H 146 | -------------------------------------------------------------------------------- /base/numeric/euler.h: -------------------------------------------------------------------------------- 1 | #ifndef EULER_H 2 | #define EULER_H 3 | 4 | #include 5 | 6 | class Ceuler { 7 | public: 8 | template 9 | inline static void getAngles(const T& x, const T& y, const T& z, T& theta, T& phi); 10 | }; 11 | 12 | template 13 | inline void Ceuler::getAngles(const T& x, const T& y, const T& z, T& theta, T& phi) { 14 | theta = acos(z); 15 | const float sintheta = sin(theta); 16 | if (sintheta == 0.0) { 17 | phi = 0.0; 18 | return; 19 | } 20 | 21 | const float cosphi = max(-1.0f, min(1.0f, x / sintheta)); 22 | const float sinphi = max(-1.0f, min(1.0f, y / sintheta)); 23 | phi = atan2(cosphi, sinphi); 24 | if (phi < 0.0) 25 | phi += 2 * M_PI; 26 | }; 27 | 28 | #endif // EULER_H 29 | -------------------------------------------------------------------------------- /base/numeric/mat.h: -------------------------------------------------------------------------------- 1 | #ifndef NUMERIC_MAT_H 2 | #define NUMERIC_MAT_H 3 | 4 | class Cmat { 5 | public: 6 | Cmat(void) { 7 | m_row = 0; 8 | m_col = 0; 9 | } 10 | 11 | Cmat(const int row, const int col) { 12 | m_row = row; 13 | m_col = col; 14 | } 15 | 16 | virtual ~Cmat() { 17 | } 18 | 19 | inline int getRow(void) const{ 20 | return m_row; 21 | } 22 | 23 | inline int getCol(void) const{ 24 | return m_col; 25 | } 26 | 27 | int m_row; 28 | int m_col; 29 | 30 | protected: 31 | }; 32 | 33 | #endif // MAT_H 34 | -------------------------------------------------------------------------------- /base/numeric/mylapack.h: -------------------------------------------------------------------------------- 1 | #ifndef NUMERIC_MYLAPACK_H 2 | #define NUMERIC_MYLAPACK_H 3 | 4 | #include 5 | 6 | class Cmylapack { 7 | public: 8 | 9 | 10 | // Solve Ax = 0. 11 | // Values contain singular values stored in an increasing order 12 | static void hlls(const std::vector >& A, 13 | std::vector& vec, 14 | std::vector& values); 15 | 16 | static void hlls(const std::vector >& A, 17 | std::vector& vec, 18 | std::vector& values); 19 | 20 | // Solve Ax = b 21 | static void lls(const std::vector >& A, 22 | const std::vector& b, 23 | std::vector& x); 24 | 25 | static void lls(const std::vector >& A, 26 | const std::vector& b, 27 | std::vector& x); 28 | 29 | static void lls(std::vector& A, 30 | std::vector& b, 31 | const int width, const int height); 32 | 33 | static void lls(std::vector& A, 34 | std::vector& b, 35 | const int width, const int height); 36 | 37 | // SVD 38 | // A = U Sigma V^T 39 | static void svd(const std::vector >& A, 40 | std::vector >& U, 41 | std::vector >& VT, 42 | std::vector& S); 43 | 44 | }; 45 | 46 | #endif // NUMERIC_MYLAPACK_H 47 | -------------------------------------------------------------------------------- /delete_files.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | /bin/rm -f $1/evaluation/* 4 | /bin/rm -f $1/evaluation/images/* 5 | /bin/rm -f $1/floorplan/* 6 | /bin/rm -f $1/object/* 7 | # some imges inside... /bin/rm -f $1/object_detection/* 8 | /bin/rm -f $1/texture_atlas/* 9 | /bin/rm -f $1/thumbnail/* 10 | 11 | -------------------------------------------------------------------------------- /main_process/Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | cd object_detection; cmake .; make 3 | cd object_refinement; cmake .; make 4 | cd object_segmentation; cmake .; make 5 | cd texture; cmake .; make 6 | 7 | clean: 8 | cd object_detection; make clean 9 | cd object_refinement; make clean 10 | cd object_segmentation; make clean 11 | cd texture; make clean 12 | -------------------------------------------------------------------------------- /main_process/object_detection/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8) 2 | project(object_detection) 3 | 4 | FIND_PACKAGE(OpenCV REQUIRED) 5 | FIND_PACKAGE(CGAL QUIET COMPONENTS Core) 6 | 7 | INCLUDE( ${CGAL_USE_FILE} ) 8 | link_directories(/usr/local/lib) 9 | 10 | if(UNIX) 11 | set(CMAKE_CXX_FLAGS "-Wno-c++11-extensions -std=c++11") 12 | endif(UNIX) 13 | 14 | if(${CMAKE_SYSTEM} MATCHES "Darwin") 15 | set( CMAKE_CXX_FLAGS "-Wno-c++11-extensions -Wno-gnu-static-float-init -Wno-sign-compare" ) 16 | include_directories("/usr/local/include/eigen3") 17 | endif(${CMAKE_SYSTEM} MATCHES "Darwin") 18 | 19 | if(${CMAKE_SYSTEM} MATCHES "Linux") 20 | include_directories("/usr/include/eigen3") 21 | endif(${CMAKE_SYSTEM} MATCHES "Linux") 22 | 23 | 24 | if (WIN32) 25 | include_directories("C:\\Eigen3.2.2") 26 | include_directories("C:\\gflags-2.1.1\\include") 27 | link_directories("C:\\gflags-2.1.1\\lib") 28 | endif (WIN32) 29 | 30 | add_executable( generate_object_icons_cli generate_object_icons_cli.cc generate_object_icons.cc polygon_triangulation2.cc ../../base/detection.cc ../../base/floorplan.cc ../../base/indoor_polygon.cc ../../base/panorama.cc ../../base/point_cloud.cc ) 31 | target_link_libraries( generate_object_icons_cli ${OpenCV_LIBS} ) 32 | target_link_libraries( generate_object_icons_cli gflags ) 33 | target_link_libraries( generate_object_icons_cli ${CGAL_LIBRARIES} ${CGAL_3RDPARTY_LIBRARIES}) 34 | 35 | if(${CMAKE_SYSTEM} MATCHES "Linux") 36 | target_link_libraries(generate_object_icons_cli pthread) 37 | endif(${CMAKE_SYSTEM} MATCHES "Linux") 38 | 39 | -------------------------------------------------------------------------------- /main_process/object_detection/generate_object_icons.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "../../base/detection.h" 8 | #include "../../base/panorama.h" 9 | #include "../../base/point_cloud.h" 10 | 11 | namespace structured_indoor_modeling { 12 | 13 | class IndoorPolygon; 14 | // room, object 15 | typedef std::pair ObjectId; 16 | 17 | void RasterizeObjectIds(const std::vector& panoramas, 18 | const std::vector& object_point_clouds, 19 | std::vector >* object_ids); 20 | 21 | void AssociateObjectId(const std::vector& panoramas, 22 | const std::vector& detections, 23 | const std::vector >& object_ids, 24 | const double score_threshold, 25 | const double area_threshold, 26 | std::map* object_id_to_detection); 27 | 28 | void AddIconInformationToDetections(const IndoorPolygon& indoor_polygon, 29 | const std::vector& object_point_clouds, 30 | const std::map& object_to_detection, 31 | std::vector* detections); 32 | 33 | void ComputeObjectPolygon(const std::vector& object_points, 34 | Detection &detection); 35 | 36 | void MarchingCube(std::vector >&grid, 37 | std::vector&vlist, 38 | std::vector&elist, 39 | const double isovalue); 40 | 41 | void Smoothing(std::vector& vlist, const int iteration = 1, const double lambda = 0.5); 42 | void Simplification(std::vector& vlist, const int target = 20, const double margin = 10.0); 43 | 44 | bool SanityCheck(const std::vector&elist); 45 | 46 | void SortPolygon(std::vector& vlist,std::vector&elist); 47 | 48 | 49 | 50 | } // namespace structured_indoor_modeling 51 | -------------------------------------------------------------------------------- /main_process/object_refinement/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8) 2 | project(Object_refinement) 3 | 4 | find_package(OpenCV REQUIRED) 5 | 6 | if(${CMAKE_SYSTEM} MATCHES "Linux") 7 | find_package(gflags REQUIRED) 8 | endif(${CMAKE_SYSTEM} MATCHES "Linux") 9 | 10 | set( CMAKE_CXX_FLAGS "-std=c++11 -Wno-c++11-extensions -Wno-gnu-static-float-init -Wno-sign-compare -DUSE_64_BIT_PTR_CAST" ) 11 | 12 | if(${CMAKE_SYSTEM} MATCHES "Darwin") 13 | include_directories(/usr/local/include/eigen3) 14 | link_directories(/usr/local/lib) 15 | elseif(${CMAKE_SYSTEM} MATCHES "Linux") 16 | include_directories("/usr/local/include") 17 | include_directories("/usr/include/eigen3") 18 | endif(${CMAKE_SYSTEM} MATCHES "Darwin") 19 | 20 | add_executable(Object_refinement object_refinement.cpp SLIC/SLIC.cpp object_refinement_cali.cpp depth_filling.cpp ../../base/point_cloud.cc ../../base/kdtree/KDtree.cc ../../base/panorama.cc ../../base/floorplan.cc ../../base/indoor_polygon.cc MRF/BP-S.cpp MRF/GCoptimization.cpp MRF/ICM.cpp MRF/LinkedBlockList.cpp MRF/MaxProdBP.cpp MRF/TRW-S.cpp MRF/graph.cpp MRF/maxflow.cpp MRF/mrf.cpp MRF/regions-maxprod.cpp) 21 | 22 | target_link_libraries(Object_refinement gflags) 23 | target_link_libraries(Object_refinement opencv_core opencv_highgui opencv_imgproc opencv_flann) 24 | # target_link_libraries(Object_hole_filling MRF) 25 | 26 | if(${CMAKE_SYSTEM} MATCHES "Linux") 27 | target_link_libraries(Object_refinement pthread) 28 | endif(${CMAKE_SYSTEM} MATCHES "Linux") 29 | -------------------------------------------------------------------------------- /main_process/object_refinement/MRF/BP-S.h: -------------------------------------------------------------------------------- 1 | #ifndef __BPS_H__ 2 | #define __BPS_H__ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "mrf.h" 9 | 10 | 11 | class BPS : public MRF{ 12 | public: 13 | typedef CostVal REAL; 14 | 15 | BPS(int width, int height, int nLabels, EnergyFunction *eng); 16 | BPS(int nPixels, int nLabels,EnergyFunction *eng); 17 | ~BPS(); 18 | void setNeighbors(int /*pix1*/, int /*pix2*/, CostVal /*weight*/){printf("Not implemented"); exit(1);} 19 | Label getLabel(int pixel){return(m_answer[pixel]);}; 20 | void setLabel(int pixel,Label label){m_answer[pixel] = label;}; 21 | Label* getAnswerPtr(){return(m_answer);}; 22 | void clearAnswer(); 23 | void setParameters(int /*numParam*/, void * /*param*/){printf("No optional parameters to set"); exit(1);} 24 | EnergyVal smoothnessEnergy(); 25 | EnergyVal dataEnergy(); 26 | 27 | protected: 28 | void setData(DataCostFn dcost); 29 | void setData(CostVal* data); 30 | void setSmoothness(SmoothCostGeneralFn cost); 31 | void setSmoothness(CostVal* V); 32 | void setSmoothness(int smoothExp,CostVal smoothMax, CostVal lambda); 33 | void setCues(CostVal* hCue, CostVal* vCue); 34 | void Allocate(); 35 | void initializeAlg(); 36 | void optimizeAlg(int nIterations); 37 | 38 | private: 39 | 40 | enum 41 | { 42 | NONE, 43 | L1, 44 | L2, 45 | FIXED_MATRIX, 46 | GENERAL, 47 | BINARY, 48 | } m_type; 49 | 50 | CostVal m_smoothMax; // used only if 51 | CostVal m_lambda; // m_type == L1 or m_type == L2 52 | 53 | Label *m_answer; 54 | CostVal *m_V; // points to array of size nLabels^2 (if type==FIXED_MATRIX) or of size nEdges*nLabels^2 (if type==GENERAL) 55 | CostVal *m_D; 56 | CostVal *m_DBinary; // valid if type == BINARY 57 | CostVal *m_horzWeights; 58 | CostVal *m_vertWeights; 59 | CostVal *m_horzWeightsBinary; 60 | CostVal *m_vertWeightsBinary; 61 | DataCostFn m_dataFn; 62 | SmoothCostGeneralFn m_smoothFn; 63 | bool m_needToFreeV; 64 | bool m_needToFreeD; 65 | 66 | REAL* m_messages; // size of one message: N = 1 if m_type == BINARY, N = K otherwise 67 | // message between edges (x,y)-(x+1,y): m_messages+(2*x+2*y*m_width)*N 68 | // message between edges (x,y)-(x,y+1): m_messages+(2*x+2*y*m_width+1)*N 69 | 70 | int m_messageArraySizeInBytes; 71 | 72 | void optimize_GRID_L1(int nIterations); 73 | void optimize_GRID_L2(int nIterations); 74 | void optimize_GRID_FIXED_MATRIX(int nIterations); 75 | void optimize_GRID_GENERAL(int nIterations); 76 | void optimize_GRID_BINARY(int nIterations); 77 | }; 78 | 79 | #endif /* __BPS_H__ */ 80 | -------------------------------------------------------------------------------- /main_process/object_refinement/MRF/ICM.h: -------------------------------------------------------------------------------- 1 | #ifndef __ICM_H__ 2 | #define __ICM_H__ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "mrf.h" 9 | #include "LinkedBlockList.h" 10 | 11 | 12 | class ICM : public MRF{ 13 | public: 14 | ICM(int width, int height, int nLabels, EnergyFunction *eng); 15 | ICM(int nPixels, int nLabels,EnergyFunction *eng); 16 | ~ICM(); 17 | void setNeighbors(int pix1, int pix2, CostVal weight); 18 | Label getLabel(int pixel){return(m_answer[pixel]);}; 19 | void setLabel(int pixel,Label label){m_answer[pixel] = label;}; 20 | Label* getAnswerPtr(){return(m_answer);}; 21 | void clearAnswer(); 22 | void setParameters(int /*numParam*/, void * /*param*/){printf("No optional parameters to set"); exit(1);} 23 | EnergyVal smoothnessEnergy(); 24 | EnergyVal dataEnergy(); 25 | 26 | protected: 27 | void setData(DataCostFn dcost); 28 | void setData(CostVal* data); 29 | void setSmoothness(SmoothCostGeneralFn cost); 30 | void setSmoothness(CostVal* V); 31 | void setSmoothness(int smoothExp,CostVal smoothMax, CostVal lambda); 32 | void setCues(CostVal* hCue, CostVal* vCue); 33 | void initializeAlg(); 34 | void optimizeAlg(int nIterations); 35 | 36 | private: 37 | Label *m_answer; 38 | CostVal *m_V; 39 | CostVal *m_D; 40 | CostVal *m_horizWeights; 41 | CostVal *m_vertWeights; 42 | DataCostFn m_dataFn; 43 | SmoothCostGeneralFn m_smoothFn; 44 | bool m_needToFreeV; 45 | 46 | typedef struct NeighborStruct{ 47 | int to_node; 48 | CostVal weight; 49 | } Neighbor; 50 | 51 | LinkedBlockList *m_neighbors; 52 | }; 53 | 54 | 55 | #endif /* __ICM_H__ */ 56 | 57 | 58 | -------------------------------------------------------------------------------- /main_process/object_refinement/MRF/LinkedBlockList.cpp: -------------------------------------------------------------------------------- 1 | #include "LinkedBlockList.h" 2 | 3 | /*********************************************************************/ 4 | 5 | void LinkedBlockList::addFront(ListType item) { 6 | 7 | if ( m_head_block_size == GCLL_BLOCK_SIZE ) 8 | { 9 | LLBlock *tmp = (LLBlock *) new LLBlock; 10 | tmp -> m_next = m_head; 11 | m_head = tmp; 12 | m_head_block_size = 0; 13 | } 14 | 15 | m_head ->m_item[m_head_block_size] = item; 16 | m_head_block_size++; 17 | } 18 | 19 | /*********************************************************************/ 20 | 21 | ListType LinkedBlockList::next() 22 | { 23 | ListType toReturn = m_cursor -> m_item[m_cursor_ind]; 24 | 25 | m_cursor_ind++; 26 | 27 | if ( m_cursor == m_head && m_cursor_ind >= m_head_block_size ) 28 | { 29 | m_cursor = m_cursor ->m_next; 30 | m_cursor_ind = 0; 31 | } 32 | else if ( m_cursor_ind == GCLL_BLOCK_SIZE ) 33 | { 34 | m_cursor = m_cursor ->m_next; 35 | m_cursor_ind = 0; 36 | } 37 | return(toReturn); 38 | } 39 | 40 | /*********************************************************************/ 41 | 42 | bool LinkedBlockList::hasNext() 43 | { 44 | if ( m_cursor != 0 ) return (true); 45 | else return(false); 46 | } 47 | 48 | 49 | /*********************************************************************/ 50 | 51 | LinkedBlockList::~LinkedBlockList() 52 | { 53 | LLBlock *tmp; 54 | 55 | while ( m_head != 0 ) 56 | { 57 | tmp = m_head; 58 | m_head = m_head->m_next; 59 | delete tmp; 60 | } 61 | }; 62 | 63 | /*********************************************************************/ 64 | 65 | -------------------------------------------------------------------------------- /main_process/object_refinement/MRF/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 unsigned 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 | -------------------------------------------------------------------------------- /main_process/object_refinement/MRF/MaxProdBP.h: -------------------------------------------------------------------------------- 1 | #ifndef __MAXPRODBP_H__ 2 | #define __MAXPRODBP_H__ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "mrf.h" 9 | #include "LinkedBlockList.h" 10 | #include "regions-new.h" 11 | 12 | #define FloatType float 13 | #define FLOATTYPE float 14 | class MaxProdBP; 15 | 16 | class MaxProdBP : public MRF{ 17 | public: 18 | MaxProdBP(int width, int height, int nLabels, EnergyFunction *eng); 19 | MaxProdBP(int nPixels, int nLabels,EnergyFunction *eng); 20 | ~MaxProdBP(); 21 | void setNeighbors(int pix1, int pix2, CostVal weight); 22 | Label getLabel(int pixel){return(m_answer[pixel]);}; 23 | void setLabel(int pixel,Label label){m_answer[pixel] = label;}; 24 | Label* getAnswerPtr(){return(m_answer);}; 25 | void clearAnswer(); 26 | void setParameters(int , void *){printf("No optional parameters to set");} 27 | EnergyVal smoothnessEnergy(); 28 | EnergyVal dataEnergy(); 29 | EnergyFunction *getEnergyFunction(); 30 | int getWidth(); 31 | int getHeight(); 32 | FLOATTYPE *getScratchMatrix(); 33 | int getNLabels(); 34 | bool varWeights(); 35 | void setExpScale(int expScale); 36 | friend void getPsiMat(OneNodeCluster &cluster, FLOATTYPE *&destMatrix, 37 | int r, int c, MaxProdBP *mrf, int direction, FLOATTYPE &var_weight); 38 | 39 | InputType getSmoothType(); 40 | FLOATTYPE getExpV(int i); 41 | FLOATTYPE *getExpV(); 42 | 43 | CostVal getHorizWeight(int r, int c); 44 | CostVal getVertWeight(int r, int c); 45 | 46 | 47 | CostVal m_lambda; 48 | CostVal m_smoothMax; 49 | int m_smoothExp; 50 | 51 | enum //Borrowed from BP-S.h by vnk 52 | { 53 | NONE, 54 | L1, 55 | L2, 56 | FIXED_MATRIX, 57 | GENERAL, 58 | BINARY, 59 | } m_type; 60 | 61 | protected: 62 | void setData(DataCostFn dcost); 63 | void setData(CostVal* data); 64 | void setSmoothness(SmoothCostGeneralFn cost); 65 | void setSmoothness(CostVal* V); 66 | void setSmoothness(int smoothExp,CostVal smoothMax, CostVal lambda); 67 | void setCues(CostVal* hCue, CostVal* vCue); 68 | void initializeAlg(); 69 | void BPinitializeAlg(); 70 | void optimizeAlg(int nIterations); 71 | 72 | private: 73 | Label *m_answer; 74 | CostVal *m_V; 75 | CostVal *m_D; 76 | CostVal *m_horizWeights; 77 | CostVal *m_vertWeights; 78 | FLOATTYPE m_exp_scale; 79 | DataCostFn m_dataFn; 80 | SmoothCostGeneralFn m_smoothFn; 81 | bool m_needToFreeV; 82 | FLOATTYPE *m_scratchMatrix; 83 | FLOATTYPE *m_ExpData; 84 | FLOATTYPE *m_message_chunk; 85 | OneNodeCluster *nodeArray; 86 | typedef struct NeighborStruct { 87 | int to_node; 88 | CostVal weight; 89 | } Neighbor; 90 | 91 | LinkedBlockList *m_neighbors; 92 | }; 93 | 94 | 95 | #endif /* __ICM_H__ */ 96 | 97 | 98 | -------------------------------------------------------------------------------- /main_process/object_refinement/MRF/TRW-S.h: -------------------------------------------------------------------------------- 1 | #ifndef __TRWS_H__ 2 | #define __TRWS_H__ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "mrf.h" 9 | 10 | 11 | class TRWS : public MRF{ 12 | public: 13 | typedef double REAL; 14 | 15 | TRWS(int width, int height, int nLabels, EnergyFunction *eng); 16 | TRWS(int nPixels, int nLabels,EnergyFunction *eng); 17 | ~TRWS(); 18 | void setNeighbors(int /*pix1*/, int /*pix2*/, CostVal /*weight*/){printf("Not implemented"); exit(1);} 19 | Label getLabel(int pixel){return(m_answer[pixel]);}; 20 | void setLabel(int pixel,Label label){m_answer[pixel] = label;}; 21 | Label* getAnswerPtr(){return(m_answer);}; 22 | void clearAnswer(); 23 | void setParameters(int /*numParam*/, void * /*param*/){printf("No optional parameters to set"); exit(1);} 24 | EnergyVal smoothnessEnergy(); 25 | EnergyVal dataEnergy(); 26 | double lowerBound() { return (double)m_lowerBound; } 27 | 28 | // For general smoothness functions, this code tries to cache all function values in an array 29 | // for efficiency. To prevent this, call the following function before calling initialize(): 30 | void dontCacheSmoothnessCosts() {m_allocateArrayForSmoothnessCostFn = false;} 31 | 32 | protected: 33 | void setData(DataCostFn dcost); 34 | void setData(CostVal* data); 35 | void setSmoothness(SmoothCostGeneralFn cost); 36 | void setSmoothness(CostVal* V); 37 | void setSmoothness(int smoothExp,CostVal smoothMax, CostVal lambda); 38 | void setCues(CostVal* hCue, CostVal* vCue); 39 | void Allocate(); 40 | void initializeAlg(); 41 | void optimizeAlg(int nIterations); 42 | 43 | private: 44 | 45 | enum 46 | { 47 | NONE, 48 | L1, 49 | L2, 50 | FIXED_MATRIX, 51 | GENERAL, 52 | BINARY, 53 | } m_type; 54 | 55 | CostVal m_smoothMax; // used only if 56 | CostVal m_lambda; // m_type == L1 or m_type == L2 57 | 58 | Label *m_answer; 59 | CostVal *m_V; // points to array of size nLabels^2 (if type==FIXED_MATRIX) or of size nEdges*nLabels^2 (if type==GENERAL) 60 | CostVal *m_D; 61 | CostVal *m_DBinary; // valid if type == BINARY 62 | CostVal *m_horzWeights; 63 | CostVal *m_vertWeights; 64 | CostVal *m_horzWeightsBinary; 65 | CostVal *m_vertWeightsBinary; 66 | DataCostFn m_dataFn; 67 | SmoothCostGeneralFn m_smoothFn; 68 | bool m_needToFreeV; 69 | bool m_needToFreeD; 70 | 71 | REAL* m_messages; // size of one message: N = 1 if m_type == BINARY, N = K otherwise 72 | // message between edges (x,y)-(x+1,y): m_messages+(2*x+2*y*m_width)*N 73 | // message between edges (x,y)-(x,y+1): m_messages+(2*x+2*y*m_width+1)*N 74 | 75 | int m_messageArraySizeInBytes; 76 | 77 | REAL m_lowerBound; 78 | 79 | void optimize_GRID_L1(int nIterations); 80 | void optimize_GRID_L2(int nIterations); 81 | void optimize_GRID_FIXED_MATRIX(int nIterations); 82 | void optimize_GRID_GENERAL(int nIterations); 83 | void optimize_GRID_BINARY(int nIterations); 84 | }; 85 | 86 | #endif /* __TRWS_H__ */ 87 | -------------------------------------------------------------------------------- /main_process/object_refinement/MRF/mrf.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "mrf.h" 7 | 8 | 9 | void MRF::initialize() 10 | { 11 | 12 | m_initialized = 1; 13 | 14 | if ( m_dataType == ARRAY ) 15 | setData(m_e->m_dataCost->m_costArray); 16 | else setData(m_e->m_dataCost->m_costFn); 17 | 18 | if ( m_smoothType == FUNCTION ) 19 | setSmoothness(m_e->m_smoothCost->m_costFn); 20 | else 21 | { 22 | if ( m_smoothType == ARRAY ) 23 | { 24 | checkArray(m_e->m_smoothCost->m_V); 25 | setSmoothness(m_e->m_smoothCost->m_V); 26 | } 27 | else 28 | { 29 | int smoothExp = m_e->m_smoothCost->m_smoothExp; 30 | if ( smoothExp != 1 && smoothExp != 2) 31 | { 32 | fprintf(stderr, "Wrong exponent in setSmoothness()!\n"); 33 | exit(1); 34 | } 35 | setSmoothness(smoothExp,m_e->m_smoothCost->m_smoothMax,m_e->m_smoothCost->m_lambda); 36 | } 37 | 38 | if (m_e->m_smoothCost->m_varWeights ) 39 | { 40 | if (!m_grid_graph) 41 | { 42 | fprintf(stderr, "Edge multiplier cannot be used with non-grid graphs\n"); 43 | exit(1); 44 | } 45 | setCues(m_e->m_smoothCost->m_hWeights,m_e->m_smoothCost->m_vWeights); 46 | } 47 | 48 | } 49 | 50 | initializeAlg(); 51 | } 52 | 53 | 54 | void MRF::commonInitialization(EnergyFunction *e) 55 | { 56 | m_dataType = e->m_dataCost->m_type; 57 | m_smoothType = e->m_smoothCost->m_type; 58 | m_varWeights = e->m_smoothCost->m_varWeights; 59 | m_initialized = 0; 60 | m_e = e; 61 | m_allocateArrayForSmoothnessCostFn = true; 62 | } 63 | 64 | 65 | MRF::MRF(int width, int height, int nLabels, EnergyFunction *e) 66 | { 67 | m_width = width; 68 | m_height = height; 69 | m_nLabels = nLabels; 70 | m_nPixels = width*height; 71 | m_grid_graph = 1; 72 | commonInitialization(e); 73 | } 74 | 75 | MRF::MRF(int nPixels, int nLabels, EnergyFunction *e) 76 | { 77 | m_nLabels = nLabels; 78 | m_nPixels = nPixels; 79 | m_grid_graph = 0; 80 | commonInitialization(e); 81 | } 82 | 83 | char MRF::checkEnergy() 84 | { 85 | if ( !m_initialized) {fprintf(stderr, "Call initialize() first,exiting!");exit(1);} 86 | return(2); 87 | } 88 | 89 | 90 | MRF::EnergyVal MRF::totalEnergy() 91 | { 92 | if (!isValid()) { fprintf(stderr, "totalEnergy() cannot be called for invalid energy!\n"); exit(1); } 93 | if (!m_initialized) { fprintf(stderr, "Call initialize() first!\n"); exit(1); } 94 | 95 | return dataEnergy()+smoothnessEnergy(); 96 | } 97 | 98 | 99 | void MRF::optimize(int nIterations, float& time) 100 | { 101 | if (!isValid()) { fprintf(stderr, "optimize() cannot be called for invalid energy!\n"); exit(1); } 102 | if (!m_initialized ) { fprintf(stderr, "run initialize() first!\n"); exit(1); } 103 | 104 | // start timer 105 | clock_t start = clock(); 106 | 107 | 108 | optimizeAlg(nIterations); 109 | 110 | // stop timer 111 | clock_t finish = clock(); 112 | time = (float) (((double)(finish - start)) / CLOCKS_PER_SEC); 113 | } 114 | 115 | 116 | void MRF::checkArray(CostVal *V) 117 | { 118 | 119 | int i, j; 120 | 121 | for (i=0; i< m_nLabels; i++) 122 | for (j=i; j 5 | 6 | // This file is a stub, to make TRWS compile. 7 | 8 | 9 | struct TypeTruncatedQuadratic2D 10 | { 11 | typedef double REAL; 12 | 13 | struct Edge 14 | { 15 | void DistanceTransformL2(int /*K*/, int /*stride*/, REAL /*alpha*/, REAL* /*source*/, REAL* /*dest*/, 16 | int* /*parabolas*/, int* /*intersections*/) 17 | { 18 | printf("\n\ 19 | +-------------------------------------------------------------+\n\ 20 | | In order to run TRW-S with truncted L2 terms, |\n\ 21 | | you need to download the implementation from |\n\ 22 | | http://pub.ist.ac.at/~vnk/papers/TRW-S.html |\n\ 23 | | and copy file typeTruncatedQuadratic2D.h |\n\ 24 | | to the main directory (i.e. replace the existing file) |\n\ 25 | +-------------------------------------------------------------+\n\ 26 | "); 27 | exit(1); 28 | } 29 | }; 30 | }; 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /main_process/object_refinement/depth_filling.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace structured_indoor_modeling{ 8 | 9 | class FileIO; 10 | class PointCloud; 11 | class Panorama; 12 | 13 | std::vector JacobiMethod(const std::vector >& A, const std::vector& B, int max_iter); 14 | 15 | 16 | class DepthFilling{ 17 | public: 18 | DepthFilling(){} 19 | void Init(const Panorama& panorama, bool maskv = true); 20 | void Init(const PointCloud &point_cloud, const Panorama &panorama, bool maskv = true); 21 | void Init(const PointCloud &point_cloud, const Panorama &panorama, const std::vector&objectgroup, bool maskv = true); 22 | void setMask(int id, bool maskv); 23 | void setMask(int x, int y, bool maskv); 24 | void fill_hole(const Panorama& panorama); 25 | 26 | inline bool insideDepth(int x,int y){ 27 | return x>=0 && x=0 && y& GetDepthmap() const{return depthmap;} 36 | private: 37 | std::vector depthmap; 38 | std::vector mask; //using vector is not a good choice... 39 | int depthwidth; 40 | int depthheight; 41 | double max_depth; 42 | double min_depth; 43 | }; 44 | 45 | } // namespace 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /main_process/object_segmentation/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8) 2 | project( object_segmentation_cli ) 3 | find_package( OpenCV REQUIRED ) 4 | #find_package( PCl 1.7 REQUIRED COMPONENTS common io) 5 | #find_package( PCl 1.7 REQUIRED COMPONENTS common) 6 | 7 | 8 | # FIND_PACKAGE( Ceres REQUIRED ) 9 | # INCLUDE_DIRECTORIES( ${CERES_INCLUDE_DIRS} ) 10 | 11 | #include_directories(${PCL_INCLUDE_DIRS}) 12 | include_directories("/usr/local/include") 13 | 14 | #link_directories(${PCL_LIBRARY_DIRS}) 15 | LINK_DIRECTORIES("/usr/local/lib") 16 | 17 | #add_definitions(${PCL_DEFINITIONS}) 18 | 19 | if(${CMAKE_SYSTEM} MATCHES "Linux") 20 | include_directories("/usr/include/eigen3") 21 | set(CMAKE_CXX_FLAGS "-Wno-c++11-extensions -std=c++11") 22 | endif(${CMAKE_SYSTEM} MATCHES "Linux") 23 | 24 | if(${CMAKE_SYSTEM} MATCHES "Darwin") 25 | include_directories("/usr/local/include/eigen3") 26 | set( CMAKE_CXX_FLAGS "-Wno-c++11-extensions -Wno-gnu-static-float-init -Wno-sign-compare" ) 27 | endif(${CMAKE_SYSTEM} MATCHES "Darwin") 28 | 29 | add_executable( object_segmentation_cli object_segmentation_cli.cc object_segmentation.cc ../../base/floorplan.cc ../../base/indoor_polygon.cc ../../base/point_cloud.cc ../../base/kdtree/KDtree.cc ) 30 | 31 | target_link_libraries( object_segmentation_cli ${OpenCV_LIBS} ) 32 | target_link_libraries( object_segmentation_cli gflags ) 33 | 34 | if(${CMAKE_SYSTEM} MATCHES "Linux") 35 | target_link_libraries(object_segmentation_cli pthread) 36 | endif(${CMAKE_SYSTEM} MATCHES "Linux") 37 | 38 | #target_link_libraries( object_segmentation_cli ${PCL_COMMON_LIBRARIES} ${PCL_IO_LIBRARIES}) 39 | 40 | 41 | # target_link_libraries( object_segmentation_cli ceres ) 42 | # target_link_libraries( object_segmentation_cli glog ) 43 | -------------------------------------------------------------------------------- /main_process/object_segmentation/object_segmentation.h: -------------------------------------------------------------------------------- 1 | #ifndef OBJECT_SEGMENTATION_H_ 2 | #define OBJECT_SEGMENTATION_H_ 3 | 4 | #include 5 | 6 | namespace structured_indoor_modeling { 7 | 8 | // room segment id definitions. 9 | const int kInitial = -1; 10 | const int kFloor = -2; 11 | const int kWall = -3; 12 | const int kCeiling = -4; 13 | const int kDetail = -5; 14 | 15 | class Floorplan; 16 | class IndoorPolygon; 17 | class PointCloud; 18 | struct Point; 19 | 20 | void SaveData(const int id, 21 | const std::vector& points, 22 | const std::vector& segments); 23 | 24 | void LoadData(const int id, 25 | std::vector* points, 26 | std::vector* segments); 27 | 28 | void SetRoomOccupancy(const Floorplan& floorplan, 29 | std::vector* room_occupancy); 30 | 31 | void SetDoorOccupancy(const Floorplan& floorplan, 32 | std::vector* room_occupancy_with_doors); 33 | 34 | void CollectPointsInRoom(const std::vector& point_clouds, 35 | const Floorplan& floorplan, 36 | const std::vector& room_occupancy, 37 | const int room, 38 | std::vector* points); 39 | 40 | void IdentifyFloorWallCeiling(const std::vector& points, 41 | const Floorplan& floorplan, 42 | const int room, 43 | const double rescale_margin, 44 | std::vector* segments); 45 | 46 | void IdentifyDetails(const std::vector& points, 47 | const Floorplan& floorplan, 48 | const IndoorPolygon& indoor_polygon, 49 | const int room, 50 | const double rescale_margin, 51 | std::vector* segments); 52 | 53 | void Subsample(const double ratio, std::vector* points); 54 | 55 | void FilterNoisyPoints(std::vector* points); 56 | 57 | void SegmentObjects(const std::vector& points, 58 | const double centroid_subsampling_ratio, 59 | const int num_initial_clusters, 60 | const std::vector >& neighbors, 61 | std::vector* segments); 62 | 63 | void SmoothObjects(const std::vector >& neighbors, 64 | std::vector* points); 65 | 66 | void DensifyObjects(const std::vector >& neighbors, 67 | std::vector* points, 68 | std::vector* segments); 69 | 70 | void SetNeighbors(const std::vector& points, 71 | const int num_neighbors, 72 | std::vector >* neighbors); 73 | 74 | void RemoveWindowAndMirror(const Floorplan& floorplan, 75 | const std::vector& room_occupancy_with_doors, 76 | const Eigen::Vector3d& center, 77 | PointCloud* point_cloud); 78 | 79 | void WriteObjectPointsWithColor(const std::vector& points, 80 | const std::vector& segments, 81 | const std::string& filename, 82 | const Eigen::Matrix3d& rotation, 83 | std::map* color_table); 84 | 85 | void WriteOtherPointsWithColor(const std::vector& points, 86 | const std::vector& segments, 87 | const std::string& filename, 88 | const Eigen::Matrix3d& rotation); 89 | 90 | 91 | } // namespace structured_indoor_modeling 92 | 93 | #endif // OBJECT_SEGMENTATION_H_ 94 | -------------------------------------------------------------------------------- /main_process/texture/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8) 2 | project(generate_texture_cli) 3 | 4 | FIND_PACKAGE(OpenCV REQUIRED) 5 | 6 | #find_package( OpenCV REQUIRED ) 7 | LINK_DIRECTORIES(/usr/local/lib) 8 | 9 | if(UNIX) 10 | set(CMAKE_CXX_FLAGS "-Wno-c++11-extensions -std=c++11") 11 | endif(UNIX) 12 | 13 | if(${CMAKE_SYSTEM} MATCHES "Darwin") 14 | set( CMAKE_CXX_FLAGS "-Wno-c++11-extensions -Wno-gnu-static-float-init -Wno-sign-compare" ) 15 | endif(${CMAKE_SYSTEM} MATCHES "Darwin") 16 | 17 | if (WIN32) 18 | include_directories("C:\\Eigen3.2.2") 19 | include_directories("C:\\gflags-2.1.1\\include") 20 | link_directories("C:\\gflags-2.1.1\\lib") 21 | endif (WIN32) 22 | 23 | add_executable( generate_texture_floorplan_cli generate_texture.cc generate_texture_floorplan_cli.cc generate_texture_floorplan.cc synthesize.cc ../../base/floorplan.cc ../../base/panorama.cc ../../base/point_cloud.cc ../../base/imageProcess/morphological_operation.cc ) 24 | target_link_libraries( generate_texture_floorplan_cli ${OpenCV_LIBS} ) 25 | TARGET_LINK_LIBRARIES( generate_texture_floorplan_cli gflags ) 26 | 27 | add_executable( generate_texture_indoor_polygon_cli generate_texture.cc generate_texture_indoor_polygon_cli.cc generate_texture_indoor_polygon.cc synthesize.cc ../../base/indoor_polygon.cc ../../base/panorama.cc ../../base/point_cloud.cc ../../base/imageProcess/morphological_operation.cc ) 28 | target_link_libraries( generate_texture_indoor_polygon_cli ${OpenCV_LIBS} ) 29 | TARGET_LINK_LIBRARIES( generate_texture_indoor_polygon_cli gflags ) 30 | 31 | add_executable( color_point_cloud_cli color_point_cloud_cli.cc generate_texture.cc synthesize.cc ../../base/floorplan.cc ../../base/panorama.cc ../../base/point_cloud.cc ../../base/imageProcess/morphological_operation.cc ../../base/kdtree/KDtree.cc ) 32 | target_link_libraries( color_point_cloud_cli ${OpenCV_LIBS} ) 33 | TARGET_LINK_LIBRARIES( color_point_cloud_cli gflags ) 34 | 35 | add_executable( generate_thumbnail_cli generate_thumbnail_cli.cc ../../base/floorplan.cc ../../base/panorama.cc ) 36 | target_link_libraries( generate_thumbnail_cli ${OpenCV_LIBS} ) 37 | target_link_libraries( generate_thumbnail_cli gflags ) 38 | -------------------------------------------------------------------------------- /main_process/texture/generate_texture.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "generate_texture.h" 5 | #include "../../base/file_io.h" 6 | #include "../../base/panorama.h" 7 | 8 | using namespace Eigen; 9 | using namespace std; 10 | 11 | namespace structured_indoor_modeling { 12 | 13 | void ReadPanoramaToGlobals(const FileIO& file_io, 14 | vector* panorama_to_globals) { 15 | const int num_panoramas = GetNumPanoramas(file_io); 16 | 17 | panorama_to_globals->resize(num_panoramas); 18 | for (int p = 0; p < num_panoramas; ++p) { 19 | const string filename = file_io.GetPanoramaToGlobalTransformation(p); 20 | ifstream ifstr; 21 | ifstr.open(filename.c_str()); 22 | if (!ifstr.is_open()) { 23 | cerr << "Cannot open a file: " << filename << endl; 24 | exit (1); 25 | } 26 | string header; 27 | ifstr >> header; 28 | for (int y = 0; y < 4; ++y) { 29 | for (int x = 0; x < 4; ++x) { 30 | ifstr >> (*panorama_to_globals)[p](y, x); 31 | } 32 | } 33 | ifstr.close(); 34 | } 35 | } 36 | 37 | void Invert(const vector& panorama_to_globals, 38 | vector* global_to_panoramas) { 39 | global_to_panoramas->resize(panorama_to_globals.size()); 40 | for (int i = 0; i < panorama_to_globals.size(); ++i) { 41 | Matrix3d rotation = panorama_to_globals[i].block(0, 0, 3, 3); 42 | global_to_panoramas->at(i).block(0, 0, 3, 3) = rotation.transpose(); 43 | global_to_panoramas->at(i).block(0, 3, 3, 1) = 44 | - rotation.transpose() * panorama_to_globals[i].block(0, 3, 3, 1); 45 | global_to_panoramas->at(i)(3, 0) = 0.0; 46 | global_to_panoramas->at(i)(3, 1) = 0.0; 47 | global_to_panoramas->at(i)(3, 2) = 0.0; 48 | global_to_panoramas->at(i)(3, 3) = 1.0; 49 | } 50 | } 51 | 52 | } // namespace structured_indoor_modeling 53 | 54 | -------------------------------------------------------------------------------- /main_process/texture/generate_texture.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include "../../base/point_cloud.h" 6 | 7 | namespace structured_indoor_modeling { 8 | 9 | class FileIO; 10 | class Panorama; 11 | 12 | void ReadPanoramaToGlobals(const FileIO& file_io, 13 | std::vector* panorama_to_globals); 14 | 15 | void Invert(const std::vector& panorama_to_globals, 16 | std::vector* global_to_panoramas); 17 | 18 | } // namespace structured_indoor_modeling 19 | 20 | -------------------------------------------------------------------------------- /main_process/texture/generate_texture_floorplan.h: -------------------------------------------------------------------------------- 1 | #ifndef GENERATE_TEXTURE_H_ 2 | #define GENERATE_TEXTURE_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | #include "../../base/floorplan.h" 8 | #include "../../base/point_cloud.h" 9 | #include "generate_texture.h" 10 | 11 | namespace structured_indoor_modeling { 12 | 13 | class FileIO; 14 | class Panorama; 15 | class WallTriangulation; 16 | 17 | // Patch where texture is generated. 18 | struct Patch { 19 | // ceiling 0------1 20 | // | | 21 | // | | 22 | // floor 3------2 23 | Eigen::Vector3d vertices[4]; 24 | 25 | // Texture is stored from 0 in a row major format. 26 | Eigen::Vector2i texture_size; 27 | std::vector texture; 28 | 29 | Eigen::Vector2d min_xy_local; 30 | Eigen::Vector2d max_xy_local; 31 | 32 | void InitVertices(const double floor_height) { 33 | vertices[0] = Eigen::Vector3d(min_xy_local[0], min_xy_local[1], floor_height); 34 | vertices[1] = Eigen::Vector3d(max_xy_local[0], min_xy_local[1], floor_height); 35 | vertices[2] = Eigen::Vector3d(max_xy_local[0], max_xy_local[1], floor_height); 36 | vertices[3] = Eigen::Vector3d(min_xy_local[0], max_xy_local[1], floor_height); 37 | } 38 | 39 | //---------------------------------------------------------------------- 40 | Eigen::Vector3d Interpolate(const Eigen::Vector2d& uv) const { 41 | return vertices[0] + uv[0] * (vertices[1] - vertices[0]) + uv[1] * (vertices[3] - vertices[0]); 42 | } 43 | 44 | Eigen::Vector2d LocalToTexture(const Eigen::Vector2d& local) const { 45 | return Eigen::Vector2d(texture_size[0] * (local[0] - min_xy_local[0]) / (max_xy_local[0] - min_xy_local[0]), 46 | texture_size[1] * (local[1] - min_xy_local[1]) / (max_xy_local[1] - min_xy_local[1])); 47 | } 48 | }; 49 | 50 | // Input data from cli.cc. 51 | struct TextureInput { 52 | Floorplan floorplan; 53 | std::vector > panoramas; 54 | std::vector point_clouds; 55 | int pyramid_level_for_floor; 56 | int max_texture_size_per_floor_patch; 57 | int max_texture_size_per_wall_patch; 58 | int texture_height_per_wall; 59 | double position_error_for_floor; 60 | int patch_size_for_synthesis; 61 | int num_cg_iterations; 62 | }; 63 | 64 | void PackWallTextures(const std::vector >& wall_patches, 65 | const int texture_image_size, 66 | Floorplan* floorplan, 67 | int* max_texture_height); 68 | 69 | // Walls. 70 | void SetWallPatches(const TextureInput& texture_input, 71 | std::vector >* wall_patches); 72 | 73 | void PackWallTextures(const std::vector >& patches, 74 | const int texture_image_size, 75 | Floorplan* floorplan, 76 | std::vector >* texture_images, 77 | std::pair* iuv, 78 | int* max_texture_height); 79 | 80 | // Floor. 81 | void SetFloorPatch(const TextureInput& texture_input, Patch* floor_patch); 82 | 83 | void PackFloorTexture(const Patch& floor_patch, 84 | const int texture_image_size, 85 | Floorplan* floorplan, 86 | std::vector >* texture_images, 87 | std::pair* iuv, 88 | int* max_texture_height); 89 | 90 | void WriteTextureImages(const FileIO& file_io, 91 | const int texture_image_size, 92 | const std::vector >& texture_images); 93 | 94 | } // namespace structured_indoor_modeling 95 | 96 | #endif // GENERATE_TEXTURE_H_ 97 | -------------------------------------------------------------------------------- /main_process/texture/generate_texture_indoor_polygon.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "../../base/indoor_polygon.h" 8 | #include "../../base/point_cloud.h" 9 | #include "generate_texture.h" 10 | 11 | namespace structured_indoor_modeling { 12 | 13 | // All the coordinates are in the manhattan coordinate frame. 14 | struct Patch { 15 | // patch xaxis 16 | // 0------1 17 | // patch | | 18 | // yaxis | | 19 | // 3------2 20 | // 21 | // patch zaxis is the normal. 22 | 23 | // Axis aligned bounding box. 24 | Eigen::Vector3d axes[3]; 25 | 26 | Eigen::Vector3d vertices[4]; 27 | Eigen::Vector2i texture_size; 28 | std::vector texture; 29 | 30 | Eigen::Vector3d UVToManhattan(const Eigen::Vector2d& uv) const; 31 | Eigen::Vector2d ManhattanToUV(const Eigen::Vector3d& manhattan) const; 32 | Eigen::Vector2d UVToTexture(const Eigen::Vector2d& uv) const; 33 | Eigen::Vector2d TextureToUV(const Eigen::Vector2d& texture) const; 34 | }; 35 | 36 | // Input data from cli.cc. 37 | struct TextureInput { 38 | IndoorPolygon indoor_polygon; 39 | std::vector > panoramas; 40 | std::vector point_clouds; 41 | 42 | int pyramid_level; 43 | int max_texture_size_per_floor_patch; 44 | int max_texture_size_per_non_floor_patch; 45 | double position_error_for_floor; 46 | double patch_size_for_synthesis; 47 | int num_cg_iterations; 48 | 49 | double texel_unit; 50 | double visibility_margin; 51 | 52 | int num_patch_half_iterations; 53 | bool erode_texture; 54 | }; 55 | 56 | double ComputeTexelUnit(const IndoorPolygon& indoor_polygon, 57 | const int target_texture_size_for_vertical); 58 | 59 | double ComputeVisibilityMargin(const IndoorPolygon& indoor_polygon); 60 | 61 | void SetPatch(const TextureInput& texture_input, 62 | const Segment& segment, 63 | const bool visibility_check, 64 | Patch* patch); 65 | 66 | void PackTexture(const Patch& patch, 67 | const int texture_image_size, 68 | Segment* segment, 69 | std::vector >* texture_images, 70 | std::pair* iuv, 71 | int* max_texture_height); 72 | 73 | void WriteTextureImages(const FileIO& file_io, 74 | const int texture_image_size, 75 | const std::vector >& texture_images, 76 | const std::string& suffix); 77 | 78 | } // namespace structured_indoor_modeling 79 | -------------------------------------------------------------------------------- /main_process/texture/run.sh: -------------------------------------------------------------------------------- 1 | #./generate_thumbnail_cli ~/Box_Sync/research/structured_indoor_modeling/data/equal-sky-0649 2 | #./generate_thumbnail_cli ~/Box_Sync/research/structured_indoor_modeling/data/lumber-cashew-1997 3 | #./generate_thumbnail_cli ~/Box_Sync/research/structured_indoor_modeling/data/new-breeze-6946 4 | #./generate_thumbnail_cli ~/Box_Sync/research/structured_indoor_modeling/data/red-lion-9567 5 | #./generate_thumbnail_cli ~/Box_Sync/research/structured_indoor_modeling/data/salmon-palace-2313 6 | #./generate_texture_floorplan_cli ~/Box_Sync/research/structured_indoor_modeling/data/lumber-cashew-1997 7 | ./generate_texture_floorplan_cli ~/Box_Sync/research/structured_indoor_modeling/data/equal-sky-0649 8 | ./generate_texture_floorplan_cli ~/Box_Sync/research/structured_indoor_modeling/data/new-breeze-6946 9 | ./generate_texture_floorplan_cli ~/Box_Sync/research/structured_indoor_modeling/data/red-lion-9567 10 | ./generate_texture_floorplan_cli ~/Box_Sync/research/structured_indoor_modeling/data/salmon-palace-2313 11 | -------------------------------------------------------------------------------- /main_process/texture/synthesize.h: -------------------------------------------------------------------------------- 1 | #ifndef STRUCTURED_INDOOR_MODELING_SYNTHESIZE_H_ 2 | #define STRUCTURED_INDOOR_MODELING_SYNTHESIZE_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace structured_indoor_modeling { 9 | 10 | struct SynthesisData { 11 | SynthesisData(const std::vector& projected_textures, 12 | const std::vector& weights) : 13 | projected_textures(projected_textures), weights(weights) { 14 | } 15 | 16 | const std::vector& projected_textures; 17 | const std::vector& weights; 18 | 19 | int num_cg_iterations; 20 | Eigen::Vector2i texture_size; 21 | int patch_size; 22 | int margin; 23 | std::vector mask; 24 | }; 25 | 26 | void CollectCandidatePatches(const SynthesisData& synthesis_data, 27 | std::vector* patches, 28 | std::vector* patch_positions); 29 | 30 | void SynthesizePoisson(const SynthesisData& synthesis_data, 31 | const std::vector& patches, 32 | const std::vector& patch_positions, 33 | const bool vertical_constraint, 34 | cv::Mat* floor_texture); 35 | 36 | } // namespace structured_indoor_modeling 37 | 38 | #endif // STRUCTURED_INDOOR_MODELING_SYNTHESIZE_H_ 39 | -------------------------------------------------------------------------------- /not_used/floorplan/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Created by the script cgal_create_cmake_script_with_options 2 | # This is the CMake script for compiling a set of CGAL applications. 3 | 4 | project( floorplan_generation_cli ) 5 | 6 | find_package( OpenCV REQUIRED ) 7 | 8 | cmake_minimum_required(VERSION 2.6.2) 9 | if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" VERSION_GREATER 2.6) 10 | if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER 2.8.3) 11 | cmake_policy(VERSION 2.8.4) 12 | else() 13 | cmake_policy(VERSION 2.6) 14 | endif() 15 | endif() 16 | 17 | set( CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true ) 18 | 19 | if ( COMMAND cmake_policy ) 20 | 21 | cmake_policy( SET CMP0003 NEW ) 22 | 23 | endif() 24 | 25 | # CGAL and its components 26 | find_package( CGAL QUIET COMPONENTS Core ) 27 | 28 | if ( NOT CGAL_FOUND ) 29 | 30 | message(STATUS "This project requires the CGAL library, and will not be compiled.") 31 | return() 32 | 33 | endif() 34 | 35 | # include helper file 36 | include( ${CGAL_USE_FILE} ) 37 | 38 | 39 | # Boost and its components 40 | find_package( Boost REQUIRED ) 41 | 42 | if ( NOT Boost_FOUND ) 43 | 44 | message(STATUS "This project requires the Boost library, and will not be compiled.") 45 | 46 | return() 47 | 48 | endif() 49 | 50 | set(CMAKE_CXX_FLAGS "-Wno-c++11-extensions") 51 | 52 | # include for local directory 53 | 54 | # include for local package 55 | 56 | 57 | # Creating entries for target: floorplan_generation_cli 58 | # ############################ 59 | 60 | if(UNIX) 61 | set(CMAKE_CXX_FLAGS "-Wno-c++11-extensions -std=c++11") 62 | endif(UNIX) 63 | 64 | if(${CMAKE_SYSTEM} MATCHES "Darwin") 65 | set( CMAKE_CXX_FLAGS "-Wno-c++11-extensions -Wno-gnu-static-float-init -Wno-sign-compare" ) 66 | endif(${CMAKE_SYSTEM} MATCHES "Darwin") 67 | 68 | 69 | add_executable( generate_floorplan_cli generate_floorplan_cli.cc ../base/floorplan.cc ) 70 | # add_to_cached_list( CGAL_EXECUTABLE_TARGETS floorplan_generation_cli ) 71 | target_link_libraries(generate_floorplan_cli ${CGAL_LIBRARIES} ${CGAL_3RD_PARTY_LIBRARIES} ) 72 | target_link_libraries(generate_floorplan_cli gflags ) 73 | -------------------------------------------------------------------------------- /not_used/floorplan/generate_floorplan_cli.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "../base/file_io.h" 10 | #include "../base/floorplan.h" 11 | 12 | using namespace Eigen; 13 | using namespace std; 14 | using namespace structured_indoor_modeling; 15 | 16 | void PrintRoom(const Floorplan& floorplan, const int room, ofstream& ofstr) { 17 | ofstr << "" << endl; 30 | } 31 | 32 | void PrintDoor(const Floorplan& floorplan, const int door, ofstream& ofstr) { 33 | ofstr << "" << endl; 70 | 71 | ofstr << "" << endl; 74 | ofstr << "" << endl; 77 | } 78 | 79 | int main(int argc, char* argv[]) { 80 | if (argc < 2) { 81 | cerr << "Usage: " << argv[0] << " data_directory" << endl; 82 | return 1; 83 | } 84 | 85 | #ifdef __APPLE__ 86 | google::ParseCommandLineFlags(&argc, &argv, true); 87 | #else 88 | gflags::ParseCommandLineFlags(&argc, &argv, true); 89 | #endif 90 | 91 | FileIO file_io(argv[1]); 92 | 93 | Floorplan floorplan; 94 | { 95 | ifstream ifstr; 96 | ifstr.open(file_io.GetFloorplan().c_str()); 97 | //ifstr.open(file_io.GetFloorplanFinal().c_str()); 98 | ifstr >> floorplan; 99 | ifstr.close(); 100 | } 101 | 102 | { 103 | ofstream ofstr; 104 | ofstr.open(file_io.GetFloorplanSVG().c_str()); 105 | ofstr << "" << endl; 106 | 107 | // Rooms. 108 | for (int room = 0; room < floorplan.GetNumRooms(); ++room) { 109 | PrintRoom(floorplan, room, ofstr); 110 | } 111 | 112 | // Doors. 113 | for (int door = 0; door < floorplan.GetNumDoors(); ++door) { 114 | PrintDoor(floorplan, door, ofstr); 115 | } 116 | 117 | ofstr << "" << endl; 118 | ofstr.close(); 119 | } 120 | 121 | return 0; 122 | } 123 | -------------------------------------------------------------------------------- /not_used/floorplan/old/floorplan.h.bak: -------------------------------------------------------------------------------- 1 | #ifndef FLOORPLAN_H__ 2 | #define FLOORPLAN_H__ 3 | 4 | #include 5 | #include 6 | 7 | //---------------------------------------------------------------------- 8 | // Input data. 9 | //---------------------------------------------------------------------- 10 | struct LineRoom { 11 | std::vector walls; 12 | double floor_height; 13 | double ceiling_height; 14 | }; 15 | 16 | struct LineDoorFace { 17 | int room_id; 18 | int wall_id; 19 | // Eigen::Vector2d position_ratio; 20 | Eigen::Vector2d left; 21 | Eigen::Vector2d right; 22 | double bottom_height; 23 | double top_height; 24 | }; 25 | 26 | typedef std::pair LineDoor; 27 | 28 | struct LineFloorplan { 29 | // Each room is an array of 2D coordinates. 30 | std::vector line_rooms; 31 | // Door connections. 32 | std::vector line_doors; 33 | }; 34 | 35 | //---------------------------------------------------------------------- 36 | // Output data. 37 | //---------------------------------------------------------------------- 38 | struct Appearance { 39 | enum Type { 40 | Color, 41 | CrossTexture 42 | }; 43 | 44 | Type type; 45 | Eigen::Vector3f color; 46 | }; 47 | 48 | struct Face { 49 | Eigen::Vector2d positions[3]; 50 | }; 51 | 52 | struct RoomInterior { 53 | Appearance appearance; 54 | // A set of faces. 55 | std::vector faces; 56 | }; 57 | 58 | typedef std::vector RoomBoundary; 59 | 60 | struct Door { 61 | // ??? To be determined 62 | }; 63 | 64 | // Floorplan drawing consists of the following information. 65 | // #0. Floor height. 66 | // #1. Outer boundaries of union. 67 | // #2. Inner boundaries of union. 68 | // #3. Room interior (faces). 69 | // #4. Doors. 70 | struct Floorplan { 71 | // #0. 72 | double floor_height; 73 | // #1. 74 | std::vector outer_boundaries; 75 | // #2. 76 | std::vector inner_boundaries; 77 | // #3. 78 | std::vector room_interiors; 79 | // #4. 80 | std::vector doors; 81 | }; 82 | 83 | std::istream& operator>>(std::istream& istr, LineFloorplan& line_floorplan); 84 | 85 | std::istream& operator>>(std::istream& istr, Floorplan& floorplan); 86 | std::ostream& operator<<(std::ostream& ostr, const Floorplan& floorplan); 87 | 88 | #endif // FLOORPLAN_H__ 89 | -------------------------------------------------------------------------------- /not_used/floorplan/old/floorplan_util.h: -------------------------------------------------------------------------------- 1 | #ifndef FLOORPLAN_UTIL_H__ 2 | #define FLOORPLAN_UTIL_H__ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "../base/floorplan.h" 10 | 11 | namespace structured_indoor_modeling { 12 | 13 | typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel; 14 | typedef Kernel::Point_2 Point_2; 15 | typedef CGAL::Polygon_2 Polygon_2; 16 | typedef CGAL::Polygon_with_holes_2 Polygon_with_holes_2; 17 | typedef CGAL::Polygon_set_2 Polygon_set_2; 18 | // typedef CGAL::General_polygon_with_holes_2 General_polygon_with_holes_2; 19 | // typedef std::list Pwh_list_2; 20 | 21 | 22 | // Conversion from the input to the output. 23 | void ConvertLineFloorplanToFloorplan(const LineFloorplan& line_floorplan, 24 | const double outward_thickness, 25 | const double inward_thickness, 26 | Floorplan* floorplan); 27 | 28 | void PolygonSetToFloorplanComponents(const Polygon_set_2& polygon_set, Floorplan* floorplan); 29 | 30 | void FloorplanToSVG(const Floorplan& floorplan, 31 | const std::string filename, 32 | const std::string filename2); 33 | 34 | } // namespace structured_indoor_modeling 35 | 36 | #endif // FLOORPLAN_UTIL_H__ 37 | -------------------------------------------------------------------------------- /not_used/floorplan/old/sample.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #include 11 | 12 | using namespace std; 13 | 14 | typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel; 15 | typedef Kernel::Point_2 Point_2; 16 | typedef CGAL::Polygon_2 Polygon_2; 17 | typedef CGAL::Polygon_with_holes_2 Polygon_with_holes_2; 18 | typedef CGAL::General_polygon_with_holes_2 General_polygon_with_holes_2; 19 | // typedef std::list Pwh_list_2; 20 | 21 | 22 | template 23 | void print_polygon(const CGAL::Polygon_2& P) { 24 | typename CGAL::Polygon_2::Vertex_const_iterator vit; 25 | 26 | cout << "[ " << P.size() << " vertices: "; 27 | for (vit = P.vertices_begin(); vit != P.vertices_end(); ++vit) 28 | cout << " (" << *vit << ')'; 29 | cout << " ]" << endl; 30 | } 31 | 32 | 33 | template 34 | void print_polygon_with_holes(const CGAL::Polygon_with_holes_2 & pwh) 35 | { 36 | if (! pwh.is_unbounded()) { 37 | std::cout << "{ Outer boundary = "; 38 | print_polygon (pwh.outer_boundary()); 39 | } else 40 | std::cout << "{ Unbounded polygon." << std::endl; 41 | typename CGAL::Polygon_with_holes_2::Hole_const_iterator hit; 42 | unsigned int k = 1; 43 | std::cout << " " << pwh.number_of_holes() << " holes:" << std::endl; 44 | for (hit = pwh.holes_begin(); hit != pwh.holes_end(); ++hit, ++k) { 45 | std::cout << " Hole #" << k << " = "; 46 | print_polygon (*hit); 47 | } 48 | std::cout << " }" << std::endl; 49 | } 50 | 51 | // Take room outline 1D polygons (with doors?), thicken walls, and generate 2D polygons. 52 | int main(int argc, char* argv[]) { 53 | if (argc < 3) { 54 | cerr << "Usage: " << argv[0] << " inptu_data output_data" << endl; 55 | exit (1); 56 | } 57 | 58 | { 59 | Polygon_2 P; 60 | P.push_back (Point_2 (0,0)); 61 | P.push_back (Point_2 (5,0)); 62 | P.push_back (Point_2 (3.5,1.5)); 63 | P.push_back (Point_2 (2.5,0.5)); 64 | P.push_back (Point_2 (1.5,1.5)); 65 | 66 | Polygon_2 Q; 67 | Q.push_back(Point_2 (0, 2)); 68 | Q.push_back(Point_2 (1.5, 0.5)); 69 | Q.push_back(Point_2 (2.5, 1.5)); 70 | Q.push_back(Point_2 (3.5, 0.5)); 71 | Q.push_back(Point_2 (5, 2)); 72 | 73 | Polygon_with_holes_2 unionR; 74 | if (CGAL::join(P, Q, unionR)) { 75 | print_polygon_with_holes(unionR); 76 | // exit (1); 77 | } 78 | } 79 | 80 | 81 | Polygon_2 P; 82 | P.push_back (Point_2 (1,0)); 83 | P.push_back (Point_2 (1,3)); 84 | P.push_back (Point_2 (0,3)); 85 | P.push_back (Point_2 (0,0)); 86 | 87 | Polygon_2 Q; 88 | Q.push_back(Point_2 (3, 2)); 89 | Q.push_back(Point_2 (3, 3)); 90 | Q.push_back(Point_2 (0, 3)); 91 | Q.push_back(Point_2 (0, 2)); 92 | 93 | Polygon_2 R; 94 | R.push_back(Point_2 (2, 0)); 95 | R.push_back(Point_2 (3, 0)); 96 | R.push_back(Point_2 (3, 3)); 97 | R.push_back(Point_2 (2, 3)); 98 | 99 | Polygon_2 S; 100 | S.push_back(Point_2 (3, 0)); 101 | S.push_back(Point_2 (3, 1)); 102 | S.push_back(Point_2 (0, 1)); 103 | S.push_back(Point_2 (0, 0)); 104 | 105 | 106 | Polygon_with_holes_2 union0; 107 | Polygon_with_holes_2 union1, union2; 108 | if (CGAL::join(P, Q, union0)) { 109 | print_polygon_with_holes(union0); 110 | 111 | if (CGAL::join(union0, R, union1)) { 112 | print_polygon_with_holes(union1); 113 | 114 | if (CGAL::join(union1, S, union2)) { 115 | print_polygon_with_holes(union2); 116 | cout << union2 << endl; 117 | 118 | } 119 | } 120 | } 121 | /* 122 | 123 | 124 | if (CGAL::join (P, Q, unionR)) { 125 | std::cout << "The union: "; 126 | print_polygon_with_holes (unionR); 127 | } else 128 | std::cout << "P and Q are disjoint and their union is trivial." 129 | << std::endl; 130 | std::cout << std::endl; 131 | */ 132 | 133 | return 0; 134 | } 135 | -------------------------------------------------------------------------------- /not_used/floorplan/polygon_triangulation2.h: -------------------------------------------------------------------------------- 1 | #ifndef CGAL_POLYGON_TRIANGULATION2_H__ 2 | #define CGAL_POLYGON_TRIANGULATION2_H__ 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | 13 | namespace Cgal { 14 | typedef float Coord_type; 15 | typedef CGAL::Point_2 > Point_2; 16 | typedef CGAL::Delaunay_triangulation_2 > Delaunay2; 17 | 18 | typedef CGAL::Constrained_Delaunay_triangulation_2 > CDelaunay2; 19 | 20 | void Triangulate(const std::vector& points, 21 | std::vector* triangles); 22 | 23 | }; 24 | 25 | #endif // CGAL_POLYGON_TRIANGULATION2_H__ 26 | -------------------------------------------------------------------------------- /not_used/segmentation/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8) 2 | project( segmentation_cli ) 3 | find_package( OpenCV REQUIRED ) 4 | # FIND_PACKAGE( Ceres REQUIRED ) 5 | # INCLUDE_DIRECTORIES( ${CERES_INCLUDE_DIRS} ) 6 | 7 | LINK_DIRECTORIES( /usr/local/lib ) 8 | 9 | if(UNIX) 10 | set(CMAKE_CXX_FLAGS "-Wno-c++11-extensions -std=c++11") 11 | endif(UNIX) 12 | 13 | if(${CMAKE_SYSTEM} MATCHES "Darwin") 14 | set( CMAKE_CXX_FLAGS "-Wno-c++11-extensions -Wno-gnu-static-float-init -Wno-sign-compare" ) 15 | endif(${CMAKE_SYSTEM} MATCHES "Darwin") 16 | 17 | 18 | add_executable( segmentation_cli segmentation_cli.cc data.cc segmentation.cc evidence.cc ) 19 | target_link_libraries( segmentation_cli ${OpenCV_LIBS} ) 20 | 21 | # target_link_libraries( segmentation_cli ceres ) 22 | # target_link_libraries( segmentation_cli gflags ) 23 | # target_link_libraries( segmentation_cli glog ) 24 | -------------------------------------------------------------------------------- /not_used/segmentation/data.cc: -------------------------------------------------------------------------------- 1 | #include "data.h" 2 | 3 | using namespace Eigen; 4 | using namespace std; 5 | 6 | namespace structured_indoor_modeling { 7 | 8 | Eigen::Vector3d Frame::ToLocalPosition(const Eigen::Vector3d& position) const { 9 | return Eigen::Vector3d((position.dot(axes[0]) - ranges[0][0]) / unit, 10 | (position.dot(axes[1]) - ranges[1][0]) / unit, 11 | (position.dot(axes[2]) - ranges[2][0]) / unit); 12 | } 13 | 14 | Eigen::Vector3d Frame::ToLocalNormal(const Eigen::Vector3d& normal) const { 15 | return Eigen::Vector3d(normal.dot(axes[0]), 16 | normal.dot(axes[1]), 17 | normal.dot(axes[2])).normalized(); 18 | } 19 | 20 | std::istream& operator>>(std::istream& istr, Frame& frame) { 21 | std::string header; 22 | istr >> header; 23 | for (int a = 0; a < 3; ++a) 24 | for (int i = 0; i < 3; ++i) 25 | istr >> frame.axes[a][i]; 26 | 27 | for (int a = 0; a < 3; ++a) 28 | for (int i = 0; i < 2; ++i) 29 | istr >> frame.ranges[a][i]; 30 | 31 | for (int i = 0; i < 3; ++i) 32 | istr >> frame.size[i]; 33 | 34 | istr >> frame.unit; 35 | 36 | return istr; 37 | }; 38 | 39 | std::ostream& operator<<(std::ostream& ostr, const Frame& frame) { 40 | ostr << "FRAME" << std::endl; 41 | for (int a = 0; a < 3; ++a) { 42 | for (int i = 0; i < 3; ++i) { 43 | ostr << frame.axes[a][i] << ' '; 44 | } 45 | ostr << std::endl; 46 | } 47 | 48 | for (int a = 0; a < 3; ++a) { 49 | for (int i = 0; i < 2; ++i) { 50 | ostr << frame.ranges[a][i] << ' '; 51 | } 52 | ostr << std::endl; 53 | } 54 | 55 | for (int i = 0; i < 3; ++i) 56 | ostr << frame.size[i] << ' '; 57 | ostr << std::endl; 58 | 59 | ostr << frame.unit << std::endl; 60 | 61 | return ostr; 62 | }; 63 | 64 | Eigen::Vector3d ConvertPoint(const Eigen::Vector3d& point, 65 | const Eigen::Matrix4d& transformation) { 66 | Vector4d point4(point[0], point[1], point[2], 1.0); 67 | point4 = transformation * point4; 68 | return Vector3d(point4[0], point4[1], point4[2]); 69 | } 70 | 71 | Eigen::Vector3d ConvertNormal(const Eigen::Vector3d& normal, 72 | const Eigen::Matrix4d& transformation) { 73 | Vector4d normal4(normal[0], normal[1], normal[2], 0.0); 74 | normal4 = transformation * normal4; 75 | return Vector3d(normal4[0], normal4[1], normal4[2]); 76 | } 77 | 78 | } // namespace structured_indoor_modeling 79 | -------------------------------------------------------------------------------- /not_used/segmentation/data.h: -------------------------------------------------------------------------------- 1 | #ifndef DATA_H_ 2 | #define DATA_H_ 3 | 4 | #include 5 | #include 6 | 7 | namespace structured_indoor_modeling { 8 | 9 | struct OrientedPoint { 10 | Eigen::Vector3d position; 11 | Eigen::Vector3d normal; 12 | // Angular resolution is not equal in a depth scan. 13 | float weight; 14 | }; 15 | 16 | struct Sweep { 17 | Eigen::Vector3d center; 18 | std::vector points; 19 | }; 20 | 21 | struct Frame { 22 | Eigen::Vector3d axes[3]; 23 | Eigen::Vector2f ranges[3]; 24 | Eigen::Vector3i size; 25 | float unit; 26 | 27 | Eigen::Vector3d ToLocalPosition(const Eigen::Vector3d& position) const; 28 | Eigen::Vector3d ToLocalNormal(const Eigen::Vector3d& normal) const; 29 | }; 30 | 31 | std::istream& operator>>(std::istream& istr, Frame& frame); 32 | std::ostream& operator<<(std::ostream& ostr, const Frame& frame); 33 | 34 | Eigen::Vector3d ConvertPoint(const Eigen::Vector3d& point, 35 | const Eigen::Matrix4d& transformation); 36 | 37 | Eigen::Vector3d ConvertNormal(const Eigen::Vector3d& normal, 38 | const Eigen::Matrix4d& transformation); 39 | 40 | } // namespace structured_indoor_modeling 41 | 42 | #endif // DATA_H_ 43 | -------------------------------------------------------------------------------- /not_used/segmentation/evidence.h: -------------------------------------------------------------------------------- 1 | #ifndef SEGMENTATION_EVIDENCE_H_ 2 | #define SEGMENTATION_EVIDENCE_H_ 3 | 4 | #include 5 | #include 6 | 7 | #include "data.h" 8 | 9 | namespace structured_indoor_modeling { 10 | 11 | void LoadEvidence(const std::string& filename, std::vector* evidence); 12 | void WriteEvidence(const std::string& filename, const std::vector& evidence); 13 | 14 | void LoadEvidence3(const std::string& filename, std::vector* evidence); 15 | void WriteEvidence3(const std::string& filename, const std::vector& evidence); 16 | 17 | void SetPointEvidence(const std::vector& sweeps, 18 | const Frame& frame, 19 | const std::string& directory, 20 | std::vector* point_evidence); 21 | 22 | void SetPointEvidence(const std::vector& sweeps, 23 | const Frame& frame, 24 | const std::string& directory, 25 | std::vector* point_evidence, 26 | std::vector* normal_evidence); 27 | 28 | void SetFreeSpaceEvidence(const std::vector& sweeps, 29 | const Frame& frame, 30 | const std::string& directory, 31 | std::vector* free_space_evidence); 32 | 33 | void DrawEvidenceToImage(const Frame& frame, 34 | const std::string directory, 35 | const std::vector& point_evidence, 36 | const std::vector& free_space_evidence); 37 | 38 | double ScalePointEvidence(const double input); 39 | 40 | double ScaleFreeSpaceEvidence(const double input); 41 | 42 | void ConvertEvidence(const int width, 43 | const int height, 44 | const std::vector& evidence, 45 | const double scale, 46 | std::vector* evidence_int); 47 | 48 | } // namespace structured_indoor_modeling 49 | 50 | #endif // SEGMENTATION_EVIDENCE_H_ 51 | -------------------------------------------------------------------------------- /not_used/segmentation/segmentation.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "data.h" 5 | #include "../base/file_io.h" 6 | 7 | namespace structured_indoor_modeling { 8 | 9 | void ReadSweeps(const FileIO& file_io, 10 | std::vector* sweeps); 11 | 12 | void NormalizeIntensity(const double min_sigma, 13 | const double max_sigma, 14 | Sweep* sweep); 15 | 16 | void ConvertSweepFromLocalToGlobal(const Eigen::Matrix4d& local_to_global, 17 | Sweep* sweep); 18 | 19 | void RotateSweep(const double angle, Sweep* sweep); 20 | 21 | float ComputeAverageDistance(const std::vector& sweeps); 22 | 23 | void InitializeFrame(const bool recompute, 24 | const std::string directory, 25 | const std::vector& sweeps, 26 | const float average_distance, 27 | Frame* frame); 28 | 29 | void ComputeFrame(const std::string directory, 30 | const std::vector& sweeps, 31 | const float average_distance, 32 | Frame* frame); 33 | 34 | void SetRanges(const std::vector& sweeps, 35 | const float average_distance, 36 | Frame* frame); 37 | 38 | void InitializeEvidence(const bool recompute, 39 | const std::vector& sweeps, 40 | const Frame& frame, 41 | const std::string directory, 42 | std::vector* point_evidence, 43 | std::vector* free_space_evidence, 44 | std::vector* normal_evidence); 45 | 46 | } // namespace structured_indoor_modeling 47 | -------------------------------------------------------------------------------- /not_used/segmentation/segmentation_cli.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "data.h" 8 | #include "segmentation.h" 9 | #include "../base/file_io.h" 10 | 11 | using namespace Eigen; 12 | using namespace structured_indoor_modeling; 13 | using namespace std; 14 | 15 | const double kMinSigmaIntensity = -2.5; 16 | const double kMaxSigmaIntensity = 1.0; 17 | 18 | int main(int argc, char* argv[]) { 19 | if (argc < 2) { 20 | cerr << "Usage: " << argv[0] << "data_directory [recompute] [rotation_angle_degrees]" << endl; 21 | exit (1); 22 | } 23 | 24 | FileIO file_io(argv[1]); 25 | vector sweeps; 26 | ReadSweeps(file_io, &sweeps); 27 | for (auto& sweep : sweeps) { 28 | NormalizeIntensity(kMinSigmaIntensity, kMaxSigmaIntensity, &sweep); 29 | } 30 | if (argc > 4) { 31 | const double angle = atof(argv[3]) * M_PI / 180.0; 32 | for (auto& sweep : sweeps) { 33 | RotateSweep(angle, &sweep); 34 | } 35 | } 36 | 37 | bool recompute = false; 38 | if (argc < 3) { 39 | if (atoi(argv[2])) 40 | recompute = true; 41 | } 42 | 43 | const float average_distance = ComputeAverageDistance(sweeps); 44 | cout << average_distance << endl; 45 | 46 | Frame frame; 47 | InitializeFrame(recompute, argv[1], sweeps, average_distance, &frame); 48 | 49 | vector point_evidence, free_space_evidence; 50 | vector normal_evidence; 51 | InitializeEvidence(recompute, sweeps, frame, argv[1], 52 | &point_evidence, 53 | &free_space_evidence, 54 | &normal_evidence); 55 | 56 | // do real compu 57 | 58 | return 0; 59 | } 60 | -------------------------------------------------------------------------------- /not_used/segmentation_old/Makefile: -------------------------------------------------------------------------------- 1 | all: door_detection_cli refine_segmentation_cli 2 | 3 | ###################################################################### 4 | CXX = clang++ 5 | 6 | CXXFLAGS = -O2 -Wall -Wno-deprecated -Wno-c++11-extensions -I/usr/local/Cellar/boost/1.54.0/include -I/usr/local/Cellar/boost/1.53.0/include -I/usr/local/include -D_GLIBCXX_DEBUG 7 | 8 | SRC = door_detection_cli.cc door_detection.cc evidence.cc transform.cc ../base/ply/points.cc ../base/imageProcess/morphological_operation.cc 9 | MYLDFLAGS = ./libMRF.a 10 | door_detection_cli: ${SRC} 11 | ${CXX} ${LDFLAGS} ${MYLDFLAGS} ${CXXFLAGS} -o $@ ${SRC} ${LDFLAGS} 12 | 13 | SRC2 = refine_segmentation_cli.cc refine_segmentation.cc door_detection.cc evidence.cc ../base/imageProcess/morphological_operation.cc 14 | MYLDFLAGS2 = ./libMRF.a 15 | 16 | refine_segmentation_cli: ${SRC2} 17 | ${CXX} ${LDFLAGS} ${MYLDFLAGS2} ${CXXFLAGS} -o $@ ${SRC2} ${LDFLAGS} 18 | 19 | ###################################################################### 20 | # implicit rules 21 | #% : %.o 22 | # ${CXX} ${LDFLAGS} ${CXXFLAGS} -o $@ $^ ${LDFLAGS} 23 | 24 | #%.o : *.cc 25 | # ${CXX} -c ${CXXFLAGS} $< 26 | 27 | #%.o : ../base/patch/*.cc 28 | # ${CXX} -c ${CXXFLAGS} $< 29 | 30 | #%.o : ../base/numeric/*.cc 31 | # ${CXX} -c ${CXXFLAGS} $< 32 | 33 | 34 | #clang++ -std=c++11 -stdlib=libc++ -Weverything -Wno-sign-conversion -Wno-sign-compare -Wno-c++98-compat -Wno-unused-parameter -Wno-padded -o readSUN3D_cli readSUN3D_cli.cc readSUN3D.cc -ljpeg -lpng 35 | 36 | ###################################################################### 37 | clean: 38 | /bin/rm -f core core.* door_detection_cli refine_segmentation_cli *.o 39 | 40 | ###################################################################### 41 | depend: 42 | rm -f Dependencies 43 | for SOURCEFILE in `ls *.cc ../base/*/*.cc ../base/*/*.c ../base/*/*.C ../base/*/*.f`; do \ 44 | echo $$SOURCEFILE; \ 45 | $(CXX) -MM $(CXXFLAGS) $$SOURCEFILE >> Dependencies; \ 46 | done 47 | 48 | #-include Dependencies 49 | -------------------------------------------------------------------------------- /not_used/segmentation_old/data.h: -------------------------------------------------------------------------------- 1 | #ifndef FLOORED_DATA_H_ 2 | #define FLOORED_DATA_H_ 3 | 4 | #include 5 | 6 | namespace floored { 7 | 8 | struct OrientedPoint { 9 | Eigen::Vector3f position; 10 | Eigen::Vector3f normal; 11 | // Angular resolution is not equal in a depth scan. 12 | float weight; 13 | }; 14 | 15 | struct Sweep { 16 | Eigen::Vector3f center; 17 | std::vector points; 18 | }; 19 | 20 | struct Frame { 21 | Eigen::Vector3f axes[3]; 22 | Eigen::Vector2f ranges[3]; 23 | Eigen::Vector3i size; 24 | float unit; 25 | 26 | Eigen::Vector3f ToLocalPosition(const Eigen::Vector3f& position) const { 27 | return Eigen::Vector3f((position.dot(axes[0]) - ranges[0][0]) / unit, 28 | (position.dot(axes[1]) - ranges[1][0]) / unit, 29 | (position.dot(axes[2]) - ranges[2][0]) / unit); 30 | } 31 | Eigen::Vector3f ToLocalNormal(const Eigen::Vector3f& normal) const { 32 | return Eigen::Vector3f(normal.dot(axes[0]), 33 | normal.dot(axes[1]), 34 | normal.dot(axes[2])).normalized(); 35 | } 36 | }; 37 | 38 | struct Floorplan { 39 | enum SpaceType{ 40 | Inside, 41 | Outside 42 | }; 43 | 44 | int width; 45 | int height; 46 | std::vector in_out; 47 | }; 48 | 49 | inline std::istream& operator>>(std::istream& istr, Frame& frame) { 50 | std::string header; 51 | istr >> header; 52 | for (int a = 0; a < 3; ++a) 53 | for (int i = 0; i < 3; ++i) 54 | istr >> frame.axes[a][i]; 55 | 56 | for (int a = 0; a < 3; ++a) 57 | for (int i = 0; i < 2; ++i) 58 | istr >> frame.ranges[a][i]; 59 | 60 | for (int i = 0; i < 3; ++i) 61 | istr >> frame.size[i]; 62 | 63 | istr >> frame.unit; 64 | 65 | return istr; 66 | }; 67 | 68 | inline std::ostream& operator<<(std::ostream& ostr, const Frame& frame) { 69 | ostr << "FRAME" << std::endl; 70 | 71 | for (int a = 0; a < 3; ++a) { 72 | for (int i = 0; i < 3; ++i) { 73 | ostr << frame.axes[a][i] << ' '; 74 | } 75 | ostr << std::endl; 76 | } 77 | 78 | for (int a = 0; a < 3; ++a) { 79 | for (int i = 0; i < 2; ++i) { 80 | ostr << frame.ranges[a][i] << ' '; 81 | } 82 | ostr << std::endl; 83 | } 84 | 85 | for (int i = 0; i < 3; ++i) 86 | ostr << frame.size[i] << ' '; 87 | ostr << std::endl; 88 | 89 | ostr << frame.unit << std::endl; 90 | 91 | return ostr; 92 | }; 93 | 94 | } // namespace floored 95 | 96 | #endif // FLOORED_DATA_H_ 97 | -------------------------------------------------------------------------------- /not_used/segmentation_old/door_detection.h: -------------------------------------------------------------------------------- 1 | #ifndef ROOM_SEGMENTATION_DOOR_DETECTION_H_ 2 | #define ROOM_SEGMENTATION_DOOR_DETECTION_H_ 3 | 4 | #include 5 | #include "../base/ply/points.h" 6 | #include "data.h" 7 | 8 | namespace room_segmentation { 9 | void ConvertPointsToSweep(const ply::Points& points, floored::Sweep* sweep); 10 | 11 | void SetRanges(const std::vector& sweeps, 12 | const float average_distance, 13 | floored::Frame* frame); 14 | 15 | void ComputeFrame(const std::string directory, 16 | const std::vector& sweeps, 17 | const float average_distance, 18 | floored::Frame* frame); 19 | 20 | float ComputeAverageDistance(const std::vector& sweeps); 21 | 22 | void DetectDoors(const std::vector& sweeps, 23 | const floored::Frame& frame, 24 | const std::string directory, 25 | const std::vector& point_evidence, 26 | const std::vector& free_space_evidence, 27 | std::vector* door_detection); 28 | 29 | void WriteClustering(const int width, 30 | const int height, 31 | const std::vector& centers, 32 | const std::vector >& clusters, 33 | const int subsample, 34 | const std::string filename); 35 | 36 | void LoadClustering(const std::string filename, 37 | std::vector* centers, 38 | std::vector >* clusters); 39 | 40 | float VisibilityDistance(const std::vector >& lhs, 41 | const std::vector >& rhs); 42 | 43 | void WriteVisibility(const std::string& filename, 44 | const std::vector > >& visibility, 45 | const int width, 46 | const int height, 47 | const int subsample); 48 | void LoadVisibility(const std::string& filename, 49 | std::vector > >* visibility, 50 | int* width, 51 | int* height, 52 | int* subsample); 53 | 54 | 55 | } // namespace room_segmentation 56 | 57 | #endif // ROOM_SEGMENTATION_DOOR_DETECTION_H_ 58 | -------------------------------------------------------------------------------- /not_used/segmentation_old/door_detection_cli: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yasu-furukawa/2015_structured_indoor_modeling/81d69495014adb51a51b058afee2abfff76b801c/not_used/segmentation_old/door_detection_cli -------------------------------------------------------------------------------- /not_used/segmentation_old/door_detection_cli.sh: -------------------------------------------------------------------------------- 1 | ./door_detection_cli ~/Google_Drive/research/structured_indoor_modeling/data/equal-sky-0649/ 1 17.5 2 | ./door_detection_cli ~/Google_Drive/research/structured_indoor_modeling/data/new-breeze-6946/ 1 -16 3 | ./door_detection_cli ~/Google_Drive/research/structured_indoor_modeling/data/lumber-cashew-1997/ 4 | -------------------------------------------------------------------------------- /not_used/segmentation_old/dynamic_programming.h: -------------------------------------------------------------------------------- 1 | #ifndef FLOORED_DYNAMIC_PROGRAMMING_H_ 2 | #define FLOORED_DYNAMIC_PROGRAMMING_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | #include "data.h" 12 | 13 | namespace floored { 14 | 15 | void Reconstruct2DDP(const Frame& frame, 16 | const std::vector& point_evidence, 17 | const std::vector& free_space_evidence, 18 | const std::string& directory, 19 | Floorplan* floorplan); 20 | 21 | } // namespace floored 22 | 23 | #endif // FLOORED_DYNAMIC_PROGRAMMING_H_ 24 | -------------------------------------------------------------------------------- /not_used/segmentation_old/evidence.h: -------------------------------------------------------------------------------- 1 | #ifndef FLOORED_EVIDENCE_H_ 2 | #define FLOORED_EVIDENCE_H_ 3 | 4 | #include 5 | #include 6 | 7 | #include "data.h" 8 | 9 | namespace floored { 10 | 11 | void LoadEvidence(const std::string& filename, std::vector* evidence); 12 | void WriteEvidence(const std::string& filename, const std::vector& evidence); 13 | 14 | void LoadEvidence3(const std::string& filename, std::vector* evidence); 15 | void WriteEvidence3(const std::string& filename, const std::vector& evidence); 16 | 17 | void SetPointEvidence(const std::vector& sweeps, 18 | const Frame& frame, 19 | const std::string& directory, 20 | std::vector* point_evidence); 21 | 22 | void SetPointEvidence(const std::vector& sweeps, 23 | const Frame& frame, 24 | const std::string& directory, 25 | std::vector* point_evidence, 26 | std::vector* normal_evidence); 27 | 28 | void SetFreeSpaceEvidence(const std::vector& sweeps, 29 | const Frame& frame, 30 | const std::string& directory, 31 | std::vector* free_space_evidence); 32 | 33 | void DrawEvidenceToImage(const Frame& frame, 34 | const std::string directory, 35 | const std::vector& point_evidence, 36 | const std::vector& free_space_evidence); 37 | 38 | double ScalePointEvidence(const double input); 39 | 40 | double ScaleFreeSpaceEvidence(const double input); 41 | 42 | void ConvertEvidence(const int width, 43 | const int height, 44 | const std::vector& evidence, 45 | const double scale, 46 | std::vector* evidence_int); 47 | 48 | 49 | } // namespace floored 50 | 51 | #endif // FLOORED_EVIDENCE_H_ 52 | -------------------------------------------------------------------------------- /not_used/segmentation_old/libMRF.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yasu-furukawa/2015_structured_indoor_modeling/81d69495014adb51a51b058afee2abfff76b801c/not_used/segmentation_old/libMRF.a -------------------------------------------------------------------------------- /not_used/segmentation_old/preprocess.h: -------------------------------------------------------------------------------- 1 | #ifndef FLOORED_PREPROCESS_H_ 2 | #define FLOORED_PREPROCESS_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include "data.h" 9 | 10 | namespace floored { 11 | 12 | void ReadSweeps(const std::string directory, const int num, 13 | std::vector* sweeps); 14 | 15 | void FilterSweeps(const float lower_height, 16 | const float upper_height, 17 | std::vector* sweeps); 18 | 19 | void ComputeFrame(const std::string directory, 20 | const std::vector& sweeps, 21 | const float average_distance, 22 | Frame* frame); 23 | 24 | void RansacPlane(const std::vector& points, 25 | const Eigen::Vector3f& axis, 26 | const int iteration, 27 | const float threshold, 28 | Eigen::Vector3f* orthogonal_axis, 29 | std::vector* inliers); 30 | 31 | void WriteSweepsAsPly(const std::vector& sweeps, 32 | const std::string filename); 33 | 34 | float ComputeAverageDistance(const std::vector& sweeps); 35 | 36 | } // namespace floored 37 | 38 | #endif // FLOORED_PREPROCESS_H_ 39 | -------------------------------------------------------------------------------- /not_used/segmentation_old/reconstruct_2d.h: -------------------------------------------------------------------------------- 1 | #ifndef FLOORED_RECONSTRUCT_2D_H_ 2 | #define FLOORED_RECONSTRUCT_2D_H_ 3 | 4 | #include 5 | #include 6 | 7 | #include "data.h" 8 | 9 | namespace floored { 10 | 11 | void Reconstruct2D(const Frame& frame, 12 | const std::vector& point_evidence, 13 | const std::vector& free_space_evidence, 14 | const std::string& directory, 15 | Floorplan* floorplan); 16 | 17 | } // namespace floored 18 | 19 | #endif // FLOORED_RECONSTRUCT_2D_H_ 20 | -------------------------------------------------------------------------------- /not_used/segmentation_old/refine_segmentation.h: -------------------------------------------------------------------------------- 1 | #ifndef REFINE_SEGMENTATION_H_ 2 | #define REFINE_SEGMENTATION_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | #include "data.h" 8 | 9 | void NormalizeEvidence(const double min_sigma, 10 | const double max_sigma, 11 | std::vector* evidence); 12 | 13 | void DrawEvidence(const int width, const int height, 14 | const std::vector& evidence, 15 | const std::string& filename, 16 | const double scale); 17 | 18 | void DrawEvidence3(const int width, const int height, 19 | const Eigen::Vector3f& x_axis, 20 | const Eigen::Vector3f& y_axis, 21 | const std::vector& evidence, 22 | const std::string& filename); 23 | 24 | void RefineSegmentation(const floored::Frame& frame, 25 | const std::vector& point_evidence, 26 | const std::vector& free_space_evidence, 27 | const std::vector& normal_evidence, 28 | const std::vector& centers, 29 | const std::vector >& clusters, 30 | const std::vector > > visibility, 31 | std::vector* segmentation); 32 | 33 | void WriteSegmentation(const std::string& output_file, 34 | const std::vector& segmentation, 35 | const int width, 36 | const int height, 37 | const int num_label); 38 | 39 | void ExpandVisibility(const int width, const int height, 40 | std::vector > >* visibility); 41 | 42 | #endif // REFINE_SEGMENTATAION_H_ 43 | -------------------------------------------------------------------------------- /not_used/segmentation_old/refine_segmentation_cli: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yasu-furukawa/2015_structured_indoor_modeling/81d69495014adb51a51b058afee2abfff76b801c/not_used/segmentation_old/refine_segmentation_cli -------------------------------------------------------------------------------- /not_used/segmentation_old/refine_segmentation_cli.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | #include "refine_segmentation.h" 9 | #include "door_detection.h" 10 | #include "evidence.h" 11 | 12 | using namespace Eigen; 13 | using namespace std; 14 | using namespace floored; 15 | using namespace room_segmentation; 16 | 17 | int main(int argc, char* argv[]) { 18 | if (argc < 2) { 19 | cerr << "Usage: " << argv[0] 20 | << " directory_prefix" << endl 21 | << "./room_segmentation ../data/mobile/" << endl; 22 | return 1; 23 | } 24 | 25 | const string directory = argv[1]; 26 | 27 | Frame frame; 28 | { 29 | char buffer[1024]; 30 | sprintf(buffer, "%sframe.dat", directory.c_str()); 31 | ifstream ifstr; 32 | ifstr.open(buffer); 33 | ifstr >> frame; 34 | ifstr.close(); 35 | } 36 | 37 | vector point_evidence, free_space_evidence; 38 | vector normal_evidence; 39 | { 40 | const string point_evidence_filename = directory + "point_evidence.dat"; 41 | const string free_space_evidence_filename = directory + "free_space_evidence.dat"; 42 | const string normal_evidence_filename = directory + "normal_evidence.dat"; 43 | LoadEvidence(point_evidence_filename, &point_evidence); 44 | LoadEvidence(free_space_evidence_filename, &free_space_evidence); 45 | LoadEvidence3(normal_evidence_filename, &normal_evidence); 46 | { 47 | const double kMinSigma = -0.3; 48 | const double kMaxSigma = 0.0; 49 | NormalizeEvidence(kMinSigma, kMaxSigma, &point_evidence); 50 | } 51 | { 52 | const double kMinSigma = -0.75; 53 | const double kMaxSigma = 0.1; 54 | NormalizeEvidence(kMinSigma, kMaxSigma, &free_space_evidence); 55 | } 56 | const double kScale = 255.0; 57 | const string point_image = directory + "point_normalized.ppm"; 58 | DrawEvidence(frame.size[0], frame.size[1], point_evidence, point_image, kScale); 59 | const string free_space_image = directory + "free_space_normalized.ppm"; 60 | DrawEvidence(frame.size[0], frame.size[1], free_space_evidence, free_space_image, kScale); 61 | const string normal_image = directory + "normal_normalized.ppm"; 62 | DrawEvidence3(frame.size[0], frame.size[1], frame.axes[0], frame.axes[1], normal_evidence, normal_image); 63 | } 64 | 65 | vector centers; 66 | vector > clusters; 67 | { 68 | const string cluster_file = directory + "initial_cluster.dat"; 69 | LoadClustering(cluster_file, ¢ers, &clusters); 70 | } 71 | vector > > visibility; 72 | { 73 | const string visibility_file = directory + "visibility.dat"; 74 | int width, height, subsample; 75 | LoadVisibility(visibility_file, &visibility, &width, &height, &subsample); 76 | if (width != frame.size[0] || height != frame.size[1]) { 77 | cerr << "Incompatible dimension: " << width << ' ' << height << ' ' << frame.size[0] << ' ' << frame.size[1] << endl; 78 | exit (1); 79 | } 80 | ExpandVisibility(width, height, &visibility); 81 | } 82 | 83 | vector segmentation; 84 | RefineSegmentation(frame, point_evidence, free_space_evidence, normal_evidence, 85 | centers, clusters, visibility, &segmentation); 86 | 87 | { 88 | const string output_file = directory + "segmentation.ppm"; 89 | WriteSegmentation(output_file, segmentation, frame.size[0], frame.size[1], centers.size() + 1); 90 | } 91 | 92 | return 0; 93 | } 94 | -------------------------------------------------------------------------------- /not_used/segmentation_old/transform.cc: -------------------------------------------------------------------------------- 1 | #include "transform.h" 2 | 3 | #include 4 | #include 5 | 6 | using namespace Eigen; 7 | using namespace std; 8 | 9 | namespace floored { 10 | 11 | void ReadTransforms(const string directory, const int num, const int reference_num, 12 | vector* transforms) { 13 | transforms->clear(); 14 | for (int s = 1; s <= num; ++s) { 15 | // Identify matrix if s is a reference. 16 | if (s == reference_num) { 17 | transforms->push_back(Matrix4f::Identity()); 18 | } else { 19 | char buffer[1024]; 20 | sprintf(buffer, 21 | "%s/transforms/sweep_%03d_sweep_%03d.txt", 22 | directory.c_str(), s, reference_num); 23 | ifstream ifstr; 24 | ifstr.open(buffer); 25 | if (!ifstr.is_open()) { 26 | cerr << "Transform file does not exist: " << buffer; 27 | exit (1); 28 | } 29 | 30 | Matrix4f transform; 31 | for (int y = 0; y < 4; ++y) 32 | for (int x = 0; x < 4; ++x) 33 | ifstr >> transform(y, x);; 34 | 35 | transforms->push_back(transform); 36 | ifstr.close(); 37 | } 38 | } 39 | } 40 | 41 | Vector3f TransformPoint(const Matrix4f& transform, const Vector3f& point) { 42 | Vector4f point4(point[0], point[1], point[2], 1.0f); 43 | point4 = transform * point4; 44 | return Vector3f(point4[0], point4[1], point4[2]); 45 | } 46 | 47 | void TransformSweeps(const vector& transforms, 48 | vector* sweeps) { 49 | if (transforms.size() != sweeps->size()) { 50 | cerr << "Array dimensions do not agree: " << transforms.size() << ' ' << sweeps->size() << endl; 51 | exit (1); 52 | } 53 | 54 | for (int s = 0; s < transforms.size(); ++s) { 55 | for (auto& point : sweeps->at(s).points) { 56 | point.position = TransformPoint(transforms[s], point.position); 57 | point.normal = TransformPoint(transforms[s], point.normal); 58 | } 59 | sweeps->at(s).center = TransformPoint(transforms[s], sweeps->at(s).center); 60 | } 61 | } 62 | 63 | void ConvertSweepsToFrame(const Frame& frame, vector* sweeps) { 64 | for (auto& sweep : (*sweeps)) { 65 | for (auto& point : sweep.points) { 66 | point.position = frame.ToLocalPosition(point.position); 67 | point.normal = frame.ToLocalNormal(point.normal); 68 | } 69 | sweep.center = frame.ToLocalPosition(sweep.center); 70 | } 71 | } 72 | 73 | } // namespace floored 74 | -------------------------------------------------------------------------------- /not_used/segmentation_old/transform.h: -------------------------------------------------------------------------------- 1 | #ifndef FLOORED_TRANSFORM_H_ 2 | #define FLOORED_TRANSFORM_H_ 3 | 4 | #include 5 | #include 6 | #include "data.h" 7 | 8 | namespace floored { 9 | 10 | void ReadTransforms(const std::string directory, const int num, const int reference_num, 11 | std::vector* transforms); 12 | 13 | Eigen::Vector3f TransformPoint(const Eigen::Matrix4f& transform, const Eigen::Vector3f& point); 14 | 15 | void TransformSweeps(const std::vector& transforms, 16 | std::vector* sweeps); 17 | 18 | void ConvertSweepsToFrame(const Frame& frame, std::vector* sweeps); 19 | 20 | } // namespace floored 21 | 22 | #endif // FLOORED_TRANSFORM_H_ 23 | -------------------------------------------------------------------------------- /post_process/Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | cd evaluation; cmake .; make 3 | cd synthetic; cmake .; make 4 | cd collada; cmake .; make 5 | 6 | clean: 7 | cd evaluation; make clean 8 | cd synthetic; make clean 9 | cd collada; make clean 10 | -------------------------------------------------------------------------------- /post_process/collada/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8) 2 | project(collada) 3 | 4 | FIND_PACKAGE(OpenCV REQUIRED) 5 | 6 | link_directories(/usr/local/lib) 7 | 8 | if(UNIX) 9 | set(CMAKE_CXX_FLAGS "-Wno-c++11-extensions -std=c++11") 10 | endif(UNIX) 11 | 12 | if(${CMAKE_SYSTEM} MATCHES "Darwin") 13 | set( CMAKE_CXX_FLAGS "-Wno-c++11-extensions -Wno-gnu-static-float-init -Wno-sign-compare" ) 14 | endif(${CMAKE_SYSTEM} MATCHES "Darwin") 15 | 16 | if (WIN32) 17 | include_directories("C:\\Eigen3.2.2") 18 | include_directories("C:\\gflags-2.1.1\\include") 19 | link_directories("C:\\gflags-2.1.1\\lib") 20 | endif (WIN32) 21 | 22 | add_executable( indoor_polygon_to_dae_cli indoor_polygon_to_dae_cli.cc ../../base/indoor_polygon.cc ) 23 | target_link_libraries( indoor_polygon_to_dae_cli ${OpenCV_LIBS} ) 24 | target_link_libraries( indoor_polygon_to_dae_cli gflags ) 25 | -------------------------------------------------------------------------------- /post_process/collada/ming/ToDraw.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import getopt 3 | from Rhino import * 4 | from Rhino.DocObjects import * 5 | from Rhino.Geometry import * 6 | from Rhino.Input import * 7 | from Rhino.Commands import * 8 | from scriptcontext import doc 9 | import rhinoscriptsyntax as rs 10 | 11 | def clearRhino(): 12 | rs.DeleteObjects(rs.AllObjects()) 13 | 14 | def addWallRhino(corners, thickness, height): 15 | outWallCrv = rs.AddPolyline(corners) 16 | inWallCrv = rs.OffsetCurve(outWallCrv, [0,1,0], thickness, [0,0,1], CurveOffsetCornerStyle.Sharp) 17 | objs = [outWallCrv, inWallCrv] 18 | btmWall = rs.AddPlanarSrf(objs)[0] 19 | extrudeLine = rs.AddLine(corners[0],map(sum, zip(corners[0],[0,0,height]))) 20 | allWalls = rs.ExtrudeSurface(btmWall, extrudeLine, True) 21 | rs.DeleteObjects([outWallCrv,inWallCrv,btmWall,extrudeLine]) 22 | return allWalls 23 | 24 | def read(filename): 25 | with open(filename) as f: 26 | return [ map(float, line.split())+[0] for line in f] 27 | def addWall (filename, thickness, height): 28 | corners = read(filename) 29 | clearRhino() 30 | addWallRhino(corners, thickness, height) 31 | 32 | def main(): 33 | wall_height = 50 34 | wall_thickness = 0.2 35 | print('==============Generate Out Walls==============') 36 | addWall('blueprint_poly.txt', wall_thickness, wall_height) 37 | 38 | print('==============Add Inner Walls==============') 39 | addWall('innerwall_poly.txt', wall_thickness, wall_height) 40 | 41 | 42 | 43 | if __name__ == "__main__": 44 | main() 45 | -------------------------------------------------------------------------------- /post_process/collada/ming/ToDraw_red.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import getopt 3 | from Rhino import * 4 | from Rhino.DocObjects import * 5 | from Rhino.Geometry import * 6 | from Rhino.Input import * 7 | from Rhino.Commands import * 8 | from scriptcontext import doc 9 | import rhinoscriptsyntax as rs 10 | 11 | def clearRhino(): 12 | rs.DeleteObjects(rs.AllObjects()) 13 | 14 | def addWallRhino(corners, thickness, height): 15 | outWallCrv = rs.AddPolyline(corners) 16 | inWallCrv = rs.OffsetCurve(outWallCrv, [0,1,0], thickness, [0,0,1], CurveOffsetCornerStyle.Sharp) 17 | objs = [outWallCrv, inWallCrv] 18 | btmWall = rs.AddPlanarSrf(objs)[0] 19 | extrudeLine = rs.AddLine(corners[0],map(sum, zip(corners[0],[0,0,height]))) 20 | allWalls = rs.ExtrudeSurface(btmWall, extrudeLine, True) 21 | rs.DeleteObjects([outWallCrv,inWallCrv,btmWall,extrudeLine]) 22 | return allWalls 23 | 24 | def read(filename): 25 | with open(filename) as f: 26 | return [ map(float, line.split())+[0] for line in f] 27 | def addWall (filename, thickness, height): 28 | corners = read(filename) 29 | clearRhino() 30 | addWallRhino(corners, thickness, height) 31 | 32 | def main(): 33 | wall_height = 50 34 | wall_thickness = 2 35 | print('==============Generate Out Walls==============') 36 | addWall('blueprint_poly_red.txt', wall_thickness, wall_height) 37 | 38 | 39 | 40 | if __name__ == "__main__": 41 | main() 42 | -------------------------------------------------------------------------------- /post_process/collada/ming/blueprint_poly.txt: -------------------------------------------------------------------------------- 1 | 21.5 40.5 2 | 65.5 40.5 3 | 65.5 28.5 4 | 120.5 28.5 5 | 120.5 10.5 6 | 144.5 10.5 7 | 144.5 25.5 8 | 164.5 25.5 9 | 164.5 39.5 10 | 176.5 39.5 11 | 176.5 67.5 12 | 196.5 67.5 13 | 196.5 96.5 14 | 175.5 96.5 15 | 175.5 113.5 16 | 183.5 113.5 17 | 183.5 149.5 18 | 96.5 149.5 19 | 96.5 182.5 20 | 196.5 182.5 21 | 196.5 212.5 22 | 174.5 212.5 23 | 174.5 230.5 24 | 197.5 230.5 25 | 197.5 258.5 26 | 174.5 258.5 27 | 174.5 268.5 28 | 164.5 268.5 29 | 164.5 279.5 30 | 101.5 279.5 31 | 101.5 291.5 32 | 164.5 291.5 33 | 164.5 289.5 34 | 174.5 289.5 35 | 174.5 333.5 36 | 168.5 333.5 37 | 168.5 343.5 38 | 174.5 343.5 39 | 174.5 347.5 40 | 190.5 347.5 41 | 190.5 379.5 42 | 174.5 379.5 43 | 174.5 385.5 44 | 164.5 385.5 45 | 164.5 406.5 46 | 174.5 406.5 47 | 174.5 407.5 48 | 189.5 407.5 49 | 189.5 439.5 50 | 174.5 439.5 51 | 174.5 459.5 52 | 189.5 459.5 53 | 189.5 492.5 54 | 174.5 492.5 55 | 174.5 511.5 56 | 188.5 511.5 57 | 188.5 521.5 58 | 130.5 521.5 59 | 130.5 514.5 60 | 56.5 514.5 61 | 56.5 521.5 62 | 49.5 521.5 63 | 49.5 463.5 64 | 81.5 463.5 65 | 81.5 435.5 66 | 68.5 435.5 67 | 68.5 209.5 68 | 49.5 209.5 69 | 49.5 174.5 70 | 65.5 174.5 71 | 65.5 140.5 72 | 49.5 140.5 73 | 49.5 139.5 74 | 21.5 139.5 75 | 21.5 40.5 76 | -------------------------------------------------------------------------------- /post_process/collada/ming/blueprint_poly_red.txt: -------------------------------------------------------------------------------- 1 | 20.5 25.5 2 | 20.5 157.5 3 | 86.5 157.5 4 | 86.5 167.5 5 | 23.5 167.5 6 | 23.5 178.5 7 | 39.5 178.5 8 | 39.5 226.5 9 | 84.5 226.5 10 | 84.5 227.5 11 | 129.5 227.5 12 | 129.5 194.5 13 | 136.5 194.5 14 | 136.5 226.5 15 | 135.5 226.5 16 | 135.5 259.5 17 | 129.5 259.5 18 | 129.5 255.5 19 | 85.5 255.5 20 | 85.5 298.5 21 | 130.5 298.5 22 | 130.5 289.5 23 | 136.5 289.5 24 | 136.5 306.5 25 | 84.5 306.5 26 | 84.5 455.5 27 | 307.5 455.5 28 | 307.5 360.5 29 | 302.5 360.5 30 | 302.5 347.5 31 | 313.5 347.5 32 | 313.5 306.5 33 | 197.5 306.5 34 | 197.5 319.5 35 | 179.5 319.5 36 | 179.5 299.5 37 | 197.5 299.5 38 | 197.5 297.5 39 | 339.5 297.5 40 | 339.5 310.5 41 | 371.5 310.5 42 | 371.5 297.5 43 | 384.5 297.5 44 | 384.5 178.5 45 | 332.5 178.5 46 | 332.5 171.5 47 | 386.5 171.5 48 | 386.5 30.5 49 | 316.5 30.5 50 | 316.5 130.5 51 | 308.5 130.5 52 | 308.5 30.5 53 | 236.5 30.5 54 | 236.5 25.5 55 | 151.5 25.5 56 | 151.5 34.5 57 | 157.5 34.5 58 | 157.5 127.5 59 | 149.5 127.5 60 | 149.5 34.5 61 | 81.5 34.5 62 | 81.5 43.5 63 | 67.5 43.5 64 | 67.5 25.5 65 | 20.5 25.5 66 | -------------------------------------------------------------------------------- /post_process/collada/ming/innerwall_poly.txt: -------------------------------------------------------------------------------- 1 | 21.5 40.5 2 | 65.5 40.5 3 | 65.5 28.5 4 | 120.5 28.5 5 | 120.5 10.5 6 | 144.5 10.5 7 | 144.5 25.5 8 | 164.5 25.5 9 | 164.5 39.5 10 | 176.5 39.5 11 | 176.5 67.5 12 | 196.5 67.5 13 | 196.5 96.5 14 | 175.5 96.5 15 | 175.5 113.5 16 | 183.5 113.5 17 | 183.5 149.5 18 | 96.5 149.5 19 | 96.5 237.5 20 | 99.5 237.5 21 | 99.5 182.5 22 | 196.5 182.5 23 | 196.5 212.5 24 | 174.5 212.5 25 | 174.5 230.5 26 | 197.5 230.5 27 | 197.5 258.5 28 | 174.5 258.5 29 | 174.5 268.5 30 | 164.5 268.5 31 | 164.5 279.5 32 | 101.5 279.5 33 | 101.5 291.5 34 | 164.5 291.5 35 | 164.5 289.5 36 | 174.5 289.5 37 | 174.5 333.5 38 | 168.5 333.5 39 | 168.5 343.5 40 | 174.5 343.5 41 | 174.5 347.5 42 | 190.5 347.5 43 | 190.5 379.5 44 | 174.5 379.5 45 | 174.5 385.5 46 | 164.5 385.5 47 | 164.5 406.5 48 | 174.5 406.5 49 | 174.5 407.5 50 | 189.5 407.5 51 | 189.5 439.5 52 | 174.5 439.5 53 | 174.5 443.5 54 | 105.5 443.5 55 | 105.5 448.5 56 | 174.5 448.5 57 | 174.5 459.5 58 | 189.5 459.5 59 | 189.5 492.5 60 | 174.5 492.5 61 | 174.5 511.5 62 | 188.5 511.5 63 | 188.5 521.5 64 | 130.5 521.5 65 | 130.5 514.5 66 | 56.5 514.5 67 | 56.5 521.5 68 | 49.5 521.5 69 | 49.5 463.5 70 | 81.5 463.5 71 | 81.5 435.5 72 | 68.5 435.5 73 | 68.5 209.5 74 | 49.5 209.5 75 | 49.5 174.5 76 | 65.5 174.5 77 | 65.5 140.5 78 | 49.5 140.5 79 | 49.5 139.5 80 | 21.5 139.5 81 | 21.5 40.5 82 | -------------------------------------------------------------------------------- /post_process/evaluation/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8) 2 | project(evaluate) 3 | 4 | FIND_PACKAGE(OpenCV REQUIRED) 5 | 6 | link_directories(/usr/local/lib) 7 | 8 | if(UNIX) 9 | set(CMAKE_CXX_FLAGS "-Wno-c++11-extensions -std=c++11") 10 | endif(UNIX) 11 | 12 | if(${CMAKE_SYSTEM} MATCHES "Darwin") 13 | set( CMAKE_CXX_FLAGS "-Wno-c++11-extensions -Wno-gnu-static-float-init -Wno-sign-compare" ) 14 | endif(${CMAKE_SYSTEM} MATCHES "Darwin") 15 | 16 | if (WIN32) 17 | include_directories("C:\\Eigen3.2.2") 18 | include_directories("C:\\gflags-2.1.1\\include") 19 | link_directories("C:\\gflags-2.1.1\\lib") 20 | endif (WIN32) 21 | 22 | add_executable( evaluate_cli evaluate_cli.cc evaluate.cc ../../base/floorplan.cc ../../base/indoor_polygon.cc ../../base/panorama.cc ../../base/point_cloud.cc ) 23 | target_link_libraries( evaluate_cli ${OpenCV_LIBS} ) 24 | target_link_libraries( evaluate_cli gflags ) 25 | 26 | add_executable( prepare_poisson_cli prepare_poisson_cli.cc ../../base/point_cloud.cc ) 27 | target_link_libraries( prepare_poisson_cli ${OpenCV_LIBS} ) 28 | target_link_libraries( prepare_poisson_cli gflags ) 29 | -------------------------------------------------------------------------------- /post_process/evaluation/evaluate.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | namespace structured_indoor_modeling { 6 | 7 | enum GeometryType { 8 | kFloor, 9 | kCeiling, 10 | kWall, 11 | kDoor, 12 | 13 | kObject, 14 | 15 | kHole 16 | }; 17 | 18 | struct RasterizedGeometry { 19 | RasterizedGeometry(const double depth, 20 | const Eigen::Vector3d& normal, 21 | const GeometryType& geometry_type) 22 | : depth(depth), normal(normal), geometry_type(geometry_type) { 23 | } 24 | double depth; 25 | Eigen::Vector3d normal; 26 | GeometryType geometry_type; 27 | }; 28 | 29 | struct Mesh { 30 | std::vector vertices; 31 | std::vector faces; 32 | GeometryType geometry_type; 33 | }; 34 | 35 | class FileIO; 36 | class Floorplan; 37 | class IndoorPolygon; 38 | class Panorama; 39 | class PointCloud; 40 | 41 | Eigen::Vector3d GetLaserCenter(const FileIO& file_io, const int panorama); 42 | 43 | void Initialize(const std::vector& panoramas, 44 | const RasterizedGeometry& initial_value, 45 | std::vector >* rasterized_geometries); 46 | 47 | void RasterizeFloorplan(const Floorplan& floorplan, 48 | const std::vector& panoramas, 49 | std::vector >* rasterized_geometries); 50 | 51 | void RasterizeIndoorPolygon(const IndoorPolygon& indoor_polygon, 52 | const std::vector& panoramas, 53 | std::vector >* rasterized_geometries); 54 | 55 | void RasterizeObjectPointClouds(const std::vector& object_point_clouds, 56 | const std::vector& panoramas, 57 | std::vector >* rasterized_geometries); 58 | 59 | bool ReadMesh(const std::string& filename, Mesh* mesh); 60 | bool ReadMeshAscii(const std::string& filename, Mesh* mesh); 61 | bool ReadMeshBinary(const std::string& filename, Mesh* mesh); 62 | 63 | void RasterizeMesh(const Mesh& mesh, 64 | const std::vector& panoramas, 65 | std::vector >* rasterized_geometries); 66 | 67 | void ReportErrors(const FileIO& file_io, 68 | const std::string& prefix, 69 | const std::vector& input_point_clouds, 70 | const std::vector >& rasterized_geometries, 71 | const std::vector& panoramas, 72 | const RasterizedGeometry& initial_value, 73 | const double depth_unit); 74 | 75 | } // namespace structured_indoor_modeling 76 | 77 | -------------------------------------------------------------------------------- /post_process/evaluation/prepare_poisson_cli.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | #include "../../base/file_io.h" 9 | #include "../../base/point_cloud.h" 10 | 11 | #ifdef _WIN32 12 | #pragma comment (lib, "gflags.lib") 13 | #pragma comment (lib, "Shlwapi.lib") 14 | #endif 15 | 16 | using namespace Eigen; 17 | using namespace std; 18 | using namespace structured_indoor_modeling; 19 | 20 | int main(int argc, char* argv[]) { 21 | if (argc < 2) { 22 | cerr << "Usage: " << argv[0] << " data_directory" << endl; 23 | return 1; 24 | } 25 | #ifdef __APPLE__ 26 | google::ParseCommandLineFlags(&argc, &argv, true); 27 | #else 28 | gflags::ParseCommandLineFlags(&argc, &argv, true); 29 | #endif 30 | 31 | FileIO file_io(argv[1]); 32 | const int num_panoramas = GetNumPanoramas(file_io); 33 | vector > oriented_points; 34 | for (int panorama = 0; panorama < num_panoramas; ++panorama) { 35 | PointCloud point_cloud; 36 | point_cloud.Init(file_io, panorama); 37 | point_cloud.ToGlobal(file_io, panorama); 38 | for (int p = 0; p < point_cloud.GetNumPoints(); ++p) { 39 | const Point& point = point_cloud.GetPoint(p); 40 | vector oriented_point; 41 | for (int i = 0; i < 3; ++i) 42 | oriented_point.push_back(point.position[i]); 43 | for (int i = 0; i < 3; ++i) 44 | oriented_point.push_back(point.normal[i]); 45 | oriented_points.push_back(oriented_point); 46 | } 47 | } 48 | 49 | ofstream ofstr; 50 | ofstr.open(file_io.GetPoissonInput().c_str()); 51 | for (const auto& oriented_point : oriented_points) { 52 | for (const auto& value : oriented_point) 53 | ofstr << value << ' '; 54 | ofstr << endl; 55 | } 56 | ofstr.close(); 57 | 58 | return 0; 59 | } 60 | -------------------------------------------------------------------------------- /post_process/evaluation/run_synthetic.sh: -------------------------------------------------------------------------------- 1 | ./evaluate_cli ~/Box_Sync/research/structured_indoor_modeling/data/synthetic0/ --evaluate_all=true 2 | ./evaluate_cli ~/Box_Sync/research/structured_indoor_modeling/data/synthetic1/ --evaluate_all=true 3 | ./evaluate_cli ~/Box_Sync/research/structured_indoor_modeling/data/synthetic2/ --evaluate_all=true 4 | ./evaluate_cli ~/Box_Sync/research/structured_indoor_modeling/data/synthetic3/ --evaluate_all=true 5 | ./evaluate_cli ~/Box_Sync/research/structured_indoor_modeling/data/synthetic4/ --evaluate_all=true 6 | ./evaluate_cli ~/Box_Sync/research/structured_indoor_modeling/data/synthetic5/ --evaluate_all=true 7 | -------------------------------------------------------------------------------- /post_process/synthetic/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8) 2 | project(generate_synthetic_data_cli) 3 | 4 | FIND_PACKAGE(OpenCV REQUIRED) 5 | 6 | LINK_DIRECTORIES(/usr/local/lib) 7 | 8 | if(UNIX) 9 | set(CMAKE_CXX_FLAGS "-Wno-c++11-extensions -std=c++11") 10 | endif(UNIX) 11 | 12 | if(${CMAKE_SYSTEM} MATCHES "Darwin") 13 | set( CMAKE_CXX_FLAGS "-Wno-c++11-extensions -Wno-gnu-static-float-init -Wno-sign-compare" ) 14 | endif(${CMAKE_SYSTEM} MATCHES "Darwin") 15 | 16 | if (WIN32) 17 | include_directories("C:\\Eigen3.2.2") 18 | include_directories("C:\\gflags-2.1.1\\include") 19 | link_directories("C:\\gflags-2.1.1\\lib") 20 | endif (WIN32) 21 | 22 | add_executable( generate_synthetic_data_cli generate_synthetic_data_cli.cc ) 23 | TARGET_LINK_LIBRARIES( generate_synthetic_data_cli ${OpenCV_LIBS} ) 24 | TARGET_LINK_LIBRARIES( generate_synthetic_data_cli gflags ) 25 | 26 | -------------------------------------------------------------------------------- /pre_process/Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | cd calibration; cmake .; make 3 | 4 | clean: 5 | cd calibration; make clean 6 | -------------------------------------------------------------------------------- /pre_process/calibration/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8) 2 | project(align_images_cli) 3 | find_package( OpenCV REQUIRED ) 4 | FIND_PACKAGE(Ceres REQUIRED) 5 | # FIND_PACKAGE(gflags REQUIRED) 6 | INCLUDE_DIRECTORIES(${CERES_INCLUDE_DIRS}) 7 | LINK_DIRECTORIES(/usr/local/lib) 8 | 9 | if(UNIX) 10 | set(CMAKE_CXX_FLAGS "-Wno-c++11-extensions -std=c++11") 11 | endif(UNIX) 12 | 13 | if(${CMAKE_SYSTEM} MATCHES "Darwin") 14 | set( CMAKE_CXX_FLAGS "-Wno-c++11-extensions -Wno-gnu-static-float-init -Wno-sign-compare" ) 15 | endif(${CMAKE_SYSTEM} MATCHES "Darwin") 16 | 17 | set(CMAKE_CXX_FLAGS "-Wno-c++11-extensions") 18 | add_executable( align_images_cli align_images_cli.cc align_images.cc transformation.cc ) 19 | target_link_libraries( align_images_cli ${OpenCV_LIBS} ) 20 | TARGET_LINK_LIBRARIES(align_images_cli ceres) 21 | TARGET_LINK_LIBRARIES(align_images_cli gflags) 22 | TARGET_LINK_LIBRARIES(align_images_cli glog) 23 | 24 | add_executable( align_panorama_to_depth_cli align_panorama_to_depth_cli.cc transformation.cc depthmap_refiner.cc ) 25 | target_link_libraries( align_panorama_to_depth_cli ${OpenCV_LIBS} ) 26 | TARGET_LINK_LIBRARIES(align_panorama_to_depth_cli ceres) 27 | TARGET_LINK_LIBRARIES(align_panorama_to_depth_cli gflags) 28 | TARGET_LINK_LIBRARIES(align_panorama_to_depth_cli glog) 29 | 30 | 31 | add_executable( render_ply_to_panorama_cli render_ply_to_panorama_cli.cc transformation.cc depthmap_refiner.cc ) 32 | target_link_libraries( render_ply_to_panorama_cli ${OpenCV_LIBS} ) 33 | TARGET_LINK_LIBRARIES( render_ply_to_panorama_cli ceres) 34 | TARGET_LINK_LIBRARIES( render_ply_to_panorama_cli gflags) 35 | 36 | add_executable( generate_depthmaps_cli generate_depthmaps_cli.cc ../../base/panorama.cc ../../base/point_cloud.cc ) 37 | target_link_libraries( generate_depthmaps_cli ${OpenCV_LIBS} ) 38 | TARGET_LINK_LIBRARIES( generate_depthmaps_cli ceres) 39 | TARGET_LINK_LIBRARIES( generate_depthmaps_cli gflags) 40 | -------------------------------------------------------------------------------- /pre_process/calibration/alignment.m: -------------------------------------------------------------------------------- 1 | function alignment(image_filename, ply_filename, points_filename) 2 | 3 | %clear all; 4 | %close all; 5 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 6 | % Alignment tool 7 | % Input ply format should be [ud, vd, X, Y, Z, r, g, b, nx, ny, nz, I] 8 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 9 | 10 | %display('Choose the input image...') 11 | %[ImgName, PathName] = uigetfile({'*.jpeg;*.jpg;*.png', 'Image Files (*.jpeg,*.jpg,*.png)'},'Select the jpeg image file'); 12 | %img = imread(sprintf('%s/%s',PathName,ImgName)); 13 | img = imread(image_filename); 14 | 15 | %display('Choose the input ply file...') 16 | %[PlyName, PathName] = uigetfile({'*.ply', 'PLY File (*.ply)'},'Select the PLY file'); 17 | %ply = simple_read_ply(sprintf('%s/%s',PathName,PlyName)); 18 | ply = simple_read_ply(ply_filename); 19 | 20 | if size(ply,2) ~= 12 21 | error('Invalid File Format!!') 22 | end 23 | 24 | cam_center = [0 0 0]; %ply(1, 3:5); 25 | pos = ply(1:end,3:5); 26 | 27 | depth = bsxfun(@minus, pos, cam_center); 28 | depth = (sqrt(sum((depth.^2)')))'; 29 | 30 | h = max(ply(1:end,1)); 31 | w = max(ply(1:end,2)); 32 | index = (ply(1:end,2)-1)*h + ply(1:end,1); 33 | 34 | depthmap = zeros(h,w); 35 | depthmap(index) = depth/max(depth(:)); 36 | 37 | %% clicking 38 | display('Plese indicate the corresponding points (ESC: compute the projection matrix, BS: remove the points from the list)') 39 | xlist1 = []; 40 | xlist2 = []; 41 | count = 1; 42 | while(1) 43 | figure(1), imagesc(min(depthmap,0.5)), colormap(jet(256)), axis equal; 44 | title(sprintf('%d-th point',count)) 45 | 46 | if count >= 2 47 | hold on 48 | plot(xlist1(:,1),xlist1(:,2),'go') 49 | hold off 50 | end 51 | 52 | figure(2), imshow(img), axis equal; 53 | title(sprintf('%d-th point',count)) 54 | 55 | if count >= 2 56 | hold on 57 | plot(xlist2(:,1),xlist2(:,2),'go') 58 | hold off 59 | end 60 | 61 | figure(1), 62 | [X,Y, key] = ginput(1); 63 | 64 | 65 | if key == 27 66 | display(sprintf('%d pairs are selected!!...',count-1)) 67 | break; 68 | end 69 | 70 | if key == 8 71 | xlist1 = xlist1(1:end-1,:); 72 | xlist2 = xlist2(1:end-1,:); 73 | display(sprintf('%d th points are removed from the lists', count-1)) 74 | count = max(1, count - 1); 75 | continue; 76 | end 77 | 78 | xlist1(count,1) = floor(X); 79 | xlist1(count,2) = floor(Y); 80 | 81 | hold on 82 | plot(X,Y,'ro') 83 | hold off 84 | 85 | figure(2), 86 | [X,Y, key] = ginput(1); 87 | 88 | if key == 27 89 | display(sprintf('%d pairs are selected!!...',count-1)) 90 | break; 91 | end 92 | 93 | if key == 8 94 | xlist1 = xlist1(1:end-1,:); 95 | display(sprintf('%d th points are removed from the lists', count-1)) 96 | continue; 97 | end 98 | 99 | xlist2(count,1) = floor(X); 100 | xlist2(count,2) = floor(Y); 101 | 102 | hold on 103 | plot(X,Y,'go') 104 | hold off 105 | 106 | display(sprintf('%d th point pair : [%d %d] and [%d %d]', count, xlist1(count,1), xlist1(count,2), xlist2(count,1), xlist2(count,2))) 107 | count = count + 1; 108 | end 109 | 110 | %% save file 111 | A = zeros(count-1,5); 112 | for i = 1 : count-1 113 | depth_index = find(index==(xlist1(i,1)-1)*h+xlist1(i,2)); 114 | A(i,1) = pos(depth_index,1); 115 | A(i,2) = pos(depth_index,2); 116 | A(i,3) = pos(depth_index,3); 117 | A(i,4) = xlist2(i,1); 118 | A(i,5) = xlist2(i,2); 119 | end 120 | 121 | %[file,path] = uiputfile('points.txt','Save file name'); 122 | %fid = fopen(sprintf('%s/%s',path,file),'w'); 123 | fid = fopen(points_filename, 'w'); 124 | fprintf(fid, '%g %g %g %g %g\n', A'); 125 | fclose(fid); 126 | close all 127 | -------------------------------------------------------------------------------- /pre_process/calibration/alignment_batch.m: -------------------------------------------------------------------------------- 1 | function alignment_batch(data_directory, start_index, end_index) 2 | 3 | dynamic_range = 3; 4 | 5 | for p = start_index:end_index 6 | image_filename = sprintf('%s/panorama/%03d_img_%d.png', data_directory, p, dynamic_range); 7 | ply_filename = sprintf('%s/ply/%03d.ply', data_directory, p); 8 | points_filename = sprintf('%s/calibration/%03d.points', data_directory, p); 9 | 10 | alignment(image_filename, ply_filename, points_filename); 11 | end 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /pre_process/calibration/depthmap_refiner.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "depthmap_refiner.h" 6 | 7 | using namespace std; 8 | 9 | namespace structured_indoor_modeling { 10 | 11 | void FillHolesAndSmooth(const int width, const int height, const double invalid, 12 | std::vector* depths) { 13 | int valid_count = 0, invalid_count = 0; 14 | for (const auto value : *depths) { 15 | if (value == invalid) 16 | ++invalid_count; 17 | else 18 | ++valid_count; 19 | } 20 | 21 | // Number of variables. 22 | const int num_vars = width * height; 23 | // Number of constraints 24 | const int num_constraints = width * height + valid_count; 25 | //Eigen::SparseMatrix A(num_constraints, num_vars); 26 | Eigen::SparseMatrix A(num_constraints, num_vars); 27 | 28 | const double kDataCost = 1.0; 29 | 30 | Eigen::VectorXd b(num_constraints); 31 | // Data constraints. 32 | vector > triplets; 33 | triplets.reserve(4 * width * height + valid_count); 34 | int index = 0; 35 | int constraint_index = 0; 36 | for (int y = 0; y < height; ++y) { 37 | for (int x = 0; x < width; ++x, ++index) { 38 | if (depths->at(index) == invalid) 39 | continue; 40 | // A.insert(index, index) = kDataCost; 41 | triplets.push_back(Eigen::Triplet(constraint_index, index, kDataCost)); 42 | b[constraint_index] = kDataCost * depths->at(index); 43 | ++constraint_index; 44 | } 45 | } 46 | // Regularization. 47 | index = 0; 48 | for (int y = 0; y < height; ++y) { 49 | for (int x = 0; x < width; ++x, ++index) { 50 | vector neighbor_indexes; 51 | if (x != width - 1) 52 | neighbor_indexes.push_back(index + 1); 53 | if (x != 0) 54 | neighbor_indexes.push_back(index - 1); 55 | if (y != height - 1) 56 | neighbor_indexes.push_back(index + width); 57 | if (y != 0) 58 | neighbor_indexes.push_back(index - width); 59 | 60 | // A.insert(valid_count + index, index) = (int)neighbor_indexes.size(); 61 | triplets.push_back(Eigen::Triplet(valid_count + index, index, (int)neighbor_indexes.size())); 62 | for (const auto neighbor_index : neighbor_indexes) { 63 | // A.insert(valid_count + index, neighbor_index) = -1.0; 64 | triplets.push_back(Eigen::Triplet(valid_count + index, neighbor_index, -1)); 65 | } 66 | b[valid_count + index] = 0.0; 67 | } 68 | }/* 69 | Eigen::SparseQR, Eigen::AMDOrdering > solver; 70 | solver.analyzePattern(A); 71 | solver.factorize(A); 72 | Eigen::VectorXd x = solver.solve(b); 73 | */ 74 | A.setFromTriplets(triplets.begin(), triplets.end()); 75 | 76 | Eigen::SparseMatrix ATA = A.transpose() * A; 77 | Eigen::VectorXd ATb = A.transpose() * b; 78 | 79 | /* 80 | Eigen::SimplicialCholesky > chol(ATA); 81 | Eigen::VectorXd x = chol.solve(ATb); 82 | */ 83 | Eigen::BiCGSTAB, Eigen::IncompleteLUT > solver(ATA); 84 | solver.preconditioner().setDroptol(0.1); 85 | //solver.setMaxIterations(300); 86 | Eigen::VectorXd x = solver.solve(ATb); 87 | 88 | for (int i = 0; i < depths->size(); ++i) 89 | depths->at(i) = x[i]; 90 | } 91 | 92 | } // namespace structured_indoor_modeling 93 | 94 | -------------------------------------------------------------------------------- /pre_process/calibration/depthmap_refiner.h: -------------------------------------------------------------------------------- 1 | #ifndef DEPTHMAP_REFINER_H__ 2 | #define DEPTHMAP_REFINER_H__ 3 | 4 | #include 5 | 6 | namespace structured_indoor_modeling { 7 | 8 | void FillHolesAndSmooth(const int width, const int height, const double invalid, 9 | std::vector* depths); 10 | 11 | } // namespace structured_indoor_modeling 12 | 13 | #endif // DEPTHMAP_REFINER_H__ 14 | -------------------------------------------------------------------------------- /pre_process/calibration/simple_read_ply.m: -------------------------------------------------------------------------------- 1 | function A = simple_read_ply(Path) 2 | 3 | [fid,Msg] = fopen(Path,'rt'); % open file in read text mode 4 | if fid == -1, error(Msg); end 5 | 6 | Buf = fscanf(fid,'%s',1); 7 | if ~strcmp(Buf,'ply') 8 | fclose(fid); 9 | error('Not a PLY file.'); 10 | end 11 | 12 | 13 | %% read headers 14 | NumProperties = 0; 15 | PropertyNames = []; % structure of lists of property names 16 | LengthHeader = 0; 17 | isEndheader = 0; 18 | 19 | while(1) 20 | 21 | Buf = fgetl(fid); % read one line from file 22 | BufRem = Buf; 23 | Token = {}; 24 | 25 | Count = 0; 26 | LengthHeader = LengthHeader + 1; 27 | while ~isempty(BufRem) % split line into tokens 28 | [tmp,BufRem] = strtok(BufRem); 29 | if ~isempty(tmp) 30 | Count = Count + 1; % count tokens 31 | Token{Count} = tmp; 32 | end 33 | end 34 | 35 | if Count 36 | switch lower(Token{1}) 37 | case 'format' % read data format 38 | if Count >= 2 39 | Format = lower(Token{2}); 40 | 41 | if Count == 3 & ~strcmp(Token{3},'1.0') 42 | fclose(fid); 43 | error('Only PLY format version 1.0 supported.'); 44 | end 45 | end 46 | case 'element' % element name 47 | if Count >= 3 48 | CurElement = Token{2}; 49 | ElementCount = str2double(Token{3}); 50 | end 51 | case 'property' % element property 52 | if ~isempty(CurElement) & Count >= 3 53 | NumProperties = NumProperties + 1; 54 | end 55 | case 'end_header' % end of header, break from while loop 56 | break; 57 | end 58 | end 59 | end 60 | 61 | 62 | %% read elements 63 | A = fscanf(fid, '%f'); 64 | A = (reshape(A, NumProperties, ElementCount))'; 65 | fclose(fid); 66 | 67 | end -------------------------------------------------------------------------------- /pre_process/calibration/transformation.cc: -------------------------------------------------------------------------------- 1 | #include "transformation.h" 2 | 3 | using namespace Eigen; 4 | 5 | namespace structured_indoor_modeling { 6 | 7 | Matrix3d RotationX(const double rx) { 8 | Matrix3d rotation; 9 | rotation << 1, 0, 0, 0, cos(rx), -sin(rx), 0, sin(rx), cos(rx); 10 | return rotation; 11 | } 12 | 13 | Matrix3d RotationY(const double ry) { 14 | Matrix3d rotation; 15 | rotation << cos(ry), 0, sin(ry), 0, 1, 0, -sin(ry), 0, cos(ry); 16 | return rotation; 17 | } 18 | 19 | Matrix3d RotationZ(const double rz) { 20 | Matrix3d rotation; 21 | rotation << cos(rz), -sin(rz), 0, sin(rz), cos(rz), 0, 0, 0, 1; 22 | return rotation; 23 | } 24 | 25 | void ConvertLocalToPanorama(const int panorama_width, const int panorama_height, 26 | const double phi_per_pixel, const Vector3d& ray, 27 | Vector2d* uv) { 28 | Vector3d normalized_ray = ray.normalized(); 29 | const double phi = asin(normalized_ray[2]); 30 | double theta = -atan2(ray[1], ray[0]); 31 | if (theta < 0.0) 32 | theta += 2 * M_PI; 33 | 34 | (*uv)[0] = theta / (2 * M_PI) * panorama_width; 35 | (*uv)[1] = panorama_height / 2.0 - phi / phi_per_pixel; 36 | } 37 | 38 | void ConvertPanoramaToLocal(const int panorama_width, const int panorama_height, 39 | const double phi_per_pixel, const Vector2d& uv, 40 | Vector3d* ray) { 41 | const double theta = uv[0] * 2 * M_PI / panorama_width; 42 | const double phi = (panorama_height / 2.0 - uv[1]) * phi_per_pixel; 43 | (*ray)[2] = sin(phi); 44 | (*ray)[1] = sin(-theta) * cos(phi); 45 | (*ray)[0] = cos(-theta) * cos(phi); 46 | } 47 | 48 | } // namespace structured_indoor_modeling 49 | -------------------------------------------------------------------------------- /pre_process/calibration/transformation.h: -------------------------------------------------------------------------------- 1 | #ifndef TRANSFORMATION_H__ 2 | #define TRANSFORMATION_H__ 3 | 4 | #include 5 | 6 | namespace structured_indoor_modeling { 7 | 8 | Eigen::Matrix3d RotationX(const double rx); 9 | Eigen::Matrix3d RotationY(const double ry); 10 | Eigen::Matrix3d RotationZ(const double rz); 11 | 12 | void ConvertLocalToPanorama(const int panorama_width, const int panorama_height, 13 | const double phi_per_pixel, const Eigen::Vector3d& ray, 14 | Eigen::Vector2d* uv); 15 | 16 | void ConvertPanoramaToLocal(const int panorama_width, const int panorama_height, 17 | const double phi_per_pixel, const Eigen::Vector2d& uv, 18 | Eigen::Vector3d* ray); 19 | 20 | } // namespace structured_indoor_modeling 21 | 22 | #endif // TRANSFORMATION_H__ 23 | -------------------------------------------------------------------------------- /pre_process/stitch_panorama/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8) 2 | 3 | project(stitch_panorama) 4 | find_package( OpenCV REQUIRED ) 5 | FIND_PACKAGE(Ceres REQUIRED) 6 | # FIND_PACKAGE(gflags REQUIRED) 7 | INCLUDE_DIRECTORIES(${CERES_INCLUDE_DIRS}) 8 | LINK_DIRECTORIES(/usr/local/lib) 9 | 10 | set( CMAKE_CXX_FLAGS "-Wno-c++11-extensions -Wno-gnu-static-float-init -Wno-sign-compare" ) 11 | #set( CMAKE_CXX_FLAGS "-Wno-c++11-extensions -Wno-gnu-static-float-init -Wno-sign-compare -fopenmp" ) 12 | 13 | set(CMAKE_C_COMPILER clang-omp CACHE STRING "C compiler" FORCE) 14 | set(CMAKE_CXX_COMPILER clang-omp++ CACHE STRING "C++ compiler" FORCE) 15 | 16 | #find_package(OpenMP REQUIRED) 17 | 18 | #set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}") 19 | #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") 20 | #set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}") 21 | 22 | 23 | 24 | add_executable(stitch_panorama_cli stitch_panorama_cli.cc ) 25 | target_link_libraries(stitch_panorama_cli stitch_panorama) 26 | target_link_libraries(stitch_panorama_cli ${OpenCV_LIBS} ) 27 | TARGET_LINK_LIBRARIES(stitch_panorama_cli ceres) 28 | TARGET_LINK_LIBRARIES(stitch_panorama_cli gflags) 29 | 30 | add_library(stitch_panorama stitch_panorama.cc stitch_panorama.h) 31 | -------------------------------------------------------------------------------- /pre_process/stitch_panorama/stitch_panorama.h: -------------------------------------------------------------------------------- 1 | #ifndef STITCH_PANORAMA_H_ 2 | #define STITCH_PANORAMA_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | namespace pre_process { 15 | 16 | class PatchCorrelationResidual; 17 | class RegularizationResidual; 18 | class RegularizationResidual2; 19 | class ManualSpecification; 20 | 21 | struct Input { 22 | std::string directory; 23 | // Pixel resolution. 24 | int out_width; 25 | int out_height; 26 | int level; 27 | int margin; 28 | int subsample; 29 | 30 | std::vector initial_rotations; 31 | }; 32 | 33 | struct Patch { 34 | // Top left corner. 35 | int x; 36 | int y; 37 | int size; 38 | 39 | std::vector indexes; 40 | }; 41 | 42 | class StitchPanorama { 43 | public: 44 | bool Stitch(const Input& input); 45 | 46 | const cv::Mat GetStitchedImage() const { return stitched_image; } 47 | 48 | const std::vector& GetRefinedRotations() const { return refined_rotations; } 49 | 50 | private: 51 | bool Init(const std::vector& initial_rotations); 52 | bool SetMasks(); 53 | 54 | bool RefineCameras(); 55 | void SamplePatches(); 56 | bool Blend(const std::string& filename); 57 | 58 | Eigen::Vector3d ScreenToRay(const Eigen::Vector2d& screen) const; 59 | Eigen::Vector2d RayToScreen(const Eigen::Vector3d& ray) const; 60 | // Return (x, y, depth). 61 | Eigen::Vector3d Project(const int camera, const Eigen::Vector3d& ray) const; 62 | 63 | // Input. 64 | std::string directory; 65 | int out_width; 66 | int out_height; 67 | int level; 68 | int margin; 69 | int subsample; 70 | 71 | int num_cameras; 72 | Eigen::Matrix3d intrinsics; 73 | std::vector rotations; 74 | std::vector projections; 75 | std::vector images; 76 | 77 | // Intermediate data. 78 | std::vector masks; 79 | std::vector patches; 80 | 81 | // Output. 82 | std::vector refined_intrinsics; 83 | std::vector refined_rotations; 84 | 85 | cv::Mat stitched_image; 86 | 87 | friend class PatchCorrelationResidual; 88 | friend class RegularizationResidual; 89 | friend class RegularizationResidual2; 90 | friend class ManualSpecification; 91 | }; 92 | 93 | class PatchCorrelationResidual { 94 | public: 95 | PatchCorrelationResidual(const pre_process::StitchPanorama& stitch_panorama, 96 | const int x, 97 | const int y, 98 | const int size, 99 | const int index0, 100 | const int index1); 101 | 102 | template bool operator()(const T* const param0, const T* const param1, T* residual) const; 103 | 104 | bool GrabPatch(const int index, 105 | const Eigen::Matrix3d& projection, 106 | std::vector& patch) const; 107 | 108 | private: 109 | const pre_process::StitchPanorama& stitch_panorama_; 110 | int x_; 111 | int y_; 112 | int size_; 113 | int index0_; 114 | int index1_; 115 | }; 116 | 117 | } // namespace pre_process 118 | 119 | #endif // STITCH_PANORAMA_H_ 120 | -------------------------------------------------------------------------------- /pre_process/stitch_panorama/stitch_panorama_cli.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "stitch_panorama.h" 6 | #include 7 | 8 | using std::cerr; 9 | using std::endl; 10 | using std::ofstream; 11 | using std::vector; 12 | using pre_process::Input; 13 | using pre_process::StitchPanorama; 14 | 15 | int main(int argc, char* argv[]) { 16 | if (argc < 6) { 17 | cerr << argv[0] << " directory width height num_levels subsample" << endl; 18 | return 1; 19 | } 20 | 21 | const int width = atoi(argv[2]); 22 | const int height = atoi(argv[3]); 23 | const int num_levels = atoi(argv[4]); 24 | 25 | Input input; 26 | input.directory = argv[1]; 27 | input.subsample = atoi(argv[5]); 28 | 29 | vector previous_rotations; 30 | for (int level = num_levels - 1; level >= 0; --level) { 31 | StitchPanorama stitch_panorama; 32 | input.level = level; 33 | input.out_width = width / (1 << level); 34 | input.out_height = height / (1 << level); 35 | // Critical parameters. 36 | input.margin = (int)round(0.02 * input.out_height); 37 | input.initial_rotations = previous_rotations; 38 | 39 | if (!stitch_panorama.Stitch(input)) { 40 | cerr << "Failed." << endl; 41 | return 1; 42 | } 43 | previous_rotations = stitch_panorama.GetRefinedRotations(); 44 | 45 | char buffer[1024]; 46 | sprintf(buffer, "%s/IMU_rotation_new_%d.txt", input.directory.c_str(), level); 47 | ofstream ofstr; 48 | ofstr.open(buffer); 49 | if (!ofstr.is_open()) { 50 | cerr << "No IMU_rotation file." << endl; 51 | return 1; 52 | } 53 | ofstr << previous_rotations.size() << endl; 54 | for (const auto& mat : previous_rotations) { 55 | for (int y = 0; y < 3; ++y) { 56 | for (int x = 0; x < 3; ++x) { 57 | ofstr << mat(x, y) << ' '; 58 | } 59 | } 60 | ofstr << endl; 61 | } 62 | ofstr.close(); 63 | } 64 | 65 | return 0; 66 | } 67 | -------------------------------------------------------------------------------- /run.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | # Textures and images for viewer. 3 | ./main_process/texture/generate_texture_floorplan_cli $1 4 | ./main_process/texture/generate_texture_indoor_polygon_cli $1 5 | ./main_process/texture/generate_thumbnail_cli $1 6 | 7 | # Objects. 8 | ./main_process/object_segmentation/object_segmentation_cli $1 9 | ./main_process/object_refinement/Object_refinement $1 10 | ./main_process/object_detection/generate_object_icons_cli $1 11 | 12 | # Misc. 13 | ./post_process/collada/indoor_polygon_to_dae_cli $1 14 | ./post_process/evaluation/evaluate_cli $1 --evaluate_all='true' 15 | ./post_process/evaluation/prepare_poisson_cli $1 16 | -------------------------------------------------------------------------------- /run_texture_for_poisson_vgcut.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | ./main_process/texture/generate_texture_indoor_polygon_cli $1 --binary_ply='input/poisson/poisson1.ply' 3 | ./main_process/texture/generate_texture_indoor_polygon_cli $1 --binary_ply='input/poisson/poisson2.ply' 4 | ./main_process/texture/generate_texture_indoor_polygon_cli $1 --binary_ply='input/poisson/poisson3.ply' 5 | ./main_process/texture/generate_texture_indoor_polygon_cli $1 --binary_ply='input/poisson/poisson_filtered1.ply' 6 | ./main_process/texture/generate_texture_indoor_polygon_cli $1 --binary_ply='input/poisson/poisson_filtered2.ply' 7 | ./main_process/texture/generate_texture_indoor_polygon_cli $1 --binary_ply='input/poisson/poisson_filtered3.ply' 8 | ./main_process/texture/generate_texture_indoor_polygon_cli $1 --ascii_ply='input/vgcut/vgcut0.ply' 9 | ./main_process/texture/generate_texture_indoor_polygon_cli $1 --ascii_ply='input/vgcut/vgcut1.ply' 10 | ./main_process/texture/generate_texture_indoor_polygon_cli $1 --ascii_ply='input/vgcut/vgcut2.ply' 11 | ./main_process/texture/generate_texture_indoor_polygon_cli $1 --ascii_ply='input/vgcut/vgcut_filtered0.ply' 12 | ./main_process/texture/generate_texture_indoor_polygon_cli $1 --ascii_ply='input/vgcut/vgcut_filtered1.ply' 13 | ./main_process/texture/generate_texture_indoor_polygon_cli $1 --ascii_ply='input/vgcut/vgcut_filtered2.ply' 14 | -------------------------------------------------------------------------------- /script.sh: -------------------------------------------------------------------------------- 1 | #./delete_files.sh ~/Box_Sync/research/structured_indoor_modeling/data/lumber-cashew-1997/ 2 | ./run.sh ~/Box_Sync/research/structured_indoor_modeling/data/lumber-cashew-1997/ 3 | 4 | #./delete_files.sh ~/Box_Sync/research/structured_indoor_modeling/data/equal-sky-0649/ 5 | ./run.sh ~/Box_Sync/research/structured_indoor_modeling/data/equal-sky-0649/ 6 | 7 | #./delete_files.sh ~/Box_Sync/research/structured_indoor_modeling/data/red-lion-9567/ 8 | ./run.sh ~/Box_Sync/research/structured_indoor_modeling/data/red-lion-9567/ 9 | 10 | #./delete_files.sh ~/Box_Sync/research/structured_indoor_modeling/data/salmon-palace-2313/ 11 | ./run.sh ~/Box_Sync/research/structured_indoor_modeling/data/salmon-palace-2313/ 12 | 13 | #./delete_files.sh ~/Box_Sync/research/structured_indoor_modeling/data/new-breeze-6946/ 14 | #./run.sh ~/Box_Sync/research/structured_indoor_modeling/data/new-breeze-6946/ 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /viewer/blend_fshader.glsl: -------------------------------------------------------------------------------- 1 | uniform sampler2D tex0; 2 | uniform sampler2D tex1; 3 | uniform float weight; 4 | uniform int divide_by_alpha; 5 | 6 | void main() { 7 | vec4 rgba0 = texture2D(tex0, gl_TexCoord[0].st); 8 | vec4 rgba1 = texture2D(tex1, gl_TexCoord[0].st); 9 | 10 | if (divide_by_alpha == 0) { 11 | gl_FragColor = rgba0 * weight + rgba1 * (1.0 - weight); 12 | } else if (divide_by_alpha == 1) { 13 | if (rgba0.r == 0.0 && rgba0.g == 0.0 && rgba0.b == 0.0) { 14 | gl_FragColor = rgba1; 15 | } else if (rgba1.r == 0.0 && rgba1.g == 0.0 && rgba1.b == 0.0) { 16 | gl_FragColor = rgba0; 17 | } else { 18 | gl_FragColor = rgba0 * weight + rgba1 * (1.0 - weight); 19 | } 20 | } else if (divide_by_alpha == 2) { 21 | if (rgba0.r == 0.0 && rgba0.g == 0.0 && rgba0.b == 0.0) { 22 | gl_FragColor = rgba1; 23 | } else { 24 | gl_FragColor = rgba0 * weight + rgba1 * (1.0 - weight); 25 | } 26 | } else { 27 | if (rgba1.r == 0.0 && rgba1.g == 0.0 && rgba1.b == 0.0) { 28 | gl_FragColor = rgba0; 29 | } else { 30 | gl_FragColor = rgba0 * weight + rgba1 * (1.0 - weight); 31 | } 32 | } 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | //gl_FragColor = texture2D(tex0, gl_TexCoord[0].st); 41 | // gl_FragColor = texture2D(tex0, vec2(0.5, 0.5)); 42 | /* 43 | gl_FragColor[0] = weight; 44 | gl_FragColor[1] = weight; 45 | gl_FragColor[2] = weight; 46 | */ 47 | // gl_FragColor[3] = 1.0; 48 | 49 | 50 | 51 | /* 52 | float suma = rgba0.a + rgba1.a; 53 | if (rgba0.a < 0.5) { 54 | gl_FragColor = vec4(1, 0, 0, 1); 55 | } 56 | else if (rgba0.a >= 0.5) { 57 | gl_FragColor = vec4(0, 1, 0, 1); 58 | } 59 | else { 60 | gl_FragColor[0] = (rgba0.r * rgba0.a + rgba1.r * rgba1.a) / suma; 61 | gl_FragColor[1] = (rgba0.g * rgba0.a + rgba1.g * rgba1.a) / suma; 62 | gl_FragColor[2] = (rgba0.b * rgba0.a + rgba1.b * rgba1.a) / suma; 63 | gl_FragColor[3] = 1.0; 64 | } 65 | */ 66 | 67 | /* 68 | vec2 coord = gl_TexCoord[0]; 69 | vec4 lhs = texture2D(sampler0, coord); 70 | vec4 rhs = texture2D(sampler1, coord); 71 | 72 | if (lhs[0] == 0 && lhs[1] == 0 && lhs[2] == 0) { 73 | gl_FragColor = rhs; 74 | } else if (rhs[0] == 0 && rhs[1] == 0 && rhs[2] == 0) { 75 | gl_FragColor = lhs; 76 | } else { 77 | gl_FragColor = weight * lhs + (1.0 - weight) * rhs; 78 | }*/ 79 | //gl_FragColor = weight * texture2D(sampler0, gl_TexCoord[0].xy) + (1.0 - weight) * texture2D(sampler1, gl_TexCoord[0].xy); 80 | // gl_FragColor = texture2D(sampler0, gl_TexCoord[0].st); 81 | 82 | //gl_FragColor.r = gl_TexCoord[0].s; 83 | } 84 | -------------------------------------------------------------------------------- /viewer/blend_vshader.glsl: -------------------------------------------------------------------------------- 1 | void main() 2 | { 3 | //gl_TexCoord[0] = gl_MultiTexCoord0; 4 | //gl_TexCoord[1] = gl_MultiTexCoord1; 5 | gl_Position = ftransform(); 6 | gl_TexCoord[0] = gl_MultiTexCoord0; 7 | } 8 | -------------------------------------------------------------------------------- /viewer/configuration.h: -------------------------------------------------------------------------------- 1 | #ifndef CONFIGURATION_H__ 2 | #define CONFIGURATION_H__ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | #include "../base/file_io.h" 11 | 12 | namespace structured_indoor_modeling { 13 | 14 | /* 15 | struct PanoramaConfiguration { 16 | std::string rgb_image_filename; 17 | std::string depth_image_filename; 18 | 19 | // Camera center. 20 | Eigen::Vector3d center; 21 | // Camera x, y, z axes. Each column is an axis. So this is a transformation from local to global. 22 | Eigen::Matrix3d local_to_global; 23 | // phi (in radian) per image y. 24 | double phi_range; 25 | }; 26 | */ 27 | 28 | struct Configuration { 29 | std::string data_directory; 30 | // std::vector panorama_configurations; 31 | 32 | // Parameters. 33 | double air_angle; 34 | double air_field_of_view_degrees; 35 | double floorplan_angle; 36 | double floorplan_field_of_view_degrees; 37 | }; 38 | 39 | /* 40 | void ReadPanoramaConfiguration(const std::string& data_directory, 41 | const int pano_index, 42 | PanoramaConfiguration* panorama_configuration); 43 | void ReadConfiguration(const std::string filename, Configuration* configuration); 44 | */ 45 | 46 | } // namespace structured_indoor_modeling 47 | 48 | #endif // CONFIGURATION_H__ 49 | -------------------------------------------------------------------------------- /viewer/indoor_polygon_renderer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace structured_indoor_modeling { 8 | 9 | class Floorplan; 10 | class IndoorPolygon; 11 | class Navigation; 12 | class ViewParameters; 13 | 14 | class IndoorPolygonRenderer : protected QGLFunctions { 15 | public: 16 | enum RenderMode { 17 | kFull, 18 | kBackWallFaceCulling, 19 | kBackWallFaceTransparent 20 | }; 21 | 22 | IndoorPolygonRenderer(const Floorplan& floorplan, 23 | const IndoorPolygon& indoor_polygon, 24 | const Navigation& navigation); 25 | virtual ~IndoorPolygonRenderer(); 26 | void RenderTextureMappedRooms(const double top_intensity, const double bottom_intensity); 27 | void RenderTextureMappedRooms(const double top_intensity, 28 | const double bottom_intensity, 29 | const ViewParameters& view_parameters, 30 | const double air_to_tree_progress, 31 | const double animation, 32 | const Eigen::Vector3d& max_vertical_shift) const; 33 | 34 | void Init(const std::string& data_directory, 35 | const std::string& suffix, 36 | QGLWidget* widget); 37 | void InitGL(); 38 | void ToggleRenderMode(); 39 | RenderMode GetRenderMode() const { return render_mode; } 40 | 41 | private: 42 | QGLWidget* widget; 43 | const Floorplan& floorplan; 44 | const IndoorPolygon& indoor_polygon; 45 | const Navigation& navigation; 46 | 47 | std::vector texture_images; 48 | std::vector texture_ids; 49 | 50 | // Floor outline. 51 | std::map > > wire_frames; 52 | 53 | RenderMode render_mode; 54 | 55 | double bottom_z; 56 | double top_z; 57 | }; 58 | 59 | } // namespace structured_indoor_modeling 60 | -------------------------------------------------------------------------------- /viewer/main_widget_util.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #ifdef __linux__ 10 | #include 11 | #elif _WIN32 12 | #include 13 | #include 14 | //#ifndef __glew_h__ 15 | //#include 16 | //#include 17 | //#endif 18 | #else 19 | #include 20 | #endif 21 | 22 | #include 23 | 24 | namespace structured_indoor_modeling { 25 | 26 | class Floorplan; 27 | class PanoramaRenderer; 28 | 29 | int FindPanoramaFromAirFloorplanClick(const std::vector& panorama_renderers, 30 | const Eigen::Vector2d& pixel, 31 | const GLint viewport[], 32 | const GLdouble modelview[], 33 | const GLdouble projection[]); 34 | 35 | /* 36 | double ProgressFunction(const double elapsed, 37 | const double offset, 38 | const double fade_in_seconds, 39 | const double fade_out_seconds); 40 | */ 41 | 42 | double AnimationTrapezoidUtil(const double elapsed, 43 | const double offset, 44 | const double fade_in_seconds, 45 | const double fade_out_seconds); 46 | 47 | double AnimationLinearUtil(const double elapsed, 48 | const double offset, 49 | const double fade_in_seconds, 50 | const double fade_out_seconds); 51 | 52 | void SetPanoramaToRoom(const Floorplan& floorplan, 53 | const std::vector& panorama_renderers, 54 | std::map* panorama_to_room); 55 | 56 | void SetRoomToPanorama(const Floorplan& floorplan, 57 | const std::vector& panorama_renderers, 58 | std::map* room_to_panorama); 59 | 60 | void SetPanoramaDistanceTable(const std::vector& panorama_renderers, 61 | std::vector >* panorama_distance_table); 62 | 63 | double ComputePanoramaDistance(const PanoramaRenderer& lhs, 64 | const PanoramaRenderer& rhs); 65 | 66 | void FindPanoramaPath(const std::vector& panorama_renderers, 67 | const std::vector >& panorama_distance_table, 68 | const int start_panorama, 69 | const int goal_panorama, 70 | std::vector* indexes); 71 | 72 | } // namespace structured_indoor_modeling 73 | -------------------------------------------------------------------------------- /viewer/panel_renderer.h: -------------------------------------------------------------------------------- 1 | #ifndef PANEL_RENDERER_H_ 2 | #define PANEL_RENDERER_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | namespace structured_indoor_modeling { 11 | 12 | class Floorplan; 13 | class MainWidget; 14 | 15 | class PanelRenderer : protected QGLFunctions { 16 | public: 17 | PanelRenderer(const Floorplan& floorplan, 18 | const GLint* viewport); 19 | virtual ~PanelRenderer(); 20 | void Init(const std::string& data_directory); 21 | void InitGL(MainWidget* main_widget); 22 | void RenderThumbnail(const double alpha, 23 | const int room_highlighted, 24 | const Eigen::Vector2i& render_pos, 25 | const Eigen::Vector3d& color, 26 | const double scale, 27 | QGLWidget* qgl_widget); 28 | const QImage& GetRoomThumbnail(const int room) { return room_thumbnails[room]; } 29 | 30 | static const double kWidthRatio; 31 | static const int kTextHeight; 32 | static const int kFrameMargin; 33 | 34 | private: 35 | std::vector room_thumbnails; 36 | const Floorplan& floorplan; 37 | const GLint* viewport; 38 | GLuint thumbnail_texid; 39 | }; 40 | 41 | } // namespace structured_indoor_modeling 42 | 43 | #endif // PANEL_RENDERER_H_ 44 | -------------------------------------------------------------------------------- /viewer/panorama_fshader.glsl: -------------------------------------------------------------------------------- 1 | uniform sampler2D tex0; 2 | uniform float phi_range; 3 | uniform float alpha; 4 | 5 | varying vec3 local; 6 | 7 | 8 | void main() { 9 | float PI = 3.1415926535897932384626433832795; 10 | 11 | float theta = - atan(local.y, local.x); 12 | if (theta < 0.0) { 13 | theta = theta + 2.0 * PI; 14 | } 15 | vec2 uv; 16 | 17 | uv.x = theta / (2.0 * PI); 18 | 19 | float depth = sqrt(local.x * local.x + local.y * local.y); 20 | float phi = atan(local.z, depth); 21 | float pixel_offset_from_center = phi / phi_range; 22 | uv.y = max(0.0, min(1.0, 0.5 + pixel_offset_from_center)); 23 | 24 | gl_FragColor = alpha * texture2D(tex0, uv); 25 | } 26 | -------------------------------------------------------------------------------- /viewer/panorama_renderer.h: -------------------------------------------------------------------------------- 1 | #ifndef PANORAMA_RENDERER_H__ 2 | #define PANORAMA_RENDERER_H__ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include "configuration.h" 12 | 13 | namespace structured_indoor_modeling { 14 | 15 | class Panorama; 16 | 17 | class PanoramaRenderer : protected QGLFunctions { 18 | public: 19 | PanoramaRenderer(); 20 | virtual ~PanoramaRenderer(); 21 | void Render(const double alpha, QOpenGLShaderProgram* program); 22 | // void Init(const PanoramaConfiguration& panorama_configuration, QGLWidget* widget); 23 | void Init(const FileIO& file_io, const int panorama_id, const Panorama* panorama, QGLWidget* widget); 24 | void InitGL(); 25 | 26 | const std::vector& DepthMesh() const { return depth_mesh; } 27 | int DepthWidth() const { return depth_width; } 28 | int DepthHeight() const { return depth_height; } 29 | const Panorama& GetPanorama() const { return *panorama; } 30 | 31 | private: 32 | void InitDepthMesh(const std::string& filename, const double phi_range); 33 | 34 | // Without texture data. 35 | const Panorama* panorama; 36 | // For texture allocation and deletion. 37 | QGLWidget* widget; 38 | 39 | // Image. 40 | QImage rgb_image; 41 | GLint texture_id; 42 | 43 | // Depthmap is turned into a grid mesh. 44 | int depth_width; 45 | int depth_height; 46 | std::vector depth_mesh; 47 | }; 48 | 49 | } // namespace structured_indoor_modeling 50 | 51 | #endif // PANORAMA_RENDERER_H__ 52 | -------------------------------------------------------------------------------- /viewer/panorama_vshader.glsl: -------------------------------------------------------------------------------- 1 | uniform mat4 global_to_local; 2 | varying vec3 local; 3 | 4 | void main() 5 | { 6 | gl_Position = ftransform(); 7 | gl_TexCoord[0] = gl_MultiTexCoord0; 8 | local = (global_to_local * gl_Vertex).xyz; 9 | } 10 | -------------------------------------------------------------------------------- /viewer/polygon_renderer.h: -------------------------------------------------------------------------------- 1 | #ifndef POLYGON_RENDERER_H__ 2 | #define POLYGON_RENDERER_H__ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include "../base/floorplan.h" 9 | 10 | namespace structured_indoor_modeling { 11 | 12 | class ViewParameters; 13 | 14 | struct Triangle2 { 15 | Eigen::Vector3d vertices[3]; 16 | Eigen::Vector3d colors[3]; 17 | Eigen::Vector3i colori; 18 | }; 19 | 20 | typedef std::vector Triangles; 21 | 22 | class PolygonRenderer : protected QGLFunctions { 23 | public: 24 | PolygonRenderer(const Floorplan& floorplan); 25 | virtual ~PolygonRenderer(); 26 | void RenderTextureMappedRooms(const double top_alpha, const double bottom_alpha) const; 27 | void RenderTextureMappedRooms(const double top_alpha, 28 | const double bottom_alpha, 29 | const ViewParameters& view_parameters, 30 | const double air_to_tree_progress, 31 | const double animation, 32 | const Eigen::Vector3d& max_vertical_shift, 33 | const double max_shrink_ratio) const; 34 | void RenderDoors(const double alpha) const; 35 | /* 36 | void RenderDoors(const double alpha, 37 | const ViewParameters& view_parameters, 38 | const double air_to_tree_progress, 39 | const double animation, 40 | const Eigen::Vector3d& max_vertical_shift, 41 | const double max_shrink_ratio) const; 42 | */ 43 | 44 | void RenderWallAll(const Eigen::Vector3d& center, 45 | const double alpha, 46 | const double height_adjustment, 47 | const bool depth_order_height_adjustment, 48 | const int room_not_rendered, 49 | const int room_highlighted, 50 | const bool render_room_id); 51 | 52 | void RenderColoredBoxes(const ViewParameters& view_parameters, 53 | const Eigen::Vector3d& max_vertical_shift, 54 | const double max_shrink_scale, 55 | const double air_to_tree_progress, 56 | const double animation, 57 | const double alpha, 58 | const Eigen::Vector3d& center); 59 | 60 | void RenderWireframeAll(const double alpha); 61 | void RenderWireframe(const int room, const double alpha); 62 | void Init(const std::string data_directory, QGLWidget* widget); 63 | void InitGL(); 64 | 65 | private: 66 | void SetTargetCeilingHeights(const Eigen::Vector3d& center, 67 | const bool depth_order_height_adjustment, 68 | const int room_not_rendered, 69 | std::vector* target_ceiling_heights); 70 | void AddTrianglesFromWalls(const double height_adjustment, 71 | const int room_not_rendered, 72 | const int room_highlighted, 73 | const std::vector& target_ceiling_heights, 74 | Triangles* triangles); 75 | void AddTrianglesFromCeiling(const double height_adjustment, 76 | const int room_not_rendered, 77 | const int room_highlighted, 78 | const std::vector& target_ceiling_heights, 79 | Triangles* triangles); 80 | 81 | void AddTrianglesFromWalls(Triangles* triangles) const; 82 | void AddTrianglesFromCeiling(Triangles* triangles) const; 83 | void AddTrianglesFromDoors(Triangles* triangles) const; 84 | 85 | QGLWidget* widget; 86 | const Floorplan& floorplan; 87 | 88 | std::vector texture_images; 89 | std::vector texture_ids; 90 | }; 91 | 92 | } // namespace structured_indoor_modeling 93 | 94 | #endif // POLYGON_RENDERER_H__ 95 | -------------------------------------------------------------------------------- /viewer/shaders.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | blend_vshader.glsl 4 | blend_fshader.glsl 5 | panorama_vshader.glsl 6 | panorama_fshader.glsl 7 | 8 | 9 | -------------------------------------------------------------------------------- /viewer/texture/kitchen.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yasu-furukawa/2015_structured_indoor_modeling/81d69495014adb51a51b058afee2abfff76b801c/viewer/texture/kitchen.jpg -------------------------------------------------------------------------------- /viewer/texture/sheep.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yasu-furukawa/2015_structured_indoor_modeling/81d69495014adb51a51b058afee2abfff76b801c/viewer/texture/sheep.png -------------------------------------------------------------------------------- /viewer/texture/tile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yasu-furukawa/2015_structured_indoor_modeling/81d69495014adb51a51b058afee2abfff76b801c/viewer/texture/tile.png -------------------------------------------------------------------------------- /viewer/texture/tile2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yasu-furukawa/2015_structured_indoor_modeling/81d69495014adb51a51b058afee2abfff76b801c/viewer/texture/tile2.png -------------------------------------------------------------------------------- /viewer/texture/tile3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yasu-furukawa/2015_structured_indoor_modeling/81d69495014adb51a51b058afee2abfff76b801c/viewer/texture/tile3.jpg -------------------------------------------------------------------------------- /viewer/texture/tile4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yasu-furukawa/2015_structured_indoor_modeling/81d69495014adb51a51b058afee2abfff76b801c/viewer/texture/tile4.jpg -------------------------------------------------------------------------------- /viewer/viewer.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include "configuration.h" 10 | 11 | #ifndef QT_NO_OPENGL 12 | #include "main_widget.h" 13 | #endif 14 | 15 | using namespace std; 16 | using namespace structured_indoor_modeling; 17 | 18 | int main(int argc, char *argv[]) { 19 | if (argc < 2) { 20 | cerr << "Usage: " << argv[0] << " data_directory [suffix=_other]" << endl; 21 | exit (1); 22 | } 23 | QApplication app(argc, argv); 24 | app.setApplicationName("viewer"); 25 | 26 | #ifndef QT_NO_OPENGL 27 | QWidget window; 28 | window.resize(1024, 720); 29 | // window.resize(1280, 720); 30 | // window.resize(1000, 600); 31 | 32 | string data_directory = argv[1]; 33 | 34 | /* 35 | string data_directory; 36 | for (int i = 1; i < argc; ++i) { 37 | string word = argv[i]; 38 | data_directory = data_directory + word; 39 | 40 | if (i != argc - 1) 41 | data_directory = data_directory + string(" "); 42 | } 43 | */ 44 | 45 | string suffix(""); 46 | if (argc > 2) 47 | suffix = argv[2]; 48 | 49 | Configuration configuration; 50 | { 51 | configuration.data_directory = data_directory; 52 | const double kAirAngle = 50.0 * M_PI / 180.0; // 60.0 * M_PI / 180.0; 53 | const double kAirFieldOfViewDegrees = 10.0; 54 | const double kFloorplanAngle = 80.0 * M_PI / 180.0; 55 | const double kFloorplanFieldOfViewDegrees = 10.0; 56 | configuration.air_angle = kAirAngle; 57 | configuration.air_field_of_view_degrees = kAirFieldOfViewDegrees; 58 | configuration.floorplan_angle = kFloorplanAngle; 59 | configuration.floorplan_field_of_view_degrees = kFloorplanFieldOfViewDegrees; 60 | } 61 | 62 | MainWidget* main_widget = new MainWidget(configuration, suffix); 63 | 64 | QHBoxLayout* layout = new QHBoxLayout(); 65 | layout->addWidget(main_widget); 66 | window.setLayout(layout); 67 | window.show(); 68 | 69 | #else 70 | QLabel note("OpenGL Support required"); 71 | note.show(); 72 | #endif 73 | return app.exec(); 74 | } 75 | -------------------------------------------------------------------------------- /viewer/viewer.pro: -------------------------------------------------------------------------------- 1 | # Feel free to add more paths here. This should just 2 | # give warnings without errors. 3 | 4 | QT += core gui widgets 5 | CONFIG += c++11 6 | TARGET = viewer 7 | TEMPLATE = app 8 | 9 | SOURCES += viewer.cc 10 | 11 | macx{ 12 | QMAKE_CXXFLAGS += '-Wno-c++11-extensions -Wno-gnu-static-float-init -Wno-sign-compare -Wno-overloaded-virtual' 13 | } 14 | 15 | qtHaveModule(opengl) { 16 | QT += opengl 17 | 18 | SOURCES += \ 19 | main_widget.cc \ 20 | main_widget_render.cc \ 21 | main_widget_util.cc \ 22 | navigation.cc \ 23 | view_parameters.cc \ 24 | floorplan_renderer.cc \ 25 | object_renderer.cc \ 26 | panel_renderer.cc \ 27 | panorama_renderer.cc \ 28 | polygon_renderer.cc \ 29 | indoor_polygon_renderer.cc \ 30 | ../base/detection.cc \ 31 | ../base/floorplan.cc \ 32 | ../base/indoor_polygon.cc \ 33 | ../base/panorama.cc \ 34 | ../base/point_cloud.cc 35 | 36 | HEADERS += \ 37 | main_widget.h \ 38 | main_widget_util.h \ 39 | configuration.h \ 40 | navigation.h \ 41 | view_parameters.h \ 42 | floorplan_renderer.h \ 43 | object_renderer.h \ 44 | panorama_renderer.h \ 45 | panel_renderer.h \ 46 | polygon_renderer.h \ 47 | indoor_polygon_renderer.h \ 48 | ../base/detection.h \ 49 | ../base/file_io.h \ 50 | ../base/floorplan.h \ 51 | ../base/indoor_polygon.h \ 52 | ../base/geometry.h \ 53 | ../base/panorama.h \ 54 | ../base/point_cloud.h 55 | 56 | RESOURCES += \ 57 | shaders.qrc 58 | 59 | unix:!macx{ 60 | INCLUDEPATH += '/usr/include' 61 | INCLUDEPATH += '/usr/include/eigen3' 62 | INCLUDEPATH += '/usr/local/include' 63 | LIBS += -L/usr/lib/x86_64-linux-gnu/ -lGLU -lopencv_core -lopencv_highgui -lopencv_imgproc 64 | } 65 | 66 | macx{ 67 | INCLUDEPATH += '/Users/furukawa/Google_Drive/research/code/' 68 | INCLUDEPATH += '/usr/local/include/' 69 | INCLUDEPATH += '/usr/local/include/eigen3/' 70 | # INCLUDEPATH += '/opt/X11/include' 71 | 72 | 73 | LIBS += '-F~/Qt/5.3/clang_64/lib/QtOpenGL.framework/Versions/5/' 74 | # LIBS += '-F/usr/local/opt/qt/Frameworks/QtOpenGL.framework/Versions/4/' 75 | LIBS += '-L/usr/local/lib' 76 | LIBS += '-lopencv_core' 77 | LIBS += '-lopencv_imgproc' 78 | LIBS += '-lopencv_highgui' 79 | # LIBS += '-L/opt/X11/lib -lGLU -framework OpenGL' 80 | } 81 | 82 | win32{ 83 | LIBS += -LC:/opencv/build/x64/vc12/lib -lopencv_core2410 -lopencv_imgproc2410 -lopencv_highgui2410 -lopencv_core2410d -lopencv_imgproc2410d -lopencv_highgui2410d 84 | INCLUDEPATH += C:/opencv/build/include 85 | #INCLUDEPATH += $$PWD/../../../lib/eigen3 86 | INCLUDEPATH += C:/Eigen3.2.2/ 87 | } 88 | } 89 | 90 | # install 91 | target.path = $$[QT_INSTALL_EXAMPLES]/opengl/cube 92 | INSTALLS += target 93 | --------------------------------------------------------------------------------