Skip to content

Commit

Permalink
Merge pull request #381 from VibekeSkytt/reveng_byproduct
Browse files Browse the repository at this point in the history
Changes from RevEng
  • Loading branch information
sbriseid authored Nov 18, 2024
2 parents f93963c + 4aa8378 commit 3879d20
Show file tree
Hide file tree
Showing 22 changed files with 318 additions and 68 deletions.
5 changes: 5 additions & 0 deletions compositemodel/include/GoTools/compositemodel/ftPointSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ class ftSamplePoint

/// Add a new neighbouring point
void addNeighbour(PointIter next);
void addTriangle(PointIter next1, PointIter next2);

/// If neighbour exists it is removed from neighbour vector.
void removeNeighbour(PointIter neighbour);

Expand Down Expand Up @@ -153,6 +155,8 @@ class ftSamplePoint
/// Distance between sample points
double pntDist(ftSamplePoint* other) const;

bool isNeighbour(ftSamplePoint* other) const;

/// Fetch all triangles containing this point
void getAttachedTriangles(std::vector<std::vector<int> >& triangles) const;

Expand All @@ -169,6 +173,7 @@ class ftSamplePoint
// 2: boundary point on subface, inner point on merged surface.
std::vector<PointIter> next_;

ftSamplePoint();

}; // End of ftSamplePoint

