Skip to content

Commit

Permalink
Merge pull request #379 from sbriseid/core_diffs_step_fixes
Browse files Browse the repository at this point in the history
Core diffs step fixes
  • Loading branch information
sbriseid authored Nov 2, 2024
2 parents 269e05c + 7430afa commit d9941d5
Show file tree
Hide file tree
Showing 50 changed files with 1,843 additions and 222 deletions.
30 changes: 29 additions & 1 deletion gotools-core/include/GoTools/creators/ApproxSurf.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@
#include "GoTools/geometry/SplineCurve.h"
#include <vector>


enum
{
ACCURACY_MAXDIST, ACCURACY_AVDIST_FRAC
};

class SmoothSurf;

Expand Down Expand Up @@ -203,6 +206,11 @@ class ApproxSurf
/// Approximate C1 continuity with a given impartance 0 <= fac < 1
void setC1Approx(double fac1, double fac2);

void setMBA(bool mba)
{
mba_ = mba;
}

/// Fetch the approximating surface

/// When everything else is set, this function can be used to run the
Expand All @@ -227,6 +235,11 @@ class ApproxSurf
/// match against the current surface.
int reParam();

std::vector<double> getParvals()
{
return parvals_;
}

/// Check whether or not the spline space will be refined during
/// the approximation iterations
bool getDoRefine()
Expand All @@ -241,6 +254,13 @@ class ApproxSurf
refine_ = refine;
}

/// Set accuracy criterion
void setAccuracyCrit(int criterion, double frac)
{
acc_criter_ = (criterion == 1) ? ACCURACY_AVDIST_FRAC : ACCURACY_MAXDIST;
acc_frac_ = frac;
}


protected:
/// Default constructor
Expand All @@ -264,6 +284,7 @@ class ApproxSurf
bool close_belt_;
bool repar_;
bool refine_;
bool mba_;

int dim_;
std::vector<double> points_;
Expand All @@ -275,6 +296,8 @@ class ApproxSurf
int constdir_;
bool orig_;
double c1fac1_, c1fac2_;
int acc_criter_;
double acc_frac_;

/// Generate an initial curve representing the spline space
int makeInitSurf(std::vector<shared_ptr<SplineCurve> > &crvs,
Expand All @@ -289,6 +312,9 @@ class ApproxSurf
/// Generate a smoothing surface
int makeSmoothSurf();

/// Approximate using mba method
void mbaApprox();

/// Check the accuracy of the current surface
int checkAccuracy(std::vector<double>& acc_outside_u,
std::vector<int>& nmb_outside_u,
Expand All @@ -307,6 +333,8 @@ class ApproxSurf
/// Define free and fixed coefficients
void coefKnownFromPoints();
void setCoefKnown();

bool approxOK();
};

} // namespace Go
Expand Down
3 changes: 2 additions & 1 deletion gotools-core/include/GoTools/geometry/BoundedCurve.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ class GO_API BoundedCurve : public ParamCurve
virtual void appendCurve(ParamCurve* cv, bool reparam=true);

virtual void appendCurve(ParamCurve* cv,
int continuity, double& dist, bool reparam=true);
int continuity, double& dist, bool reparam=true,
double tol = 1.0e-4);

