HOpSelectPolygonOOC.h
1 // Copyright (c) Tech Soft 3D, Inc.
2 //
3 // The information contained herein is confidential and proprietary to Tech Soft 3D, Inc.,
4 // and considered a trade secret as defined under civil and criminal statutes.
5 // Tech Soft 3D, Inc. shall pursue its civil and criminal remedies in the event of
6 // unauthorized use or misappropriation of its trade secrets. Use of this information
7 // by anyone other than authorized employees of Tech Soft 3D, Inc. is granted only under
8 // a written non-disclosure agreement, expressly prescribing the scope and manner of such use.
9 
10 #pragma once
11 
12 
13 #ifdef HMFC_STATIC_LIB
14 # error "Code cannot be statically linked."
15 #endif
16 
17 
18 #ifdef H_PACK_8
19 # pragma pack(push)
20 # pragma pack(8)
21 #endif
22 
23 
25 
26 
27 #include "HOpSelectPolygon.h"
28 #include "HSelectionSetOOC.h"
29 #include <vector>
30 
31 
33 
34 
40 template <typename SelectionSet>
42 public:
47  : HOpSelectPolygon(&view)
48  {}
49 
52  virtual char const * GetName ()
53  {
54  return "HOpSelectPolygonOOC";
55  }
56 
61  virtual HBaseOperator * Clone ()
62  {
63  return new HOpSelectPolygonOOC(*GetView());
64  }
65 
71  virtual int OnLButtonDown (HEventInfo & e)
72  {
73  GetSelectionSet().DeSelectAll();
75  }
76  virtual int OnLButtonDblClk (HEventInfo & e)
82  {
83  HSelectionSetOOC<SelectionSet> & selset = GetSelectionSet();
84 
85  return selset.SynchronizeWith([&] () -> int {
86  int const result = HOpSelectPolygon::OnLButtonDblClk(e);
87 
88  std::vector<ooc::Point> const triangles(ComputePolygonTriangles());
89 
90  for (size_t i = 0; i < triangles.size(); i += 3) {
91  selset.AddTriangleWindow(triangles[i], triangles[i + 1], triangles[i + 2]);
92  }
93 
94  return result;
95  });
96  }
97 
98 private:
99  HSelectionSetOOC<SelectionSet> & GetSelectionSet ()
100  {
101  HBaseView & view = *GetView();
102  HSelectionSet & selset = *view.GetSelection();
103  return static_cast<HSelectionSetOOC<SelectionSet> &>(selset);
104  }
105 
106  std::vector<ooc::Point> ComputePolygonTriangles ()
107  {
108  std::vector<ooc::Point> triangles;
109 
110  HC_Open_Segment("/");{
111  HC_KEY segment_key = HC_Open_Segment("");{
112  HC_KEY polygon_key = HC_Insert_Polygon(m_PolylineCount, m_pPolyline);
113  HC_KEY shell_key = HC_Generate_Shell_From_Geometry(polygon_key, "");
114 
115  int point_count;
116  int tristrip_count;
117  HC_Show_Shell_By_Tristrips_Size(shell_key, &point_count, &tristrip_count, 0);
118  std::vector<ooc::Point> points(point_count);
119  std::vector<int> tristrips(tristrip_count);
120  HC_Show_Shell_By_Tristrips(shell_key, 0, points.data(), 0, tristrips.data(), 0, 0);
121 
122  triangles = ComputeTrianglesFromTristrips(points, tristrips);
123  }HC_Close_Segment();
124 
125  HC_Delete_By_Key(segment_key);
126  }HC_Close_Segment();
127 
128  return triangles;
129  }
130 
131  static bool IsDegenerate (int const (&triangle_indices)[3])
132  {
133  if (triangle_indices[0] == triangle_indices[1]) {
134  return true;
135  }
136  if (triangle_indices[0] == triangle_indices[2]) {
137  return true;
138  }
139  if (triangle_indices[1] == triangle_indices[2]) {
140  return true;
141  }
142  return false;
143  }
144 
145  static std::vector<ooc::Point> ComputeTrianglesFromTristrips (
146  std::vector<ooc::Point> const & points,
147  std::vector<int> const & tristrips)
148  {
149  std::vector<ooc::Point> triangles;
150 
151  for (size_t i = 0; i < tristrips.size(); ) {
152  size_t const strip_len = tristrips[i++];
153  ASSERT(i + strip_len <= tristrips.size());
154  for (size_t j = 2; j < strip_len; ++j) {
155  ASSERT(i + j < tristrips.size());
156  int triangle_indices[] = {
157  tristrips[i + j - 2],
158  tristrips[i + j - 1],
159  tristrips[i + j - 0],
160  };
161  if (!IsDegenerate(triangle_indices)) {
162  for (size_t k = 0; k < 3; ++k) {
163  triangles.push_back(points[triangle_indices[k]]);
164  }
165  }
166  }
167  i += strip_len;
168  }
169 
170  return triangles;
171  }
172 };
173 
174 
175 
Definition: HSelectionSetOOC.h:77
HOpSelectPolygonOOC(HBaseView &view)
Definition: HOpSelectPolygonOOC.h:46
void HC_Show_Shell_By_Tristrips(Key key, int *pcount, Point points[], int *tristrips_length, int tristrips[], int *face_indices_length, int face_indices[])
The HOpSelectPolygon class computes a selection list for objects inside a user-defined polygonal area...
Definition: HOpSelectPolygon.h:46
virtual int OnLButtonDblClk(HEventInfo &e)
Definition: HOpSelectPolygonOOC.h:81
virtual int OnLButtonDown(HEventInfo &hevent)
The HSelectionSet class manages a list of selected items.
Definition: HSelectionSet.h:66
virtual HBaseOperator * Clone()
Definition: HOpSelectPolygonOOC.h:61
Definition: HOpSelectPolygonOOC.h:41
int m_PolylineCount
Definition: HOpConstructPolyline.h:104
void HC_Show_Shell_By_Tristrips_Size(Key key, int *pcount, int *tristrips_length, int *face_indices_length)
void AddTriangleWindow(ooc::Point const &p1, ooc::Point const &p2, ooc::Point const &p3)
Definition: HSelectionSetOOC.h:420
HSelectionSet * GetSelection()
Definition: HBaseView.h:696
auto SynchronizeWith(Func const &task) -> decltype(task())
Definition: HSelectionSetOOC.h:436
The HBaseOperator class serves as a base for classes which handle user input and operate on the scene...
Definition: HBaseOperator.h:60
Key HC_Generate_Shell_From_Geometry(Key geom, char const *options)
The HBaseView class defines and manages a view of model information.
Definition: HBaseView.h:332
HBaseView * GetView()
Returns a pointer to the view that this operator is associated with.
Definition: HBaseOperator.h:103
void HC_Close_Segment(void)
The HEventInfo class stores and manages event information.
Definition: HEventInfo.h:207
virtual int OnLButtonDown(HEventInfo &e)
Definition: HOpSelectPolygonOOC.h:71
virtual char const * GetName()
Definition: HOpSelectPolygonOOC.h:52
void HC_Delete_By_Key(Key key)
HPoint * m_pPolyline
Definition: HOpConstructPolyline.h:103
Key HC_Insert_Polygon(int count, Point const points[])
Key HC_Open_Segment(char const *segment)
virtual int OnLButtonDblClk(HEventInfo &hevent)