@@ -104,12 +104,36 @@ def flip_ctrlpts2d_file(file_in='', file_out='ctrlpts_flip.txt'):
104104 _save_ctrlpts2d_file (new_ctrlpts2d , size_u , size_v , file_out )
105105
106106
107- def generate_ctrlptsw (ctrlpts2d ):
108- """ Generates weighted control points from unweighted ones.
107+ def generate_ctrlptsw (ctrlpts ):
108+ """ Generates weighted control points from unweighted ones in 1-D .
109109
110110 This function
111111
112- #. Takes in a 2D control points file whose coordinates are organized like (x, y, z, w)
112+ #. Takes in a 1-D control points list whose coordinates are organized like (x, y, z, w)
113+ #. converts into (x*w, y*w, z*w, w) format
114+ #. Returns the result
115+
116+ :param ctrlpts: 1-D control points (P)
117+ :type ctrlpts: list
118+ :return: 1-D weighted control points (Pw)
119+ :rtype: list
120+ """
121+ # Multiply control points by weight
122+ new_ctrlpts = []
123+ for cpt in ctrlpts :
124+ temp = [float (pt * cpt [- 1 ]) for pt in cpt ]
125+ temp [- 1 ] = float (cpt [- 1 ])
126+ new_ctrlpts .append (temp )
127+
128+ return new_ctrlpts
129+
130+
131+ def generate_ctrlptsw2d (ctrlpts2d ):
132+ """ Generates weighted control points from unweighted ones in 2-D.
133+
134+ This function
135+
136+ #. Takes in a 2D control points list whose coordinates are organized like (x, y, z, w)
113137 #. converts into (x*w, y*w, z*w, w) format
114138 #. Returns the result
115139
@@ -125,23 +149,21 @@ def generate_ctrlptsw(ctrlpts2d):
125149 for row in ctrlpts2d :
126150 ctrlptsw_v = []
127151 for col in row :
128- temp = [float (col [0 ] * col [3 ]),
129- float (col [1 ] * col [3 ]),
130- float (col [2 ] * col [3 ]),
131- col [3 ]]
152+ temp = [float (c * col [- 1 ]) for c in col ]
153+ temp [- 1 ] = float (col [- 1 ])
132154 ctrlptsw_v .append (temp )
133155 new_ctrlpts2d .append (ctrlptsw_v )
134156
135157 return new_ctrlpts2d
136158
137159
138160# Generates weighted control points from unweighted ones
139- def generate_ctrlptsw_file (file_in = '' , file_out = 'ctrlptsw.txt' ):
140- """ Generates weighted control points from unweighted ones.
161+ def generate_ctrlptsw2d_file (file_in = '' , file_out = 'ctrlptsw.txt' ):
162+ """ Generates weighted control points from unweighted ones in 2-D .
141163
142164 This function
143165
144- #. Takes in a 2D control points file whose coordinates are organized like (x, y, z, w)
166+ #. Takes in a 2-D control points file whose coordinates are organized like (x, y, z, w)
145167 #. Converts into (x*w, y*w, z*w, w) format
146168 #. Saves the result to a file
147169
@@ -156,18 +178,42 @@ def generate_ctrlptsw_file(file_in='', file_out='ctrlptsw.txt'):
156178 ctrlpts2d , size_u , size_v = _read_ctrltps2d_file (file_in )
157179
158180 # Multiply control points by weight
159- new_ctrlpts2d = generate_ctrlptsw (ctrlpts2d )
181+ new_ctrlpts2d = generate_ctrlptsw2d (ctrlpts2d )
160182
161183 # Save new control points
162184 _save_ctrlpts2d_file (new_ctrlpts2d , size_u , size_v , file_out )
163185
164186
165- def generate_ctrlpts_weights (ctrlpts2d ):
166- """ Generates weighted control points from unweighted ones.
187+ def generate_ctrlpts_weights (ctrlpts ):
188+ """ Generates unweighted control points from weighted ones in 1-D.
189+
190+ This function
191+
192+ #. Takes in 1-D control points list whose coordinates are organized like (x*w, y*w, z*w, w)
193+ #. Converts the input control points list into (x, y, z, w) format
194+ #. Returns the result
195+
196+ :param ctrlpts: 1-D control points (P)
197+ :type ctrlpts: list
198+ :return: 1-D weighted control points (Pw)
199+ :rtype: list
200+ """
201+ # Divide control points by weight
202+ new_ctrlpts = []
203+ for cpt in ctrlpts :
204+ temp = [float (pt / cpt [- 1 ]) for pt in cpt ]
205+ temp [- 1 ] = float (cpt [- 1 ])
206+ new_ctrlpts .append (temp )
207+
208+ return new_ctrlpts
209+
210+
211+ def generate_ctrlpts2d_weights (ctrlpts2d ):
212+ """ Generates unweighted control points from weighted ones in 2-D.
167213
168214 This function
169215
170- #. Takes in 2D control points list whose coordinates are organized like (x*w, y*w, z*w, w)
216+ #. Takes in 2-D control points list whose coordinates are organized like (x*w, y*w, z*w, w)
171217 #. Converts the input control points list into (x, y, z, w) format
172218 #. Returns the result
173219
@@ -181,21 +227,19 @@ def generate_ctrlpts_weights(ctrlpts2d):
181227 for row in ctrlpts2d :
182228 ctrlptsw_v = []
183229 for col in row :
184- temp = [float (col [0 ] / col [3 ]),
185- float (col [1 ] / col [3 ]),
186- float (col [2 ] / col [3 ]),
187- col [3 ]]
230+ temp = [float (c / col [- 1 ]) for c in col ]
231+ temp [- 1 ] = float (col [- 1 ])
188232 ctrlptsw_v .append (temp )
189233 new_ctrlpts2d .append (ctrlptsw_v )
190234
191235 return new_ctrlpts2d
192236
193237
194238# Generates unweighted control points from weighted ones
195- def generate_ctrlpts_weights_file (file_in = '' , file_out = 'ctrlpts_weights.txt' ):
196- """ Generates unweighted control points from weighted ones.
239+ def generate_ctrlpts2d_weights_file (file_in = '' , file_out = 'ctrlpts_weights.txt' ):
240+ """ Generates unweighted control points from weighted ones in 2-D .
197241
198- #. Takes in 2D control points list whose coordinates are organized like (x*w, y*w, z*w, w)
242+ #. Takes in 2-D control points list whose coordinates are organized like (x*w, y*w, z*w, w)
199243 #. Converts the input control points list into (x, y, z, w) format
200244 #. Saves the result to a file
201245
@@ -208,14 +252,14 @@ def generate_ctrlpts_weights_file(file_in='', file_out='ctrlpts_weights.txt'):
208252 ctrlpts2d , size_u , size_v = _read_ctrltps2d_file (file_in )
209253
210254 # Divide control points by weight
211- new_ctrlpts2d = generate_ctrlpts_weights (ctrlpts2d )
255+ new_ctrlpts2d = generate_ctrlpts2d_weights (ctrlpts2d )
212256
213257 # Save new control points
214258 _save_ctrlpts2d_file (new_ctrlpts2d , size_u , size_v , file_out )
215259
216260
217261def combine_ctrlpts_weights (ctrlpts , weights ):
218- """ Multiplies control points with the weights to generate (x*w, y*w, z*w, w)
262+ """ Multiplies control points with the weights to generate weighted control points in any dimension.
219263
220264 :param ctrlpts: un-weighted control points
221265 :type ctrlpts: list, tuple
@@ -226,8 +270,8 @@ def combine_ctrlpts_weights(ctrlpts, weights):
226270 """
227271 ctrlptsw = []
228272 for pt , w in zip (ctrlpts , weights ):
229- temp = [c * w for c in pt ]
230- temp .append (w )
273+ temp = [float ( c * w ) for c in pt ]
274+ temp .append (float ( w ) )
231275 ctrlptsw .append (temp )
232276
233277 return ctrlptsw
0 commit comments