virtual void closestPoint(const Point& pt,
double tmin,
Expand Down
39 changes: 37 additions & 2 deletions gotools-core/include/GoTools/geometry/BoundedUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,11 @@ namespace BoundedUtils {
std::vector< shared_ptr< CurveOnSurface > >& bnd_cvs,
double eps);

std::vector<shared_ptr<CurveOnSurface> >
intersectWithElementarySurface(shared_ptr<ParamSurface>& surf,
shared_ptr<ElementarySurface>& elem,
double geom_tol);

/// Find the intersection curve(s) between a parametric surface and a given plane.
/// The plane is defined by its normal and a point on the plane.
/// \param surf the surface to intersect with the plane
Expand Down Expand Up @@ -322,7 +327,21 @@ namespace BoundedUtils {
intersectWithCylinder(shared_ptr<ParamSurface>& surf,
Point pnt, Point vec, double radius, double geom_tol);

/// Find the intersction curve(s) between two spline surfaces
std::vector<shared_ptr<CurveOnSurface> >
intersectWithSphere(shared_ptr<ParamSurface>& surf,
Point pnt, double radius, double geom_tol);

std::vector<shared_ptr<CurveOnSurface> >
intersectWithCone(shared_ptr<ParamSurface>& surf,
Point pnt, Point axispt, Point sfpt, double geom_tol);

std::vector<shared_ptr<CurveOnSurface> >
intersectWithTorus(shared_ptr<ParamSurface>& surf,
Point pnt, Point normal, double radius1,
double radius2, double geom_tol);

/// Find the intersction curve(s) between two parametric surfaces. The surfaces
/// are represented as spline surface if this was not the case initially.
/// \param sf1 the first surface to intersect
/// \param sf2 the second surface to intersect
/// \retval int_segments1 a vector of CurveOnSurface s, representing the intersection
Expand All @@ -337,7 +356,23 @@ namespace BoundedUtils {
double epsge);


/// Translate a given BoundedSurface
/// Find the intersction curve(s) between two parametric surfaces where at least
/// one is an elementary surface.
/// \param sf1 the first surface to intersect
/// \param sf2 the second surface to intersect
/// \retval int_segments1 a vector of CurveOnSurface s, representing the intersection
/// curves as lying on 'sf1'.
/// \retval int_segments2 a vector of CurveOnSurface s, representing the intersection
/// curves as lying on 'sf2'.
/// \param epsge geometrical tolerance to be used for intersection computations
void getIntersectionCurveElem(shared_ptr<ParamSurface>& sf1,
shared_ptr<ParamSurface>& sf2,
std::vector<shared_ptr<CurveOnSurface> >& int_segments1,
std::vector<shared_ptr<CurveOnSurface> >& int_segments2,
double epsge);


/// Translate a given BoundedSurface
/// \param trans_vec the vector specifying the translation to apply to the surface
/// \param bd_sf the surface to translate
/// \param deg_eps an epsilon value used when determining degenerate boundary loops
Expand Down
8 changes: 7 additions & 1 deletion gotools-core/include/GoTools/geometry/Circle.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ class Circle : public ElementaryCurve
virtual void appendCurve(ParamCurve* cv, bool reparam=true);

virtual void appendCurve(ParamCurve* cv,
int continuity, double& dist, bool reparam=true);
int continuity, double& dist, bool reparam=true,
double tol = 1.0e-4);

virtual void closestPoint(const Point& pt,
double tmin,
Expand Down Expand Up @@ -168,6 +169,11 @@ class Circle : public ElementaryCurve
return vec1_;
}

Point getYAxis() const
{
return vec2_;
}

double getRadius() const
{
return radius_;
Expand Down
5 changes: 4 additions & 1 deletion gotools-core/include/GoTools/geometry/CurveOnSurface.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ class GO_API CurveOnSurface : public ParamCurve
// inherited from ParamCurve. NB: does not check whether the resulting ParamCurve
// stays inside parameter domain (or that the space curve stays on surface).
virtual void appendCurve(ParamCurve* cv,
int continuity, double& dist, bool reparam=true);
int continuity, double& dist, bool reparam=true,
double tol = 1.0e-4);

/// Set the underlying surface to the one pointed to by the argument
/// \param surface the pointer to the surface we will set as underlying for this
Expand Down Expand Up @@ -441,6 +442,8 @@ class GO_API CurveOnSurface : public ParamCurve

/// Check if the curve is a constant parameter curve with regard to the
/// parameter tol
/// pardir = 1: constant in 1. parameter direction
/// pardir = 2: constant in 2. parameter direction
bool isConstantCurve(double tol, int& pardir, double& parval) const;

/// Fetch recorded constant curve information
Expand Down
8 changes: 7 additions & 1 deletion gotools-core/include/GoTools/geometry/ElementarySurface.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,11 @@ class ElementarySurface : public ParamSurface
virtual void setParameterBounds(double from_upar, double from_vpar,
double to_upar, double to_vpar) = 0;


/// Fetch parameter bounds. NB! Not oriented
virtual RectDomain getParameterBounds() const = 0;

virtual void turnOrientation();
virtual void turnOrientation();
virtual void reverseParameterDirection(bool direction_is_u);
virtual void swapParameterDirection();

Expand Down Expand Up @@ -166,6 +167,11 @@ class ElementarySurface : public ParamSurface
return -1.0;
}

virtual double radius2(double u, double v) const
{
return -1.0;
}

