NurbsSurface.h
Go to the documentation of this file.
1 //Copyright (c) 2013-2023, The MercuryDPM Developers Team. All rights reserved.
2 //For the list of developers, see <http://www.MercuryDPM.org/Team>.
3 //
4 //Redistribution and use in source and binary forms, with or without
5 //modification, are permitted provided that the following conditions are met:
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above copyright
9 // notice, this list of conditions and the following disclaimer in the
10 // documentation and/or other materials provided with the distribution.
11 // * Neither the name MercuryDPM nor the
12 // names of its contributors may be used to endorse or promote products
13 // derived from this software without specific prior written permission.
14 //
15 //THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16 //ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 //WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 //DISCLAIMED. IN NO EVENT SHALL THE MERCURYDPM DEVELOPERS TEAM BE LIABLE FOR ANY
19 //DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 //(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 //LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22 //ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 //(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 //SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 
26 #ifndef MERCURYDPM_NURBSSURFACE_H
27 #define MERCURYDPM_NURBSSURFACE_H
28 
29 #include <vector>
30 #include <array>
31 #include "Math/Vector.h"
32 
34 {
35 public:
39  NurbsSurface();
40 
48  NurbsSurface(const std::vector<double>& knotsU, const std::vector<double>& knotsV,
49  const std::vector<std::vector<Vec3D>>& controlPoints,
50  const std::vector<std::vector<double>>& weights);
51 
63  NurbsSurface(const std::vector<std::vector<Vec3D>>& controlPoints,
64  const std::vector<std::vector<Mdouble>>& weights,
65  unsigned int degreeU, unsigned int degreeV,
66  bool clampedAtStartU = true, bool clampedAtEndU = true,
67  bool clampedAtStartV = true, bool clampedAtEndV = true);
68 
75  Vec3D evaluate(double u, double v) const;
76 
77  void evaluateDerivatives(double u, double v, std::array<std::array<Vec3D,3>,3>& S) const;
78 
82  bool getDistance(Vec3D P, double radius, double& distance, Vec3D& normal) const;
83 
91  void set(const std::vector<double>& knotsU, const std::vector<double>& knotsV,
92  const std::vector<std::vector<Vec3D>>& controlPoints, const std::vector<std::vector<double>>& weights);
93 
94  void setClosedInU(bool closedInU);
95 
96  void setClosedInV(bool closedInV);
97 
98  void flipOrientation();
99 
100  void closestPoint(Vec3D position, double& u, double& v) const;
101 
102  void splitSurface (int spanU, int spanV) {
103 
104  }
105 
109  friend std::ostream& operator<<(std::ostream& os, const NurbsSurface& a);
110 
114  friend std::istream& operator>>(std::istream& is, NurbsSurface& a);
115 
119  double getLowerBoundU() const{
120  return knotsU_[degreeU_];
121  }
125  double getUpperBoundU() const{
126  return knotsU_[knotsU_.size() - degreeU_ - 1]; // same as knotsU_[controlPoints.size()];
127  }
131  double getLowerBoundV() const{
132  return knotsV_[degreeV_];
133  }
137  double getUpperBoundV() const{
138  return knotsV_[knotsV_.size() - degreeV_ - 1]; // same as knotsV_[controlPoints[0].size()];
139  }
140 
141  const std::vector<std::vector<Vec3D>>& getControlPoints() const
142  { return controlPoints_; }
143 
144  const std::vector<std::vector<Mdouble>>& getWeights() const
145  { return weights_; }
146 
147  const std::vector<Mdouble>& getKnotsU() const
148  { return knotsU_; }
149 
150  const std::vector<Mdouble>& getKnotsV() const
151  { return knotsV_; }
152 
161 
170 
177  void makeClosedInU();
178 
185  void makeClosedInV();
186 
192  void unclampKnots(bool inU, bool atStart);
193 
194  void moveControlPoint(unsigned int indexU, unsigned int indexV, Vec3D dP, bool includingClosedOrPeriodic);
195 
196 private:
198  std::vector<Mdouble> knotsU_;
200  std::vector<Mdouble> knotsV_;
202  std::vector<std::vector<Vec3D>> controlPoints_;
204  std::vector<std::vector<Mdouble>> weights_;
206  unsigned int degreeU_, degreeV_;
209  // For when using periodic boundaries and the surface is extended to make it continuous
211 
212  // Storing starting points for a quick start of the getDistance method
213  std::vector<Vec3D> startingPoints_;
214  std::vector<Mdouble> startingKnotsU_;
215  std::vector<Mdouble> startingKnotsV_;
216 
224  void wrapAroundInU(unsigned int numStartToEnd, unsigned int numEndToStart, bool forceBothEndsUniform = false);
225 
233  void wrapAroundInV(unsigned int numStartToEnd, unsigned int numEndToStart, bool forceBothEndsUniform = false);
234 };
235 
236 #endif //MERCURYDPM_NURBSSURFACE_H
Definition: NurbsSurface.h:34
std::vector< Mdouble > startingKnotsU_
Definition: NurbsSurface.h:214
void makeClosedInU()
This will make the surface close around on itself and ensure continuity.
Definition: NurbsSurface.cc:471
Vec3D evaluate(double u, double v) const
Definition: NurbsSurface.cc:170
void closestPoint(Vec3D position, double &u, double &v) const
bool getDistance(Vec3D P, double radius, double &distance, Vec3D &normal) const
Definition: NurbsSurface.cc:198
unsigned int degreeU_
degree pu = mu-nu-1, pv = mv-nv-1
Definition: NurbsSurface.h:206
void setClosedInU(bool closedInU)
Definition: NurbsSurface.cc:142
void makeClosedInV()
This will make the surface close around on itself and ensure continuity.
Definition: NurbsSurface.cc:478
void setClosedInV(bool closedInV)
Definition: NurbsSurface.cc:146
unsigned int degreeV_
Definition: NurbsSurface.h:206
void makePeriodicContinuousInV()
This will make the surface repeat itself and ensure continuity over periodic boundaries.
Definition: NurbsSurface.cc:464
void wrapAroundInU(unsigned int numStartToEnd, unsigned int numEndToStart, bool forceBothEndsUniform=false)
Copies control points from the start and adds to the end and vice versa. The first and last control p...
Definition: NurbsSurface.cc:485
void splitSurface(int spanU, int spanV)
Definition: NurbsSurface.h:102
void evaluateDerivatives(double u, double v, std::array< std::array< Vec3D, 3 >, 3 > &S) const
Definition: NurbsSurface.cc:329
bool periodicInV_
Definition: NurbsSurface.h:210
const std::vector< std::vector< Vec3D > > & getControlPoints() const
Definition: NurbsSurface.h:141
bool closedInU_
make it a periodic system
Definition: NurbsSurface.h:208
std::vector< std::vector< Vec3D > > controlPoints_
nu x nv control points
Definition: NurbsSurface.h:202
const std::vector< std::vector< Mdouble > > & getWeights() const
Definition: NurbsSurface.h:144
void set(const std::vector< double > &knotsU, const std::vector< double > &knotsV, const std::vector< std::vector< Vec3D >> &controlPoints, const std::vector< std::vector< double >> &weights)
Definition: NurbsSurface.cc:60
void unclampKnots(bool inU, bool atStart)
Unclamps the knot vector by changing the control points, weights and knots.
Definition: NurbsSurface.cc:578
std::vector< Vec3D > startingPoints_
Definition: NurbsSurface.h:213
double getLowerBoundV() const
Definition: NurbsSurface.h:131
void makePeriodicContinuousInU()
This will make the surface repeat itself and ensure continuity over periodic boundaries.
Definition: NurbsSurface.cc:457
NurbsSurface()
Definition: NurbsSurface.cc:34
bool periodicInU_
Definition: NurbsSurface.h:210
void flipOrientation()
Definition: NurbsSurface.cc:150
void wrapAroundInV(unsigned int numStartToEnd, unsigned int numEndToStart, bool forceBothEndsUniform=false)
Copies control points from the start and adds to the end and vice versa. The first and last control p...
Definition: NurbsSurface.cc:538
std::vector< Mdouble > knotsU_
mu knots
Definition: NurbsSurface.h:198
friend std::istream & operator>>(std::istream &is, NurbsSurface &a)
Adds elements to an input stream.
Definition: NurbsSurface.cc:402
double getUpperBoundU() const
Definition: NurbsSurface.h:125
bool closedInV_
Definition: NurbsSurface.h:208
const std::vector< Mdouble > & getKnotsU() const
Definition: NurbsSurface.h:147
std::vector< Mdouble > knotsV_
mv knots
Definition: NurbsSurface.h:200
void moveControlPoint(unsigned int indexU, unsigned int indexV, Vec3D dP, bool includingClosedOrPeriodic)
Definition: NurbsSurface.cc:658
friend std::ostream & operator<<(std::ostream &os, const NurbsSurface &a)
Adds elements to an output stream.
Definition: NurbsSurface.cc:376
const std::vector< Mdouble > & getKnotsV() const
Definition: NurbsSurface.h:150
double getLowerBoundU() const
Definition: NurbsSurface.h:119
double getUpperBoundV() const
Definition: NurbsSurface.h:137
std::vector< Mdouble > startingKnotsV_
Definition: NurbsSurface.h:215
std::vector< std::vector< Mdouble > > weights_
nu x nv weights
Definition: NurbsSurface.h:204
Definition: Vector.h:51
double P
Uniform pressure.
Definition: TwenteMeshGluing.cpp:73