Skip to content

Commit 8aba865

Browse files
authored
Merge pull request #322 from VibekeSkytt/small_diffs
Small functionality extensions and fixes, OPENMP related compilation …
2 parents eab5d22 + 45ac4e6 commit 8aba865

File tree

12 files changed

+110
-34
lines changed

12 files changed

+110
-34
lines changed

compositemodel/src/SurfaceModelUtils.C

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2390,7 +2390,12 @@ void SurfaceModelUtils::tesselateOneSrf(shared_ptr<ParamSurface> surf,
23902390
else
23912391
{
23922392
ParametricSurfaceTesselator tesselator(*surf.get());
2393-
tesselator.changeRes(n, m);
2393+
int n2, m2;
2394+
tesselator.getRes(n2, m2);
2395+
if (n == n2 && m == m2)
2396+
tesselator.tesselate();
2397+
else
2398+
tesselator.changeRes(n, m);
23942399
mesh = tesselator.getMesh();
23952400
}
23962401
}

gotools-core/src/geometry/SplineUtils.C

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,10 @@ void SplineUtils::closest_on_rectgrid(const double* pt, const double* array,
220220
clo_v = best_v;
221221
int ii = min(int(floor(clo_u)), u_max - 1);
222222
int jj = min(int(floor(clo_v)), v_max - 1);
223+
if (ii < 0)
224+
ii = floor(0.5*u_max);
225+
if (jj < 0)
226+
jj = floor(0.5*v_max);
223227
p[0].setValue(array + (jj*nmb_coefs_u + ii)*3);
224228
p[1].setValue(array + (jj*nmb_coefs_u + ii+1)*3);
225229
p[2].setValue(array + ((jj+1)*nmb_coefs_u + ii+1)*3);

lrsplines2D/app/getLRSfDomain.C

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,15 @@ int main( int argc, char* argv[] )
9494
// Fetch domain
9595
RectDomain domain = sf->containingDomain();
9696

97+
// Fetch box
98+
BoundingBox bb = sf->boundingBox();
99+
100+
97101
// Output
102+
int dim = sf->dimension();
98103
printf("Surface domain: %13.4f %13.4f %13.4f %13.4f \n", domain.umin(),
99104
domain.umax(), domain.vmin(), domain.vmax());
105+
printf("Bound z: %13.7f %13.7f \n", bb.low()[dim-1], bb.high()[dim-1]);
100106

101107
shared_ptr<LRSplineSurface> lrsf =
102108
dynamic_pointer_cast<LRSplineSurface, ParamSurface>(sf);

lrsplines2D/app/isoContours.C

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ namespace {
299299

300300
const double minval = bbox.low()[0];
301301
const double maxval = bbox.high()[0];
302+
std::cout << "Minval: " << minval << ", maxval: " << maxval << std::endl;
302303

303304
vector<double> result(num_contours, 0);
304305
for (int i = 0; i != num_contours; ++i)

lrsplines2D/app/liftSurfTo3D.C

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141

4242
#include "GoTools/geometry/ObjectHeader.h"
4343
#include "GoTools/geometry/BoundedSurface.h"
44+
#include "GoTools/geometry/SplineSurface.h"
4445
#include "GoTools/lrsplines2D/LRSplineSurface.h"
4546
#include "GoTools/geometry/GoTools.h"
4647
#include "GoTools/geometry/Factory.h"
@@ -105,6 +106,16 @@ int main(int argc, char *argv[])
105106
MESSAGE("Surface type " << header.classType() << " in the underlying surface is not supported.");
106107
}
107108
}
109+
else if (header.classType() == Class_SplineSurface)
110+
{
111+
shared_ptr<SplineSurface> sf(new SplineSurface());
112+
sf->read(filein);
113+
shared_ptr<LRSplineSurface> lr_sf(new LRSplineSurface(sf.get(), 1.0e-8));
114+
lr_sf->to3D();
115+
shared_ptr<SplineSurface> splsf(lr_sf->asSplineSurface());
116+
splsf->writeStandardHeader(fileout);
117+
splsf->write(fileout);
118+
}
108119
else
109120
{
110121
MESSAGE("Surface type " << header.classType() << " is not supported.");

lrsplines2D/app/translateSurf.C

Lines changed: 49 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,11 @@
3838
*/
3939

4040
#include "GoTools/utils/config.h"
41+
#include "GoTools/geometry/Factory.h"
42+
#include "GoTools/geometry/GoTools.h"
4143
#include "GoTools/geometry/Utils.h"
4244
#include "GoTools/geometry/ObjectHeader.h"
45+
#include "GoTools/geometry/BoundedSurface.h"
4346
#include "GoTools/lrsplines2D/LRSplineSurface.h"
4447
#include <iostream>
4548
#include <fstream>
@@ -50,33 +53,63 @@ using std::vector;
5053

5154
int main(int argc, char *argv[])
5255
{
53-
if (argc != 3) {
54-
std::cout << "Usage: input surface(.g2), output surface(.g2)" << std::endl;
56+
if (argc != 3 && argc != 4) {
57+
std::cout << "Usage: input surface(.g2), output surface(.g2), distance (optional)" << std::endl;
5558
return -1;
5659
}
5760

5861
std::ifstream input(argv[1]);
5962
std::ofstream output(argv[2]);
63+
double dist = 0.0;
64+
if (argc == 4)
65+
dist = atof(argv[3]);
6066

61-
ObjectHeader header2;
62-
header2.read(input);
63-
shared_ptr<LRSplineSurface> sf(new LRSplineSurface());
64-
sf->read(input);
67+
GoTools::init();
68+
Registrator<LRSplineSurface> r293;
6569

66-
if (sf->dimension() != 3)
70+
ObjectHeader header;
71+
header.read(input);
72+
shared_ptr<GeomObject> geom_obj(Factory::createObject(header.classType()));
73+
geom_obj->read(input);
74+
75+
shared_ptr<ParamSurface> sf = dynamic_pointer_cast<ParamSurface, GeomObject>(geom_obj);
76+
if (!sf.get())
6777
{
68-
std::cout << "Dimension not equal to 3" << std::endl;
69-
return 0;
78+
std::cerr << "Input file contains no surface" << std::endl;
79+
exit(-1);
7080
}
7181

72-
// Bounding box
73-
BoundingBox box = sf->boundingBox();
74-
Point low = box.low();
75-
Point high = box.high();
76-
Point mid = 0.5*(low + high);
82+
shared_ptr<ParamSurface> sf2 = sf;
83+
shared_ptr<BoundedSurface> bdsf =
84+
dynamic_pointer_cast<BoundedSurface, ParamSurface>(sf);
85+
if (bdsf.get())
86+
sf2 = bdsf->underlyingSurface();
87+
88+
shared_ptr<LRSplineSurface> lrsf =
89+
dynamic_pointer_cast<LRSplineSurface, ParamSurface>(sf2);
90+
if (!lrsf.get())
91+
{
92+
std::cerr << "Input file contains no LR B-spline surface" << std::endl;
93+
exit(-1);
94+
}
7795

78-
// Translate surface
79-
sf->translate(-mid);
96+
if (dist == 0.0)
97+
{
98+
// Bounding box
99+
BoundingBox box = sf->boundingBox();
100+
Point low = box.low();
101+
Point high = box.high();
102+
Point mid = 0.5*(low + high);
103+
104+
// Translate surface
105+
lrsf->translate(-mid);
106+
}
107+
else
108+
{
109+
Point vec(sf->dimension());
110+
vec.setValue(dist);
111+
lrsf->translate(vec);
112+
}
80113

81114
sf->writeStandardHeader(output);
82115
sf->write(output);

lrsplines2D/src/LRApproxApp.C

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,9 @@ void LRApproxApp::computeDistPointSpline(vector<double>& points,
420420
vector<Element2D*> elements;
421421
surf->constructElementMesh(elements);
422422

423-
max_above = max_below = avdist = 0.0;
423+
max_above = std::numeric_limits<double>::lowest();
424+
max_below = std::numeric_limits<double>::max();
425+
avdist = 0.0;
424426
nmb_points = 0;
425427

426428
// For each point, classify according to distance
@@ -547,7 +549,7 @@ void LRApproxApp::computeDistPointSpline_omp(vector<double>& points,
547549
vector<vector<double> > pts_dist(num_kj);
548550
int ki, kj, kr;
549551
#pragma omp parallel default(none) private(ki, kj, kr, knotv, knotu, pp0, pp1) \
550-
shared(surf, points, num_pts, pts_dist, num_kj, elements, evalsrf)
552+
shared(surf, points, num_pts, pts_dist, num_kj, elements, evalsrf, uknots_begin, uknots_end, nmb_knots_u, vknots_begin, vknots_end)
551553
{
552554
Point pos;
553555
int nump;
@@ -818,7 +820,7 @@ void LRApproxApp::classifyCloudFromDist_omp(vector<double>& points,
818820

819821
int kj;
820822
#pragma omp parallel default(none) private(kj) \
821-
shared(surf, points, limits, elements, all_max_above, all_max_below, all_dist, all_nmb_points, all_level_points, evalsrf)
823+
shared(surf, points, limits, elements, all_max_above, all_max_below, all_dist, all_nmb_points, all_level_points, evalsrf, uknots_begin, uknots_end, nmb_knots_u, vknots_begin, vknots_end, num_kj)
822824
{
823825
Element2D* elem = NULL;
824826
int ki, kr, ka;
@@ -1123,7 +1125,7 @@ void LRApproxApp::categorizeCloudFromDist_omp(vector<double>& points,
11231125
int kj;
11241126

11251127
#pragma omp parallel default(none) private(kj) \
1126-
shared(surf, points, limits, elements, all_max_above, all_max_below, all_dist, all_nmb_points, all_classification, all_nmb_group, evalsrf)
1128+
shared(surf, points, limits, elements, all_max_above, all_max_below, all_dist, all_nmb_points, all_classification, all_nmb_group, evalsrf, uknots_begin, uknots_end, nmb_knots_u, vknots_begin, vknots_end, num_kj)
11271129
{
11281130
Element2D* elem = NULL;
11291131
int ki, kr, ka;

lrsplines2D/src/LRSplineMBA.C

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ void LRSplineMBA::MBADistAndUpdate_omp(LRSplineSurface *srf,
406406
int kl, kk;
407407
// const int num_threads = 1;
408408
// omp_set_num_threads(num_threads);
409-
#pragma omp parallel default(none) private(kl, kk, el1/*, el2*/) shared(nom_denom, tol, dim, el1_vec, /*el2_vec,*/ umax, vmax, max_num_bsplines, elem_bspline_contributions, kdim, order2, significant_factor, sgn)
409+
#pragma omp parallel default(none) private(kl, kk, el1/*, el2*/) shared(nom_denom, tol, dim, el1_vec, /*el2_vec,*/ umax, vmax, max_num_bsplines, elem_bspline_contributions, kdim, order2, significant_factor, sgn, num_elem)
410410
{
411411
size_t nb;
412412
// Temporary vector to store weights associated with a given data point
@@ -944,7 +944,7 @@ void LRSplineMBA::MBAUpdate_omp(LRSplineSurface *srf,
944944
LRSplineSurface::ElementMap::const_iterator el1;
945945
LRSplineSurface::ElementMap::const_iterator el2;
946946
int kl;
947-
#pragma omp parallel default(none) private(kl, el1) shared(nom_denom, tol, dim, el1_vec, umax, vmax, max_num_bsplines, elem_bspline_contributions, kdim, significant_factor, sgn)
947+
#pragma omp parallel default(none) private(kl, el1) shared(nom_denom, tol, dim, el1_vec, umax, vmax, max_num_bsplines, elem_bspline_contributions, kdim, significant_factor, sgn, num_elem)
948948
{
949949
vector<double> tmp(dim);
950950
// Temporary vector to store weights associated with a given data point

lrsplines2D/src/LRSurfApprox.C

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1703,7 +1703,7 @@ void LRSurfApprox::computeAccuracy_omp(vector<Element2D*>& ghost_elems)
17031703
elem_iters.push_back(it);
17041704
}
17051705

1706-
#pragma omp parallel default(none) private(kj, it) shared(dim, elem_iters, rd, ghost_fac, ghost_elems, outlier_threshold, outlier_fac, outlier_rad, update_global, nmb_outliers)
1706+
#pragma omp parallel default(none) private(kj, it) shared(dim, elem_iters, rd, ghost_fac, ghost_elems, outlier_threshold, outlier_fac, outlier_rad, update_global, nmb_outliers, num_elem)
17071707
{
17081708
double av_prev, max_prev;
17091709
int nmb_out_prev;
@@ -2356,7 +2356,7 @@ void LRSurfApprox::computeAccuracyElement_omp(vector<double>& points, int nmb, i
23562356
#endif
23572357
// omp_set_num_threads(4);
23582358
#pragma omp parallel default(none) private(ki, curr, idx1, idx2, dist, upar, vpar, close_pt, curr_pt, vec, norm, dist1, dist2, dist3, dist4, sgn, pos, kr, kj/*, sfval, bval*/) \
2359-
shared(points, nmb, umax, vmax, del, dim, rd, maxiter, elem_grid_start, grid2, grid1, grid_height, grid3, grid4, elem2, bsplines, del2, prev_point_dist)
2359+
shared(points, nmb, umax, vmax, del, dim, rd, maxiter, elem_grid_start, grid2, grid1, grid_height, grid3, grid4, elem2, bsplines, del2, prev_point_dist, nmb_bsplines)
23602360
#pragma omp for schedule(dynamic, 4)//static, 4)//runtime)//guided)//auto)
23612361
for (ki=0; ki<nmb; ++ki)
23622362
{

lrsplines2D/src/LRSurfSmoothLS.C

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ void LRSurfSmoothLS::setLeastSquares_omp(const double weight,
526526
// For each element
527527
int ki;
528528
LRSplineSurface::ElementMap::const_iterator it;
529-
#pragma omp parallel default(none) private(ki, it) shared(dim, elem_iters)
529+
#pragma omp parallel default(none) private(ki, it) shared(dim, elem_iters, significant_factor, weight, num_elem)
530530
{
531531
bool has_LS_mat, is_modified;
532532
size_t nmb, inb, inb1;
@@ -1000,7 +1000,7 @@ void LRSurfSmoothLS::fetchBasisDerivs(const vector<LRBSpline2D*>& bsplines,
10001000
for (kj=0; kj<wgs1; ++kj)
10011001
gausspar1[kj] = 0.5*(sample[ix1][kj]*(umax-umin) + umax + umin);
10021002
for (kj=0; kj<wgs2; ++kj)
1003-
gausspar2[kj] = 0.5*(sample[ix1][kj]*(vmax-vmin) + vmax + vmin);
1003+
gausspar2[kj] = 0.5*(sample[ix2][kj]*(vmax-vmin) + vmax + vmin);
10041004

10051005
// Allocate scratch for the results of the basis evaluation. Store only those
10061006
// entries that will be used
@@ -1071,6 +1071,10 @@ void LRSurfSmoothLS::fetchBasisDerivs(const vector<LRBSpline2D*>& bsplines,
10711071
std::copy(derivs.begin()+ki*nmbb+7*nmbGauss,
10721072
derivs.begin()+ki*nmbb+8*nmbGauss,
10731073
basis_derivs.begin()+(curr+ki)*nmbGauss);
1074+
curr += bsize;
1075+
std::copy(derivs.begin()+ki*nmbb+8*nmbGauss,
1076+
derivs.begin()+ki*nmbb+9*nmbGauss,
1077+
basis_derivs.begin()+(curr+ki)*nmbGauss);
10741078
}
10751079
}
10761080
}
@@ -1307,8 +1311,9 @@ void LRSurfSmoothLS::computeDer1Integrals(const vector<LRBSpline2D*>& bsplines,
13071311
if (coef_fixed)
13081312
{
13091313
// Add contribution to the right side of the equation system
1314+
Point coef = bsplines[kj]->Coef();
13101315
for (int kk=0; kk<dim; ++kk)
1311-
gright_[kk*ncond_+ix1] -= val;
1316+
gright_[kk*ncond_+ix1] -= coef[kk]*val;
13121317
}
13131318
else
13141319
{
@@ -1417,8 +1422,9 @@ void LRSurfSmoothLS::computeDer2Integrals(const vector<LRBSpline2D*>& bsplines,
14171422
if (coef_fixed)
14181423
{
14191424
// Add contribution to the right side of the equation system
1425+
Point coef = bsplines[kj]->Coef();
14201426
for (int kk=0; kk<dim; ++kk)
1421-
gright_[kk*ncond_+ix1] -= val;
1427+
gright_[kk*ncond_+ix1] -= coef[kk]*val;
14221428
}
14231429
else
14241430
{
@@ -1534,8 +1540,9 @@ void LRSurfSmoothLS::computeDer3Integrals(const vector<LRBSpline2D*>& bsplines,
15341540
if (coef_fixed)
15351541
{
15361542
// Add contribution to the right side of the equation system
1543+
Point coef = bsplines[kj]->Coef();
15371544
for (int kk=0; kk<dim; ++kk)
1538-
gright_[kk*ncond_+ix1] -= val;
1545+
gright_[kk*ncond_+ix1] -= coef[kk]*val;
15391546
}
15401547
else
15411548
{

0 commit comments

Comments
 (0)