00001 // Copyright (c) 1998-2014 by Tech Soft 3D, Inc. 00002 // 00003 // The information contained herein is confidential and proprietary to Tech Soft 3D, Inc., 00004 // and considered a trade secret as defined under civil and criminal statutes. 00005 // Tech Soft 3D, Inc. shall pursue its civil and criminal remedies in the event of 00006 // unauthorized use or misappropriation of its trade secrets. Use of this information 00007 // by anyone other than authorized employees of Tech Soft 3D, Inc. is granted only under 00008 // a written non-disclosure agreement, expressly prescribing the scope and manner of such use. 00009 00010 #pragma once 00011 00012 00013 #ifdef HMFC_STATIC_LIB 00014 # error "Code cannot be statically linked." 00015 #endif 00016 00017 00018 #ifdef H_PACK_8 00019 # pragma pack(push) 00020 # pragma pack(8) 00021 #endif 00022 00023 00025 00026 00027 #include "HOpSelectPolygon.h" 00028 #include "HSelectionSetOOC.h" 00029 #include <vector> 00030 00031 00033 00034 00040 template <typename SelectionSet> 00041 class HOpSelectPolygonOOC : public HOpSelectPolygon { 00042 public: 00046 HOpSelectPolygonOOC (HBaseView & view) 00047 : HOpSelectPolygon(&view) 00048 {} 00049 00052 virtual char const * GetName () 00053 { 00054 return "HOpSelectPolygonOOC"; 00055 } 00056 00061 virtual HBaseOperator * Clone () 00062 { 00063 return new HOpSelectPolygonOOC(*GetView()); 00064 } 00065 00071 virtual int OnLButtonDown (HEventInfo & e) 00072 { 00073 GetSelectionSet().DeSelectAll(); 00074 return HOpSelectPolygon::OnLButtonDown(e); 00075 } 00076 virtual int OnLButtonDblClk (HEventInfo & e) 00082 { 00083 HSelectionSetOOC<SelectionSet> & selset = GetSelectionSet(); 00084 00085 return selset.SynchronizeWith([&] () -> int { 00086 int const result = HOpSelectPolygon::OnLButtonDblClk(e); 00087 00088 std::vector<ooc::Point> const triangles(ComputePolygonTriangles()); 00089 00090 for (size_t i = 0; i < triangles.size(); i += 3) { 00091 selset.AddTriangleWindow(triangles[i], triangles[i + 1], triangles[i + 2]); 00092 } 00093 00094 return result; 00095 }); 00096 } 00097 00098 private: 00099 HSelectionSetOOC<SelectionSet> & GetSelectionSet () 00100 { 00101 HBaseView & view = *GetView(); 00102 HSelectionSet & selset = *view.GetSelection(); 00103 return static_cast<HSelectionSetOOC<SelectionSet> &>(selset); 00104 } 00105 00106 std::vector<ooc::Point> ComputePolygonTriangles () 00107 { 00108 std::vector<ooc::Point> triangles; 00109 00110 HC_Open_Segment("/");{ 00111 HC_KEY segment_key = HC_Open_Segment("");{ 00112 HC_KEY polygon_key = HC_Insert_Polygon(m_PolylineCount, m_pPolyline); 00113 HC_KEY shell_key = HC_Generate_Shell_From_Geometry(polygon_key, ""); 00114 00115 int point_count; 00116 int tristrip_count; 00117 HC_Show_Shell_By_Tristrips_Size(shell_key, &point_count, &tristrip_count, 0); 00118 std::vector<ooc::Point> points(point_count); 00119 std::vector<int> tristrips(tristrip_count); 00120 HC_Show_Shell_By_Tristrips(shell_key, 0, points.data(), 0, tristrips.data(), 0, 0); 00121 00122 triangles = ComputeTrianglesFromTristrips(points, tristrips); 00123 }HC_Close_Segment(); 00124 00125 HC_Delete_By_Key(segment_key); 00126 }HC_Close_Segment(); 00127 00128 return triangles; 00129 } 00130 00131 static bool IsDegenerate (int const (&triangle_indices)[3]) 00132 { 00133 if (triangle_indices[0] == triangle_indices[1]) { 00134 return true; 00135 } 00136 if (triangle_indices[0] == triangle_indices[2]) { 00137 return true; 00138 } 00139 if (triangle_indices[1] == triangle_indices[2]) { 00140 return true; 00141 } 00142 return false; 00143 } 00144 00145 static std::vector<ooc::Point> ComputeTrianglesFromTristrips ( 00146 std::vector<ooc::Point> const & points, 00147 std::vector<int> const & tristrips) 00148 { 00149 std::vector<ooc::Point> triangles; 00150 00151 for (size_t i = 0; i < tristrips.size(); ) { 00152 size_t const strip_len = tristrips[i++]; 00153 ASSERT(i + strip_len <= tristrips.size()); 00154 for (size_t j = 2; j < strip_len; ++j) { 00155 ASSERT(i + j < tristrips.size()); 00156 int triangle_indices[] = { 00157 tristrips[i + j - 2], 00158 tristrips[i + j - 1], 00159 tristrips[i + j - 0], 00160 }; 00161 if (!IsDegenerate(triangle_indices)) { 00162 for (size_t k = 0; k < 3; ++k) { 00163 triangles.push_back(points[triangle_indices[k]]); 00164 } 00165 } 00166 } 00167 i += strip_len; 00168 } 00169 00170 return triangles; 00171 } 00172 }; 00173 00174 00175