virtual Point location() const
{
Point dummy;
Expand Down
3 changes: 2 additions & 1 deletion gotools-core/include/GoTools/geometry/Ellipse.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ class Ellipse : public ElementaryCurve
virtual void appendCurve(ParamCurve* cv, bool reparam=true);

virtual void appendCurve(ParamCurve* cv,
int continuity, double& dist, bool reparam=true);
int continuity, double& dist, bool reparam=true,
double tol = 1.0e-4);

virtual void closestPoint(const Point& pt,
double tmin,
Expand Down
4 changes: 2 additions & 2 deletions gotools-core/include/GoTools/geometry/GeometryTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -405,15 +405,15 @@ namespace GeometryTools
/// \param lc reference to the LineCloud that is to be rotated
void GO_API rotateLineCloud(Point rot_axis, double alpha, LineCloud& lc);

/// Rotate the given 3D point a certain angle around a certain axis.
/// Rotate the given 2D or 3D point a certain angle around a certain axis.
/// \param rot_axis the axis of rotation. It does not have to be normalized, but
/// must of course be nonzero.
/// \param alpha the angle of rotation, given in radians
/// \param space_pt pointer to the memory location where the 3D coordinates of
/// the point are stored. These will be overwritten with the
/// rotated coordinates.
void GO_API rotatePoint(Point rot_axis, double alpha, double* space_pt);
/// Rotate the given 3D point a certain angle around a certain axis.
/// Rotate the given 2D or 3D point a certain angle around a certain axis.
/// \param rot_axis the axis of rotation. It does not have to be normalized, but
/// must of course be nonzero.
/// \param alpha the angle of rotation, given in radians
Expand Down
6 changes: 6 additions & 0 deletions gotools-core/include/GoTools/geometry/GoIntersections.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ void intersectParamCurves(ParamCurve* cv1, ParamCurve* cv2, double epsge,
double epsge, std::vector<double >& intpar,
std::vector<std::pair<double,double> >& int_cvs);

/// Intersect a curve with a cylinder
void intersectCurveCylinder(ParamCurve* cv, const Point& pos,
const Point&axis, double radius,
double epsge, std::vector<double >& intpar,
std::vector<std::pair<double,double> >& int_cvs);

///Intersect two spline curves. Collect intersection parameters.
/// \param cv1 pointer to the first spline curve
/// \param cv2 pointer to the second spline curve
Expand Down
5 changes: 3 additions & 2 deletions gotools-core/include/GoTools/geometry/Hyperbola.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ class Hyperbola : public ElementaryCurve
virtual void appendCurve(ParamCurve* cv, bool reparam=true);

virtual void appendCurve(ParamCurve* cv,
int continuity, double& dist, bool reparam=true);
int continuity, double& dist, bool reparam=true,
double tol = 1.0e-4);

virtual void closestPoint(const Point& pt,
double tmin,
Expand All @@ -151,7 +152,7 @@ class Hyperbola : public ElementaryCurve
/// Query if parametrization is bounded. Both upper and lower
/// parameter bounds must be finite for this to be true.
/// \return \a true if bounded, \a false otherwise
bool isBounded() const;
virtual bool isBounded() const;

/// If the curve is 2 dimensional, x and y coordinates will be swapped.
/// Used when curve is a parameter curve.
Expand Down
5 changes: 3 additions & 2 deletions gotools-core/include/GoTools/geometry/Line.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ class Line : public ElementaryCurve
virtual void appendCurve(ParamCurve* cv, bool reparam=true);

virtual void appendCurve(ParamCurve* cv,
int continuity, double& dist, bool reparam=true);
int continuity, double& dist, bool reparam=true,
double tol = 1.0e-4);

virtual void closestPoint(const Point& pt,
double tmin,
Expand Down Expand Up @@ -165,7 +166,7 @@ class Line : public ElementaryCurve
/// Query if parametrization is bounded. Both upper and lower
/// parameter bounds must be finite for this to be true.
/// \return \a true if bounded, \a false otherwise
bool isBounded() const;
virtual bool isBounded() const;

/// Confirm that the curve is linear
virtual bool isLinear(Point& dir, double tol);
Expand Down
5 changes: 3 additions & 2 deletions gotools-core/include/GoTools/geometry/Parabola.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ class Parabola : public ElementaryCurve
virtual void appendCurve(ParamCurve* cv, bool reparam=true);

virtual void appendCurve(ParamCurve* cv,
int continuity, double& dist, bool reparam=true);
int continuity, double& dist, bool reparam=true,
double tol = 1.0e-4);