Expand Down
7 changes: 6 additions & 1 deletion compositemodel/include/GoTools/compositemodel/ftSurface.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ namespace Go
class GO_API ftSurface : public ftFaceBase
{
public:
ftSurface();

/// Constructor. Typically, the ParamSurface in this constructor
/// will be a BoundedSurface. A loop will be built from this, but
/// if we already have a loop and the edges in the loop has
Expand All @@ -111,6 +113,8 @@ class GO_API ftSurface : public ftFaceBase
/// Empty destructor
virtual ~ftSurface();

void attachSurface(shared_ptr<ParamSurface> sf);

/// Return as type ftSurface
virtual ftSurface* asFtSurface();

Expand Down Expand Up @@ -634,7 +638,8 @@ class GO_API ftSurface : public ftFaceBase
void replaceSurf(shared_ptr<ParamSurface> sf)
{ surf_ = sf;}

private:
//private:
protected:
/// Geometric description of the surface associated to this face
shared_ptr<ParamSurface> surf_;

Expand Down
9 changes: 5 additions & 4 deletions compositemodel/src/SurfaceModel_intersections.C
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,7 @@ shared_ptr<SurfaceModel> SurfaceModel::trimWithPlane(const ftPlane& plane)
// The other surface model
for (ki=0; ki<nmb2; ki++)
{
shared_ptr<ftSurface> face2 = model2->getFace(ki);
if (all_int_cvs2[ki].size() == 0)
{
// The surface is not involved in any intersections. Check if
Expand Down Expand Up @@ -910,10 +911,10 @@ shared_ptr<SurfaceModel> SurfaceModel::trimWithPlane(const ftPlane& plane)
bool inside = isInside(pnt, normal, pt_dist);
shared_ptr<ParamSurface> tmp_surf(surf->clone());
shared_ptr<ftSurface> tmp_face(new ftSurface(tmp_surf, -1));
if (faces_[ki]->asFtSurface()->hasBoundaryConditions())
if (face2->asFtSurface()->hasBoundaryConditions())
{
int bd_cond_type, bd_cond;
faces_[ki]->asFtSurface()->getBoundaryConditions(bd_cond_type, bd_cond);
face2->asFtSurface()->getBoundaryConditions(bd_cond_type, bd_cond);
tmp_face->setBoundaryConditions(bd_cond_type, bd_cond);
}
if (inside)
Expand Down Expand Up @@ -974,10 +975,10 @@ shared_ptr<SurfaceModel> SurfaceModel::trimWithPlane(const ftPlane& plane)
double pt_dist;
bool inside = isInside(pnt, normal, pt_dist);
shared_ptr<ftSurface> tmp_face(new ftSurface(trim_sfs[kr], -1));
if (faces_[ki]->asFtSurface()->hasBoundaryConditions())
if (face2->asFtSurface()->hasBoundaryConditions())
{
int bd_cond_type, bd_cond;
faces_[ki]->asFtSurface()->getBoundaryConditions(bd_cond_type, bd_cond);
face2->asFtSurface()->getBoundaryConditions(bd_cond_type, bd_cond);
tmp_face->setBoundaryConditions(bd_cond_type, bd_cond);
}
if (inside)
Expand Down
43 changes: 31 additions & 12 deletions compositemodel/src/ftEdge.C
Original file line number Diff line number Diff line change
Expand Up @@ -767,12 +767,20 @@ void ftEdge::disconnectTwin()

ftEdge *prev = dynamic_cast<ftEdge*>(prev_);
ftEdge *next = dynamic_cast<ftEdge*>(next_);
shared_ptr<Vertex> prev_start = prev->getVertex(true);
shared_ptr<Vertex> next_start = next->getVertex(true);
shared_ptr<Vertex> prev_end = prev->getVertex(false);
shared_ptr<Vertex> next_end = next->getVertex(false);
bool prev_v1 = (v1_->hasEdge(prev));
bool next_v2 = (v2_->hasEdge(next));
shared_ptr<Vertex> prev_start, next_start, prev_end, next_end;
bool prev_v1 = false, next_v2 = false;
if (prev)
{
prev_start = prev->getVertex(true);
prev_end = prev->getVertex(false);
prev_v1 = (v1_->hasEdge(prev));
}
if (next)
{
next_start = next->getVertex(true);
next_end = next->getVertex(false);
next_v2 = (v2_->hasEdge(next));
}
bool at_start1 = (prev_v1 && prev_start == v1_) ||
((!prev_v1) && prev_start == v2_) ;
bool at_start2 = (next_v2 && next_start == v2_) ||
Expand All @@ -790,12 +798,19 @@ void ftEdge::disconnectTwin()
v1_ = shared_ptr<Vertex>(new Vertex(this, !is_reversed_));
v2_ = shared_ptr<Vertex>(new Vertex(this, is_reversed_));

shared_ptr<Vertex> tmp_vx1 = prev_v1 ? prev->getVertex(at_start1) :
next->getVertex(!at_start2);
joinVertex(v1_, tmp_vx1);
shared_ptr<Vertex> tmp_vx2 = next_v2 ? next->getVertex(at_start2) :
prev->getVertex(!at_start1);
joinVertex(v2_, tmp_vx2);
shared_ptr<Vertex> tmp_vx1, tmp_vx2;
if (prev_v1)
tmp_vx1 = prev->getVertex(at_start1);
else if (next_v2)
tmp_vx1 = next->getVertex(!at_start2);
if (tmp_vx1)
joinVertex(v1_, tmp_vx1);
if (next_v2)
tmp_vx2 = next->getVertex(at_start2);
else if (prev_v1)
tmp_vx2 = prev->getVertex(!at_start1);
if (tmp_vx2)
joinVertex(v2_, tmp_vx2);

// Remove from radial edge
if (all_edges_.get())
Expand Down Expand Up @@ -1095,6 +1110,10 @@ shared_ptr<Vertex> ftEdge::getOtherSignificantVertex(const Vertex* vx,

return edgs[ki]->getOtherSignificantVertex(other.get(), angtol);
}

shared_ptr<Vertex> dummy;
return dummy; // Uncertain about the effect, but the function should
// always return something
}

//===========================================================================
Expand Down
91 changes: 76 additions & 15 deletions compositemodel/src/ftPointSet.C
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,19 @@
namespace Go
{

//===========================================================================
ftSamplePoint::ftSamplePoint()
: xyz_(Vector3D(0.0, 0.0, 0.0)), uv_(Vector2D(0.0, 0.0)),
dist_(-1.0), index_(0), at_boundary_(0)
//---------------------------------------------------------------------------
//
// Purpose: Constructor
//
//===========================================================================
{
}


//===========================================================================
ftSamplePoint::ftSamplePoint(Vector3D xyz, int bnd)
: xyz_(xyz), uv_(Vector2D(0.0, 0.0)),
Expand Down Expand Up @@ -80,6 +93,36 @@ void ftSamplePoint::addNeighbour(PointIter next)
next_.push_back(next);
}

//===========================================================================
void ftSamplePoint::addTriangle(PointIter next1, PointIter next2)
//---------------------------------------------------------------------------
//
// Purpose: Add a new triangle
//
//===========================================================================
{
size_t ki, kj;
for (ki=0; ki<next_.size(); ++ki)
if (next_[ki] == next1)
break;
for (kj=0; kj<next_.size(); ++kj)
if (next_[kj] == next2)
break;
if (ki == next_.size() && kj == next_.size())
{
next_.push_back(next1);
next_.push_back(next2);
}
else if (ki == next_.size())
{
next_.insert(next_.begin()+kj, next1);
}
else if (kj == next_.size())
{
next_.insert(next_.begin()+ki+1, next2);
}
}

//===========================================================================
void ftSamplePoint::removeNeighbour(PointIter neighbour)
//===========================================================================
Expand Down Expand Up @@ -136,6 +179,16 @@ double ftSamplePoint::pntDist(ftSamplePoint* other) const
return xyz_.dist(other->xyz_);
}

//===========================================================================
bool ftSamplePoint::isNeighbour(ftSamplePoint* other) const
//===========================================================================
{
for (size_t ki=0; ki<next_.size(); ++ki)
if (next_[ki] == other)
return true;
return false;
}

//===========================================================================
void ftSamplePoint::getAttachedTriangles(vector<vector<int> >& triangles) const
//===========================================================================
Expand All @@ -156,8 +209,10 @@ double ftSamplePoint::pntDist(ftSamplePoint* other) const
index[1] = next_[ki]->index_;
index[2] = pnt->index_;
std::sort(index.begin(), index.end());
auto it = std::find(triangles.begin(), triangles.end(), index);

triangles.push_back(index);
if (it == triangles.end())
triangles.push_back(index);
break;
}
// if (kh<pnt->next_.size())
Expand Down Expand Up @@ -1383,7 +1438,7 @@ void ftPointSet::getOrientedTriangles(vector<vector<int> >& triangles)
Vector3D node2 = index_to_iter_[triangles[0][1]]->getPoint();
Vector3D node3 = index_to_iter_[triangles[0][2]]->getPoint();
Point vec1(node2[0]-node1[0], node2[1]-node1[1], node2[2]-node1[2]);
Point vec2(node3[0]-node1[0], node3[1]-node1[1], node3[2]-node1[2]);
Point vec2(node1[0]-node3[0], node1[1]-node3[1], node1[2]-node3[2]);
Point norm2 = vec2.cross(vec1);
if (norm1*norm2 < 0.0)
std::swap(triangles[0][1],triangles[0][2]);
Expand Down Expand Up @@ -1423,26 +1478,32 @@ void ftPointSet::getOrientedTriangles(vector<vector<int> >& triangles)
if (ki2 >= 0)
{
// Common edge
// @@@ VSK, 0214. Uncertain whether this test always will
// be correct
if ((ki2-ki1 == kj2-kj1 && (ki2-ki1)*(kj2-kj1) > 0) ||
(ki1==0 && ki2==2 && (ki2-ki1)*(kj2-kj1)<0) ||
(kj1==0 && kj2==2 && (ki2-ki1)*(kj2-kj1)<0))
// // @@@ VSK, 0214. Uncertain whether this test always will
// // be correct
// if ((ki2-ki1 == kj2-kj1 && (ki2-ki1)*(kj2-kj1) > 0) ||
// (ki1==0 && ki2==2 && (ki2-ki1)*(kj2-kj1)<0) ||
// (kj1==0 && kj2==2 && (ki2-ki1)*(kj2-kj1)<0))
if (ki2 - ki1 > 1)
std::swap(ki1, ki2);
if (kj1 > kj2)
std::swap(kj1, kj2);
if (kj2 - kj1 > 1)
std::swap(kj1, kj2);
if ((triangles[ki][ki2]-triangles[ki][ki1])*
(triangles[kj][kj2]-triangles[kj][kj1]) > 0)
{
// Same orientation. Swap
std::swap(triangles[kj][kj1], triangles[kj][kj2]);
}
if (not_swapped >= 0)

if (kj > not_swapped)
{
// Reorganize triangles to avoid changing sequence back
if (kj > ki+1)
{
triangles.insert(triangles.begin()+ki+1,
triangles[kj]);
triangles.erase(triangles.begin()+kj+1);
}
not_swapped++;
triangles.insert(triangles.begin()+not_swapped,
triangles[kj]);
triangles.erase(triangles.begin()+kj+1);
}
not_swapped++;
}
// else if (not_swapped == -1)
// {
Expand Down
16 changes: 16 additions & 0 deletions compositemodel/src/ftSurface.C
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@ using std::make_pair;
namespace Go
{

//---------------------------------------------------------------------------
ftSurface::ftSurface()
: ftFaceBase(-1), surf_(0), prio_type_(ftNoType), degenerate_eps_(-1.0),
twin_(0), body_(0), has_boundary_condition_(false),
boundary_cond_type_(-1), boundary_cond_(-1)
//---------------------------------------------------------------------------
{
}

//---------------------------------------------------------------------------
ftSurface::ftSurface(shared_ptr<ParamSurface> sf, int id)
: ftFaceBase(id), surf_(sf), prio_type_(ftNoType), degenerate_eps_(-1.0),
Expand Down Expand Up @@ -105,6 +114,13 @@ ftSurface::~ftSurface()
}


