Skip to content

Commit 06a2304

Browse files
authored
Merge pull request #324 from VibekeSkytt/lr_trim
Lr trim
2 parents 409c239 + 3397978 commit 06a2304

File tree

8 files changed

+817
-211
lines changed

8 files changed

+817
-211
lines changed

gotools-core/src/geometry/BoundedSurface.C

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ BoundedSurface(shared_ptr<ParamSurface> surf,
331331
loop_fixed_ = bd_sf->loop_fixed_;
332332
iso_trim_= bd_sf->iso_trim_;
333333
iso_trim_tol_ = bd_sf->iso_trim_tol_;
334+
valid_state_ = bd_sf->valid_state_;
334335
}
335336
else
336337
{
@@ -346,10 +347,10 @@ BoundedSurface(shared_ptr<ParamSurface> surf,
346347
}
347348
iso_trim_ = true;
348349
iso_trim_tol_ = space_epsilon;
350+
351+
// We then analyze the loops and set valid_state_.
352+
analyzeLoops();
349353
}
350-
351-
// We then analyze the loops and set valid_state_.
352-
analyzeLoops();
353354
}
354355

355356
//===========================================================================
Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
/*
2+
* Copyright (C) 1998, 2000-2007, 2010, 2011, 2012, 2013 SINTEF ICT,
3+
* Applied Mathematics, Norway.
4+
*
5+
* Contact information: E-mail: [email protected]
6+
* SINTEF ICT, Department of Applied Mathematics,
7+
* P.O. Box 124 Blindern,
8+
* 0314 Oslo, Norway.
9+
*
10+
* This file is part of GoTools.
11+
*
12+
* GoTools is free software: you can redistribute it and/or modify
13+
* it under the terms of the GNU Affero General Public License as
14+
* published by the Free Software Foundation, either version 3 of the
15+
* License, or (at your option) any later version.
16+
*
17+
* GoTools is distributed in the hope that it will be useful,
18+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+
* GNU Affero General Public License for more details.
21+
*
22+
* You should have received a copy of the GNU Affero General Public
23+
* License along with GoTools. If not, see
24+
* <http://www.gnu.org/licenses/>.
25+
*
26+
* In accordance with Section 7(b) of the GNU Affero General Public
27+
* License, a covered work must retain the producer line in every data
28+
* file that is created or manipulated using GoTools.
29+
*
30+
* Other Usage
31+
* You can be released from the requirements of the license by purchasing
32+
* a commercial license. Buying such a license is mandatory as soon as you
33+
* develop commercial activities involving the GoTools library without
34+
* disclosing the source code of your own applications.
35+
*
36+
* This file may be used in accordance with the terms contained in a
37+
* written agreement between you and SINTEF ICT.
38+
*/
39+
40+
#include "GoTools/lrsplines2D/LRSplineSurface.h"
41+
#include "GoTools/geometry/PointCloud.h"
42+
#include "GoTools/geometry/ObjectHeader.h"
43+
#include "GoTools/geometry/BoundedSurface.h"
44+
#include "GoTools/geometry/Factory.h"
45+
#include "GoTools/geometry/GoTools.h"
46+
#include "GoTools/geometry/FileUtils.h"
47+
#include "GoTools/lrsplines2D/TrimSurface.h"
48+
#include "GoTools/geometry/SplineDebugUtils.h"
49+
#include <iostream>
50+
#include <fstream>
51+
#include <vector>
52+
#include <string>
53+
#include <cstring>
54+
55+
using namespace Go;
56+
57+
using std::cout;
58+
using std::endl;
59+
using std::vector;
60+
using std::string;
61+
62+
//#define DEBUG
63+
64+
void print_help_text()
65+
{
66+
std::cout << "TrimSurfWithPoints trims an LR B-spline surface with respect to a point cloud. \n";
67+
std::cout << "The surface must be a hight function parameterized on xy and the domain of the point cloud must relate to the domain of the surface. \n";
68+
std::cout << "A tightness parameter governs how close to the point cloud the trimming curve will pass. \n";
69+
std::cout << "The density and uniformity of the cloud should be reflected in this parameter. \n";
70+
std::cout << "The parameter should be in the range [1:8] and higher for denser point clouds. \n";
71+
std::cout << "The smaller number should be used only when the point cloud is very ragged towards the boundary. \n";
72+
std::cout << "Usage: Input surface (.g2), input cloud (.txt, .g2), tightness parameter, output surface (.g2) \n";
73+
std::cout << "Optional: only outer trimming (0/1). Default 0 \n";
74+
std::cout << "-h or --help for help text" << std::endl;
75+
}
76+
77+
78+
int main(int argc, char* argv[])
79+
{
80+
for (int kii=1; kii<argc; ++kii)
81+
{
82+
string arg(argv[kii]);
83+
if (arg == "-h" || arg == "--help")
84+
{
85+
print_help_text();
86+
exit(0);
87+
}
88+
}
89+
90+
if (argc != 5 && argc != 6)
91+
{
92+
std::cout << "ERROR: Number of parameters is not correct" << std::endl;
93+
print_help_text();
94+
return 1;
95+
}
96+
97+
98+
std::ifstream filein_sf(argv[1]);
99+
char *pointfile(argv[2]);
100+
int tightness = atoi(argv[3]);
101+
std::ofstream fileout_bd_sf(argv[4]);
102+
int only_outer = false;
103+
if (argc == 6)
104+
only_outer = atoi(argv[5]);
105+
106+
GoTools go_tools;
107+
go_tools.init();
108+
Registrator<LRSplineSurface> r293;
109+
110+
shared_ptr<GeomObject> geom_obj;
111+
ObjectHeader header;
112+
try {
113+
header.read(filein_sf);
114+
}
115+
catch (...)
116+
{
117+
std::cout << "ERROR: Input object not recognized. Exiting" << std::endl;
118+
return 1;
119+
}
120+
shared_ptr<ParamSurface> sf;
121+
try {
122+
geom_obj = shared_ptr<GeomObject>(Factory::createObject(header.classType()));
123+
geom_obj->read(filein_sf);
124+
}
125+
catch (...)
126+
{
127+
std::cout << "ERROR: Input surface could not be read. Exiting" << std::endl;
128+
return 1;
129+
}
130+
sf = dynamic_pointer_cast<ParamSurface, GeomObject>(geom_obj);
131+
if (!sf.get())
132+
{
133+
std::cout << "ERROR: Input file contains no surface" << std::endl;
134+
return 1;
135+
}
136+
137+
// Read point cloud
138+
vector<double> data;
139+
vector<double> extent(6); // Limits for points in all coordinates
140+
// Possible types of input files
141+
char keys[6][8] = {"g2", "txt", "TXT", "xyz", "XYZ", "dat"};
142+
int ptstype = FileUtils::fileType(pointfile, keys, 6);
143+
if (ptstype < 0)
144+
{
145+
std::cout << "ERROR: File type not recognized" << std::endl;
146+
return 1;
147+
}
148+
149+
int nmb_pts = 0;
150+
std::ifstream pointsin(pointfile);
151+
if (ptstype == 0)
152+
{
153+
// g2 file
154+
ObjectHeader header;
155+
PointCloud3D points;
156+
try {
157+
header.read(pointsin);
158+
points.read(pointsin);
159+
}
160+
catch (...)
161+
{
162+
std::cout << "ERROR: Not a valid point file" << std::endl;
163+
return -1;
164+
}
165+
BoundingBox box = points.boundingBox();
166+
Point low = box.low();
167+
Point high = box.high();
168+
nmb_pts = points.numPoints();
169+
data.insert(data.end(), points.rawData(), points.rawData()+3*nmb_pts);
170+
for (int ki=0; ki<3; ++ki)
171+
{
172+
extent[2*ki] = low[ki];
173+
extent[2*ki+1] = high[ki];
174+
}
175+
std::cout << "Domain: [" << extent[0] << ", " << extent[1] << "] x [" << extent[2];
176+
std::cout << ", " << extent[3] << "]" << std::endl;
177+
std::cout << "Range: " << extent[4] << " - " << extent[5] << std::endl;
178+
}
179+
else
180+
FileUtils::readTxtPointFile(pointsin, 3, data, nmb_pts, extent);
181+
182+
183+
// Make bounded surface
184+
shared_ptr<BoundedSurface> bd_sf;
185+
vector<shared_ptr<BoundedSurface> > bd_surfs;
186+
bool isotrim[4];
187+
isotrim[0] = isotrim[1] = isotrim[2] = isotrim[3] = false;
188+
try {
189+
TrimSurface::makeBoundedSurface(sf, isotrim, data, tightness,
190+
bd_sf, only_outer);
191+
}
192+
catch (...)
193+
{
194+
std::cout << "ERROR: Trimming of surface failed" << std::endl;
195+
return 1;
196+
}
197+
198+
if (bd_sf->dimension() > 1)
199+
{
200+
std::ofstream ofl("sf_loop.g2");
201+
SplineDebugUtils::writeBoundary(*bd_sf, ofl);
202+
}
203+
204+
// Write output surface
205+
bd_sf->writeStandardHeader(fileout_bd_sf);
206+
bd_sf->write(fileout_bd_sf);
207+
208+
return 0;
209+
}

lrsplines2D/app/trimSurface.C renamed to lrsplines2D/app/trimSurfaceFromTrimPts.C

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@ int main(int argc, char* argv[])
158158

159159
// The curve should be CCW.
160160
const double int_tol = 1e-06;
161-
bool loop_is_ccw = LoopUtils::loopIsCCW(par_cvs, epsgeo, int_tol);
161+
vector<shared_ptr<ParamCurve> > par_cvs2(par_cvs.begin(), par_cvs.end());
162+
bool loop_is_ccw = LoopUtils::loopIsCCW(par_cvs2, epsgeo, int_tol);
162163
if (!loop_is_ccw)
163164
{
164165
MESSAGE("We should change direction of the loop cv!");

0 commit comments

Comments
 (0)