virtual void closestPoint(const Point& pt,
double tmin,
Expand All @@ -148,7 +149,7 @@ class Parabola : public ElementaryCurve
/// Query if parametrization is bounded. Both upper and lower
/// parameter bounds must be finite for this to be true.
/// \return \a true if bounded, \a false otherwise
bool isBounded() const;
virtual bool isBounded() const;

// Translate the curve along a given vector
virtual void translateCurve(const Point& dir);
Expand Down
9 changes: 8 additions & 1 deletion gotools-core/include/GoTools/geometry/ParamCurve.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,10 @@ class GO_API ParamCurve : public GeomObject
/// \param dist a measure of the local distorsion around the transition in order
/// to achieve the specified continuity.
/// \param reparam specify whether or not there should be reparametrization
/// \param tol relevant only for CurveOnSurface
virtual void appendCurve(ParamCurve* cv,
int continuity, double& dist, bool reparam=true) = 0;
int continuity, double& dist, bool reparam=true,
double tol = 1.0e-4) = 0;

/// Estimate the length of the curve, by sampling it at a certain number of points
/// and calculating the linear approximation to the curve through these points.
Expand Down Expand Up @@ -331,6 +333,11 @@ class GO_API ParamCurve : public GeomObject
// bounded curves and some elementary curves
}

virtual bool isBounded() const
{
return true; // Is overridden when an unbounded curve is possible
}

/// Check if the curve is linear
virtual bool isLinear(Point& dir, double tol);

Expand Down
7 changes: 5 additions & 2 deletions gotools-core/include/GoTools/geometry/Plane.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ class Plane : public ElementarySurface
/// Check for paralell and anti paralell partial derivatives in surface corners
virtual void getDegenerateCorners(std::vector<Point>& deg_corners, double tol) const;

virtual shared_ptr<ElementaryCurve>
getElementaryParamCurve(ElementaryCurve* space_crv, double tol,
const Point* start_par_pt = NULL, const Point* end_par_pt = NULL) const;
// --- Functions specific to Plane ---

/// Point in plane
Expand All @@ -179,7 +182,7 @@ class Plane : public ElementarySurface
{ return normal_; }

/// Vectors in plane
void getSpanningVectors(Point& axis1, Point& axis2)
void getSpanningVectors(Point& axis1, Point& axis2) const
{
axis1 = vec1_;
axis2 = vec2_;
Expand Down Expand Up @@ -228,7 +231,7 @@ class Plane : public ElementarySurface
/// \return \a true if bounded, \a false otherwise
virtual bool isBounded() const;

/// Check if the plane is closed. Virtual function - always false.
/// Check if the plane is closed. Virtual function - always false.
virtual bool isClosed(bool& closed_dir_u, bool& closed_dir_v) const;

/// Return the result from intersecting the unbounded plane with a
Expand Down
14 changes: 14 additions & 0 deletions gotools-core/include/GoTools/geometry/RectDomain.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@ class GO_API RectDomain : public Domain
virtual bool isOnBoundary(const Array<double, 2>& point,
double tolerance) const;

/// bd = -1 : Not a boundary point
/// bd = 0: umin
/// bd = 1: umax
/// bd = 2: vmin
/// bd = 3: vmax
/// bd2 = -1 : Not a corner point
/// otherwise: as bd
bool isOnBoundary(const Array<double, 2>& point,
double tolerance, int& bd, int& bd2) const;

/// Check if a given parameter pair lies on a corner in the domain within
/// the given tolerance
bool isOnCorner(const Array<double, 2>& point,
Expand Down Expand Up @@ -144,6 +154,10 @@ class GO_API RectDomain : public Domain
/// included
bool overlap(const RectDomain& rd, double tol);

/// Check if two domains overlap, boundary overlap within tolerance
/// dependent on parameter direction included
bool overlap(const RectDomain& rd, double tol1, double tol2);

/// Get the 'lower left' corner of this RectDomain.
/// \return a 2D array containing the 'lower left' corner of this RectDomain
Array<double, 2> lowerLeft() const { return ll_; }
Expand Down
Loading

0 comments on commit d9941d5

Please sign in to comment.