//===========================================================================
void ftSurface::attachSurface(shared_ptr<ParamSurface> sf)
//===========================================================================
{
surf_ = sf;
}

//===========================================================================
ftSurface* ftSurface::asFtSurface()
//===========================================================================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,10 @@ namespace Go
/// Translation of surface
void translateSurfaceDomain(ParamSurface* sf, const Point& translate_vec);

#if 0
// We rescale the value of the z dimension. Typically relevant for 2.5D surfaces.
void scaleZ(ParamSurface& sf, double scale_factor);

#endif
// from and to referr to index of a 2-tuple in pts_2d. We allow negative indices as
// well as indices larger than the number of 2-tuples, with the modulo operation
// defining the correct index.
Expand Down
7 changes: 7 additions & 0 deletions gotools-core/include/GoTools/creators/TrimCurve.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ class TrimCurve : public EvalCurveSet
/// limited in the parameter domain
TrimCurve(CurveOnSurface* bd_crv, double start, double end);

/// Constructor given the CurveOnSurface curve representing the trim curve
/// limited in the geometry space and in parameter space. This can avoid
/// troubles in the case of a closed input curve. It is left to the user
/// to ensure consistence
TrimCurve(double startpar, Point startpt, double endpar, Point endpt,
CurveOnSurface* bd_crv);

