MGCL V10  V10
MGCL V10
 全て クラス 名前空間 関数 変数 型定義 列挙型 列挙値 フレンド グループ ページ
CPointsVec.h
1 /********************************************************************/
2 /* Copyright (c) 2015 DG Technologies Inc. and Yuzi Mizuno */
3 /* All rights reserved. */
4 /********************************************************************/
5 #ifndef _mgCPointsVec_HH_
6 #define _mgCPointsVec_HH_
7 
8 #include <memory>
9 #include <iosfwd>
10 #include <vector>
11 #include <deque>
12 #include <algorithm>
13 #include "mg/Pvector.h"
14 #include "topo/LEPoint.h"
15 #include "topo/Loop.h"
16 #include "topo/Face.h"
17 
19 
20 class MGTrimLoop;
21 class mgCPoints;
22 class mgCPointsVec;
23 class mgTL2PlBridge;
24 
25 class MG_DLL_DECLR mgCONNECT_POINT{
26 public:
27  enum OUTIN{coming_in, going_out};
28 private:
29  MGTrimLoop* m_trim_loop;//MGTrimLoop that touch the inner loop.
30  OUTIN m_outin;
31  //indicates if the contact point is coming_in of m_trim_loop(that is,
32  //the end point of m_trim_loop), or going_out(that is, the start point
33  //of m_trim_loop).
34 
35 public:
36  mgCONNECT_POINT():m_trim_loop(0){;};
37  mgCONNECT_POINT(MGTrimLoop* loop, OUTIN outin)
38  :m_trim_loop(loop), m_outin(outin){;}
39 
40  bool operator< (const mgCONNECT_POINT& linf2)const;
41  bool operator== (const mgCONNECT_POINT& linf2)const;
42  bool operator!= (const mgCONNECT_POINT& linf2)const{return !operator==(linf2);};
43  MGVector eval_deriv()const;
44  bool is_null()const{return m_trim_loop->is_null();};
45  bool is_going_out(){return m_outin==going_out;};
46  bool is_coming_in(){return m_outin==coming_in;};
47  MGLEPoint lep()const{
48  if(m_outin==coming_in)
49  return m_trim_loop->end_lep();
50  else
51  return m_trim_loop->start_lep();
52  };
53  std::auto_ptr<MGLoop> loop_clone(){
54  return std::auto_ptr<MGLoop>(new MGLoop(*(m_trim_loop->loop())));
55  };
56  OUTIN outin()const{return m_outin;};
57  MGTrimLoop* trim_loop(){return m_trim_loop;};
58  const MGTrimLoop* trim_loop()const{return m_trim_loop;};
59 
60  //obtain the next point of this connect point.
61  //The next point may be in the same loop, or in a different loop.
62  //function's return value is the mgCONNECT_POINT of the next point.
63  mgCONNECT_POINT next_point(
64  mgCPointsVec& cpointsVec//container of MGTrimLoop.
65  );
66 
67  //obtain the previous point of this connect point.
68  //The next point may be in the same loop, or in a different loop.
69  //function's return value is the mgCONNECT_POINT of the previous point.
70  mgCONNECT_POINT prev_point(
71  mgCPointsVec& cpointsVec//container of MGTrimLoop.
72  );
73 
74  //Debug Function
75  MG_DLL_DECLR friend std::ostream& operator<< (std::ostream& out, const mgCONNECT_POINT& cpoint);
76 
77 };
78 
79 class MG_DLL_DECLR mgCPoints{
80 public:
81  std::vector<mgCONNECT_POINT> m_cpoints;
82 
83  mgCONNECT_POINT& operator[](int i){return m_cpoints[i];};
84 
85  int size()const{return (int)m_cpoints.size();}
86  void sort(){std::sort(m_cpoints.begin(), m_cpoints.end());}
87  void push_back(const mgCONNECT_POINT& cpoint){m_cpoints.push_back(cpoint);};
88 
89  int next_id(int j)const{return (j+1)%m_cpoints.size();};
90  int prev_id(int j)const{
91  int n=(int)m_cpoints.size();
92  return (j+n-1)%n;
93  };
94  mgCONNECT_POINT next_point(int j){
95  return m_cpoints[next_id(j)];
96  }
97  mgCONNECT_POINT prev_point(int j){
98  return m_cpoints[prev_id(j)];
99  }
100 
101  //get the id of m_cpoints that includes tloop
102  int find_trim_loop(const MGTrimLoop* tloop, mgCONNECT_POINT::OUTIN out_in)const;
103 
104  //Debug Function
105  MG_DLL_DECLR friend std::ostream& operator<< (std::ostream& out, const mgCPoints& cpoints);
106 };
107 
108 class MG_DLL_DECLR mgCPointsVec{
109 
110 const MGFace& m_face;//Target face to trim
111 const MGPosition& m_uv;//trimming positioning data.
112 MGPvector<MGTrimLoop> m_trim_loops;//Trimloop's
113 std::vector<mgCPoints> m_cpoints_vec;//vector of mgCPoints.
114 
115 public:
116 
117 explicit mgCPointsVec(
118  const MGFace& face, //target face.
119  const MGPosition& uv=mgNULL_VEC
120 ):m_face(face), m_uv(uv), m_cpoints_vec(face.get_number_of_boundaries()){;};
121 
122 //Extract MGTrimLoop & mgCPoints info, and build this mgCPointsVec data.
123 void build_CPointsVec(
124  mgTL2PlBridge& bridge //original loops to trim.
125  //includes uv is output when return code =0 or 1.
126 );
127 
128 //Extract MGTrimLoop & mgCPoints info, and build this mgCPointsVec data.
129 //While processing, a closed outer loop or closed inner loop is found, store it in
130 //the oloops or iloops.
131 //When m_uv is not null, oloops contains the only closed outer loop that contain m_uv,
132 //and return function's return code as 1. If the closed loop was not found,
133 //generate m_trim_loops(the vector of MGTrimLoop).
134 //When m_uv is null, put all the outer loops into oloops, and inner loops into iloops.
135 //Function's return value is
136 // 1: when m_uv is not null, a closed loop that includes m_uv was extracted into oloops.
137 // 0: when m_uv is not null, no closed outer loop that includes m_uv was found
138 // and trim loop info were output into m_trim_loops and
139 // mgCONNECT_POINT's into m_cpoints_vec. Closed inner loops may be output to iloops.
140 //When m_uv is null, function's return value is always 0.
141 int extract_trim_loop_info(
142  const MGLoop& network, //original loops to trim.
143  MGPvector<MGLoop>& oloops,//When m_uv is not nul, the closed outerboundary loop
144  //that includes m_uv is output and the return code ==1.
145  //When m_uv is null, all the detected closed outerboundary loops will be output,
146  //and the function's return value is 0.
147  MGPvector<MGLoop>& iloops//closed inner boundary loop that
148  //includes uv is output when return code =0 or 1.
149 );
150 
151 //Extract a boundary out of networks that includes m_uv.
152 //m_uv is a parameter of m_face.
153 //Function's return value is
154 // 0: no loops were extracted,
155 // 2: Loops to trim face were output into used_tloops.
156 // If trimming is performed by used_tloops[i] for i=0,...,n-1 one by one,
157 // face will be trimmed by the part of the face that includes uv.
158 int extract_uv_boundary(
159  std::auto_ptr<MGLoop>& loop, //the loop that includes m_uv will be output
160  //when return code=2.
161  std::deque<MGTrimLoop*>& used_tloops
162 );
163 
164 //extract the loop whose start point is first_point.
165 //Function's return value is:
166 //0: no loop was extracted since first_point was null.
167 //1: a loop was extracted into loop.
168 int extract_loop(
169  mgCONNECT_POINT& first_point,
170  std::auto_ptr<MGLoop>& loop, //the loop will be output.
171  std::deque<MGTrimLoop*>& tloops//used MGTrimLoop to extract loop will be output.
172 );
173 
174 mgCPoints& operator[](int i){return m_cpoints_vec[i];};
175 void push_at(int i, const mgCONNECT_POINT& cpoint){m_cpoints_vec[i].push_back(cpoint);};
176 int size()const{return (int)m_cpoints_vec.size();};
177 bool no_uv()const{return m_uv.is_null();};
178 
179 MG_DLL_DECLR friend std::ostream& operator<< (std::ostream& out, const mgCPointsVec& cpvec);
180 
181 };
182 
184 #endif
bool is_null() const
Test if this is null.
Definition: Position.h:238
MGLEPoint start_lep() const
Definition: TrimLoop.h:41
bool is_null() const
Definition: TrimLoop.h:36
MGLoop * loop()
Definition: TrimLoop.h:37
std::ostream & operator<<(std::ostream &ostrm, const MGisect &is)
Debug Function.
Definition: isect.h:95
Vector of a general n space dimension.
Definition: Vector.h:26
MGTrimLoop is a private and utility class to implement trimming of MGFSurface.
Definition: TrimLoop.h:21
MGFace is a trimmed surface.
Definition: Face.h:51
MGLEPoint end_lep() const
Definition: TrimLoop.h:47
Express a splitting line for a face for tessellation.
Definition: TL2Face.h:122
Represent a positional data.
Definition: Position.h:28
Is to represent a Loop's point.
Definition: LEPoint.h:28
MGLoop is a boundary of a face, a boundary of 2D manifold cell.
Definition: Loop.h:44
Defines Vector of newed object pointers.
Definition: Pvector.h:27