Skip to content

Commit

Permalink
Visualize 2D curves and surfaces, various changes related to enforcing
Browse files Browse the repository at this point in the history
colienearity between coefficients at common face boundaries
  • Loading branch information
vsk committed Jan 11, 2012
1 parent 9b00668 commit a17031c
Show file tree
Hide file tree
Showing 24 changed files with 781 additions and 78 deletions.
5 changes: 3 additions & 2 deletions compositemodel/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ ADD_LIBRARY(GoCompositeModel ${GoCompositeModel_SRCS})

# Apps, examples, tests, ...?

FILE(GLOB GoCompositeModel_APPS app/*.C)
FOREACH(app ${GoCompositeModel_APPS})
FILE(GLOB_RECURSE GoCompositeModel_APPS app/*.C)
FILE(GLOB_RECURSE GoCompositeModel_EXAMPLES examples/*.C)
FOREACH(app ${GoCompositeModel_APPS} ${GoCompositeModel_EXAMPLES})
GET_FILENAME_COMPONENT(appname ${app} NAME_WE)
ADD_EXECUTABLE(${appname} ${app})
TARGET_LINK_LIBRARIES(${appname} GoCompositeModel ${DEPLIBS})
Expand Down
10 changes: 10 additions & 0 deletions compositemodel/include/GoTools/compositemodel/FaceUtilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ namespace Go

void getInnerData(ftSurface* face, int nmb_sample_u, int nmb_sample_v,
std::vector<SamplePointData>& sample_points);

/// Enforce colinearity of coefficients of spline surfaces
/// related to the given faces
/// Return value = false : No modification
bool enforceCoLinearity(ftSurface *face1, ftEdge *edge1,
ftSurface *face2,
double tol, double ang_tol);

bool enforceVxCoLinearity(shared_ptr<Vertex> vx,
double tol, double ang_tol);
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ void faceWithHoles(std::vector<std::vector<ftEdge*> >& half_holes);
computeCornerSplit(shared_ptr<Vertex> corner,
std::vector<shared_ptr<Vertex> >& hole_vx,
std::vector<shared_ptr<Vertex> >& hole_vx2,
shared_ptr<BoundedSurface>& bd_sf);
shared_ptr<BoundedSurface>& bd_sf,
bool outer_vx=true);

void faceOuterBd(std::vector<std::vector<ftEdge*> >& half_holes);

Expand Down
4 changes: 4 additions & 0 deletions compositemodel/include/GoTools/compositemodel/SurfaceModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,10 @@ class GO_API SurfaceModel : public CompositeModel
/// Ensure that the blocks in the model has got common spline spaces
void makeCommonSplineSpaces();

/// Modify adjacent spline surfaces from having almost co-linear
/// coefficients to exact co-linearity
void enforceCoLinearCoefs();

/// Regularize face to mimic the division of a twin surface
/// \param face
/// \retval twinset
Expand Down
12 changes: 12 additions & 0 deletions compositemodel/include/GoTools/compositemodel/ftEdge.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,18 @@ class ftEdge : public ftEdgeBase

virtual void updateGeomCurve(double tol);

/// Update geometry info if possible
bool updateEdgeInfo(double tol);

/// Fetch index of geometry curve with respect to associated surface,
/// if this information exists:
/// -1 : No info or not a rectangular surface
/// 0 : umin
/// 1 : umax
/// 2 : vmin
/// 3 : vmax
int getCurveIndex() const;

/// Access function for vertices. The function takes into account
/// whether or not the orientation is reversed.
shared_ptr<Vertex> getVertex(bool at_start);
Expand Down
8 changes: 6 additions & 2 deletions compositemodel/include/GoTools/compositemodel/ftSurface.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ class GO_API ftSurface : public ftFaceBase
std::vector<shared_ptr<Vertex> > getCornerVertices(double kink,
int loop_idx) const;

/// Get all vertices commont to this face and another face
/// Get all vertices common to this face and another face
std::vector<shared_ptr<Vertex> >
getCommonVertices(ftSurface* other) const;

Expand Down Expand Up @@ -415,7 +415,11 @@ class GO_API ftSurface : public ftFaceBase
AdjacencyInfo getAdjacencyInfo(ftSurface *other, double tol,
int adj_idx = 0, bool test_corner = false);

/// Check if two degenerate surface boundaries meet in a vertex
/// Fetch info on adjacency between neighbouring faces given information
/// about the common edge
AdjacencyInfo getAdjacencyInfo(ftEdge *edge, ftSurface *other, double tol);

/// Check if two degenerate surface boundaries meet in a vertex
bool checkDegAdjacency(ftSurface *other, shared_ptr<Vertex> vx,
double tol,
shared_ptr<ParamCurve>& bdcv1,
Expand Down
142 changes: 142 additions & 0 deletions compositemodel/src/FaceUtilities.C
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "GoTools/geometry/ParamSurface.h"
#include "GoTools/geometry/BoundedSurface.h"
#include "GoTools/geometry/CurvatureAnalysis.h"
#include "GoTools/geometry/SurfaceTools.h"
#include "GoTools/creators/ModifySurf.h"

using namespace Go;
using std::vector;
Expand Down Expand Up @@ -266,5 +268,145 @@ using std::pair;
}
}

//===========================================================================
bool
FaceUtilities::enforceCoLinearity(ftSurface *face1, ftEdge *edge1,
ftSurface *face2,
double tol, double ang_tol)
//===========================================================================
{
// Check input
if ((!face1->isSpline()) || (!face2->isSpline()))
return false; // Associated surfaces are not spline surfaces, cannot
// modify coefficients

if (!edge1->hasConnectivityInfo())
return false; // No tangency information

// Check tangency
int status = edge1->getConnectivityInfo()->WorstStatus();
if (status > 1)
return false; // A corner curve

// Fetch information about common boundary
AdjacencyInfo adj_info = face1->getAdjacencyInfo(edge1, face2, tol);
if (adj_info.adjacency_found_ == false)
return false;

// Fetch surface geometry
shared_ptr<ParamSurface> srf1 = face1->surface();
shared_ptr<ParamSurface> srf2 = face2->surface();
shared_ptr<SplineSurface> splsf1 =
dynamic_pointer_cast<SplineSurface, ParamSurface>(srf1);
shared_ptr<SplineSurface> splsf2 =
dynamic_pointer_cast<SplineSurface, ParamSurface>(srf2);
if (!splsf1.get() || !splsf2.get())
return false;

// Check if the surface coefficients at the common boundary are almost
// co-linear and fetch the local enumeration of the associated coefficients
vector<vector<int> > coef_enum;
bool colinear = checkCoefCoLinearity(splsf1, splsf2, adj_info.bd_idx_1_,
adj_info.bd_idx_2_, adj_info.same_orient_,
tol, ang_tol, coef_enum);
if (coef_enum.size() == 0)
return false; // No information computed
// if (!colinear)
// return false;

// Peform surface modification
bool smoothed = ModifySurf::enforceCoefCoLinearity(splsf1, adj_info.bd_idx_1_,
splsf2, adj_info.bd_idx_2_,
tol, coef_enum);
if (!smoothed)
return false;

// Update edge information if possible
(void)edge1->updateEdgeInfo(tol);
ftEdge *edge2 = edge1->twin()->geomEdge();
if (edge2)
(void)edge2->updateEdgeInfo(tol);

return true;
}

//===========================================================================
bool
FaceUtilities::enforceVxCoLinearity(shared_ptr<Vertex> vx,
double tol, double ang_tol)
//===========================================================================
{
// Fetch all associated faces
vector<pair<ftSurface*, Point> > faces = vx->getFaces();

if (faces.size() != 4)
return false; // Not a regular corner

vector<ftEdge*> edges;
vector<Point> norms(faces.size());
vector<shared_ptr<SplineSurface> > sfs(faces.size());
size_t ki, kj;
for (ki=0; ki<faces.size(); ++ki)
{
if (!faces[ki].first->isSpline())
return false; // Cannot modify

shared_ptr<ParamSurface> curr_sf = faces[ki].first->surface();
shared_ptr<SplineSurface> splsf =
dynamic_pointer_cast<SplineSurface, ParamSurface>(curr_sf);
if (!splsf.get())
return false; // Something wrong
sfs[ki] = splsf;

vector<ftEdge*> curr_edges;// = getFaceEdge(faces[ki].first);
if (curr_edges.size() != 2)
return false; // Unclear how to handle this

if (!(curr_edges[0]->twin() && curr_edges[1]->twin()))
return false; // At the face set boundary. Do not change

// Collect face normal
norms[ki] = faces[ki].first->normal(faces[ki].second[0], faces[ki].second[1]);

edges.insert(edges.end(), curr_edges.begin(), curr_edges.end());
}

// Check tangent plane continuity at vertex
for (ki=1; ki<norms.size(); ++ki)
if (norms[0].angle(norms[ki]) > ang_tol)
return false;

// Compute adjacency info
for (ki=0; ki<faces.size(); ++ki)
{
ftEdge* twin1 = edges[2*ki]->twin()->geomEdge();
ftEdge* twin2 = edges[2*ki+1]->twin()->geomEdge();
if (!(twin1 && twin2))
return false;

for (kj=ki+1; kj<faces.size(); ++kj)
{
ftEdge *curr_edge = NULL;
if (twin1 == edges[2*kj] || twin1 == edges[2*kj+1])
curr_edge = edges[2*ki];
else if (twin2 == edges[2*kj] || twin2 == edges[2*kj+1])
curr_edge = edges[2*ki+1];
if (curr_edge)
{
AdjacencyInfo adj_info =
faces[ki].first->getAdjacencyInfo(curr_edge, faces[kj].first, tol);
vector<vector<int> > coef_enum;
if (adj_info.adjacency_found_ == true)
{
// bool colinear = checkCoefCoLinearity(sfs[ki], sfs[kj], adj_info.bd_idx_1_,
// adj_info.bd_idx_2_,
// adj_info.same_orient_,
// tol, ang_tol, coef_enum);
}
}
}
}
}



87 changes: 84 additions & 3 deletions compositemodel/src/RegularizeFace.C
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,8 @@ shared_ptr<CurveOnSurface>
RegularizeFace::computeCornerSplit(shared_ptr<Vertex> corner,
vector<shared_ptr<Vertex> >& hole_vx,
vector<shared_ptr<Vertex> >& hole_vx2,
shared_ptr<BoundedSurface>& bd_sf)
shared_ptr<BoundedSurface>& bd_sf,
bool outer_vx)
//==========================================================================
{
shared_ptr<CurveOnSurface> dummy;
Expand Down Expand Up @@ -1143,8 +1144,9 @@ RegularizeFace::computeCornerSplit(shared_ptr<Vertex> corner,
double d2 = pos2.dist(pnt);
if (d1 > epsge_ && d2 > epsge_)
trim_segments.erase(trim_segments.begin()+kr);
else if ((d1 < epsge_ && pos2.dist(centre_) > pos1.dist(centre_)) ||
(d2 < epsge_ && pos1.dist(centre_) > pos2.dist(centre_)))
else if (outer_vx &&
((d1 < epsge_ && pos2.dist(centre_) > pos1.dist(centre_)) ||
(d2 < epsge_ && pos1.dist(centre_) > pos2.dist(centre_))))
trim_segments.erase(trim_segments.begin()+kr);
else
{
Expand Down Expand Up @@ -1230,6 +1232,85 @@ void RegularizeFace::faceOneHole2()
if (corner.size() > 0)
{
// Split in corners
vector<shared_ptr<CurveOnSurface> > segments;
shared_ptr<BoundedSurface> bd_sf;
shared_ptr<ParamSurface> surf = face_->surface();
vector<shared_ptr<Vertex> > dummy_vx; // No vertices in outer loop
for (size_t ki=0; ki<corner.size(); ++ki)
{
Point pnt = corner[ki]->getVertexPoint();
Point vec = pnt - centre_;
vec.normalize();

// Compute splitting curve
shared_ptr<CurveOnSurface> trim_segment =
computeCornerSplit(corner[ki], dummy_vx, dummy_vx, bd_sf,
false);
if (trim_segment.get())
segments.push_back(trim_segment);
}

if (segments.size() > 0)
{
// Divide out hole
// Define faces
vector<shared_ptr<BoundedSurface> > sub_sfs =
BoundedUtils::splitWithTrimSegments(bd_sf, segments, epsge_);

#ifdef DEBUG_REG
std::ofstream of("split_surf.g2");
for (size_t kr=0; kr<sub_sfs.size(); ++kr)
{
sub_sfs[kr]->writeStandardHeader(of);
sub_sfs[kr]->write(of);
}
#endif

vector<shared_ptr<Vertex> > dummy_vx;
vector<shared_ptr<ftSurface> > faces =
RegularizeUtils::createFaces(sub_sfs, face_, epsge_, tol2_,
angtol_, dummy_vx);

// Set up topology
FaceAdjacency<ftEdgeBase,ftFaceBase> top(epsge_, tol2_, angtol_, bend_);
vector<shared_ptr<ftFaceBase> > tmp(faces.begin(), faces.end());
top.computeAdjacency(tmp);

// Treat each sub face
int nmb_faces = (int)faces.size();
for (int ki=0; ki<nmb_faces; )
{
RegularizeFace regularize(faces[ki], epsge_, angtol_, tol2_, bend_);
if (centre_.dimension() > 0)
regularize.setAxis(centre_, axis_);
regularize.setDivideInT(divideInT_);
if (cand_params_.size() > 0)
regularize.setCandParams(cand_params_);

vector<shared_ptr<ftSurface> > faces2 =
regularize.getRegularFaces();

if (faces2.size() > 1)
{
// Update topology
top.releaseFaceAdjacency(faces[ki]);
faces.erase(faces.begin()+ki);
nmb_faces--;
for (size_t kr=0; kr<faces2.size(); ++kr)
{
vector<shared_ptr<ftFaceBase> > tmp_faces(faces.begin(), faces.end());
top.computeFaceAdjacency(tmp_faces, faces2[kr]);
faces.push_back(faces2[kr]);
}

// Check if any new faces may be joined across the seam
mergeSeams(faces, nmb_faces, faces2);
}
else
ki++;
}
sub_faces_.insert(sub_faces_.end(), faces.begin(), faces.end());
}
}
else
{
Expand Down
Loading

0 comments on commit a17031c

Please sign in to comment.