/// Constructor given the CurveOnSurface curve representing the trim curve
/// limited in the geometry space
TrimCurve(Point startpt, Point endpt, CurveOnSurface* bd_crv);
Expand Down
17 changes: 16 additions & 1 deletion gotools-core/src/creators/CurveCreators.C
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,23 @@ CurveCreators::projectCurve(shared_ptr<ParamCurve>& space_cv,
shared_ptr<CurveOnSurface> sf_cv =
shared_ptr<CurveOnSurface>(new CurveOnSurface(surf, space_cv, false));

// Compute endpoints
// There is a possibility to end up at the wrong side of the seam for closed
// surface, but the position of the closest point should not be that distant
double eps = 1.0e-9;
Point pos1, pos2;
double t1 = space_cv->startparam();
double t2 = space_cv->endparam();
space_cv->point(pos1, t1);
space_cv->point(pos2, t2);

double u1, v1, u2, v2, d1, d2;
Point close1, close2;
surf->closestPoint(pos1, u1, v1, close1, d1, eps);
surf->closestPoint(pos2, u2, v2, close2, d2, eps);

// We must first construct a EvalCurveSet for use in GoHermitAppS.
shared_ptr<TrimCurve> proj_crv(new TrimCurve(sf_cv.get()));
shared_ptr<TrimCurve> proj_crv(new TrimCurve(t1, close1, t2, close2, sf_cv.get()));

// Approximate
vector<double> initpars;
Expand Down
Loading

0 comments on commit 3879d20

Please sign in to comment.