42 #ifndef CORE_DATATYPES_STRUCTCURVEMESH_H
43 #define CORE_DATATYPES_STRUCTCURVEMESH_H 1
66 template <
class Basis>
80 #if (SCIRUN_STRUCTCURVE_SUPPORT > 0)
87 template <
class Basis>
88 class StructCurveMesh :
public ScanlineMesh<Basis>
115 virtual bool get_dim(std::vector<size_type>&)
const;
116 virtual void set_dim(std::vector<size_type> dims) {
119 points_.resize(dims[0]);
172 {
return (idx == 0 || idx == static_cast<index_type>((points_.size()-1)) ? 1 : 2); }
207 std::vector<double>& coords,
217 {
ASSERTFAIL(
"StructCurveMesh::get_weights for faces isn't supported"); }
220 {
ASSERTFAIL(
"StructCurveMesh::get_weights for cells isn't supported"); }
233 {
ASSERTFAIL(
"This mesh type does not have node normals."); }
238 {
ASSERTFAIL(
"This mesh type does not have element normals."); }
274 return mesh_.points_[index_];
279 return mesh_.points_[index_+1];
294 unsigned int div_per_unit)
const
298 this->
basis_.approx_edge(0, div_per_unit, coords);
315 template<
class VECTOR,
class INDEX>
319 return this->
basis_.get_coords(coords, p, ed);
324 template<
class VECTOR,
class INDEX>
328 pt = this->
basis_.interpolate(coords, ed);
335 template<
class VECTOR1,
class VECTOR2>
341 this->
basis_.derivate(coords, ed, J);
347 template<
class VECTOR>
359 template<
class VECTOR>
366 this->
basis_.derivate(coords,ed,Jv);
384 template<
class VECTOR>
391 this->
basis_.derivate(coords,ed,Jv);
408 template<
class INDEX>
424 size_t num_vertices = this->
basis_.number_of_vertices();
425 for (
size_t j=0;j < num_vertices;j++)
427 this->
basis_.derivate(this->
basis_.unit_vertices[j],ed,Jv);
433 if(temp < min_jacobian) min_jacobian = temp;
436 return (min_jacobian);
440 template<
class INDEX>
456 size_t num_vertices = this->
basis_.number_of_vertices();
457 for (
size_t j=0;j < num_vertices;j++)
459 this->
basis_.derivate(this->
basis_.unit_vertices[j],ed,Jv);
465 if(temp < min_jacobian) min_jacobian = temp;
468 return (min_jacobian);
471 template <
class INDEX>
476 if (points_.size() == 0)
return (
false);
482 double mindist = DBL_MAX;
486 double dist = (p-points_[*ni]).length2();
487 if ( dist < mindist )
490 idx =
static_cast<INDEX
>(*ni);
492 if (mindist < epsilon2_)
return (
true);
501 template <
class INDEX>
510 if (sz == 0)
return (
false);
515 if (idx >= 0 && idx < sz)
517 if (inside2_p(idx,p,alpha))
return (
true);
528 if (inside2_p(*ei,p,alpha))
530 idx =
static_cast<INDEX
>(*ei);
539 template <
class INDEX,
class ARRAY>
548 if (sz == 0)
return (
false);
554 if (idx >= 0 && idx < sz)
556 if (inside2_p(idx,p,coords[0]))
return (
true);
567 if (inside2_p(*ei,p,alpha))
570 idx =
static_cast<INDEX
>(*ei);
580 template <
class INDEX>
588 template <
class INDEX>
591 double maxdist)
const
593 if (maxdist < 0.0) maxdist = DBL_MAX;
else maxdist = maxdist*maxdist;
598 if (sz == 0)
return (
false);
609 if (idx >= 0 && idx < sz)
612 dist = (point-p2).length2();
614 if ( dist < epsilon2_ )
623 double mindist = maxdist;
628 dist = (point-p2).length2();
630 if ( dist < mindist )
633 idx =
static_cast<INDEX
>(*ni);
635 if (mindist < epsilon2_)
637 pdist = sqrt(mindist);
644 if (maxdist == mindist)
return (
false);
646 pdist = sqrt(mindist);
652 template <
class INDEX,
class ARRAY>
663 template <
class INDEX,
class ARRAY>
669 double maxdist)
const
671 if (maxdist < 0.0) maxdist = DBL_MAX;
else maxdist = maxdist*maxdist;
676 if (sz == 0)
return (
false);
688 if (idx >= 0 && idx < sz)
691 dist = distance2_p(idx,p,result,alpha);
692 if ( dist < epsilon2_ )
701 double mindist = maxdist;
707 dist = distance2_p(*ni,p,res,alpha);
708 if ( dist < mindist )
712 idx =
static_cast<INDEX
>(*ni);
714 if (mindist < epsilon2_)
716 pdist = sqrt(mindist);
723 if (mindist == maxdist)
return (
false);
725 pdist = sqrt(mindist);
729 template <
class INDEX>
740 template<
class ARRAY>
750 if (sz == 0)
return (
false);
760 double mindist = DBL_MAX;
766 dist = distance2_p(*ni,p,res,dummy);
768 if (dist < mindist - epsilon2_)
772 elems.push_back(static_cast<typename ARRAY::value_type>(*ni));
775 else if (dist < mindist)
777 elems.push_back(static_cast<typename ARRAY::value_type>(*ni));
782 pdist = sqrt(mindist);
794 static const std::string
type_name(
int n = -1);
807 std::vector<Core::Geometry::Point>&
get_points() {
return (points_); }
821 void compute_epsilon();
823 std::vector<Core::Geometry::Point> points_;
831 template <
class Basis>
837 template <
class Basis>
840 synchronize_lock_(
"Synchronize lock"),
841 synchronized_(
Mesh::ALL_ELEMENTS_E),
854 template <
class Basis>
858 synchronize_lock_(
"StructCurveMesh lock"),
859 synchronized_(
Mesh::EDGES_E |
Mesh::NODES_E),
872 template <
class Basis>
875 points_(copy.points_),
876 synchronize_lock_(
"StructCurveMesh lock"),
877 synchronized_(copy.synchronized_)
881 copy.synchronize_lock_.lock();
886 epsilon_ = copy.epsilon_;
887 epsilon2_ = copy.epsilon2_;
889 copy.synchronize_lock_.unlock();
898 template <
class Basis>
905 array.push_back(this->ni_);
911 template <
class Basis>
918 template <
class Basis>
923 epsilon2_ = epsilon_*epsilon_;
926 template <
class Basis>
938 result.
extend(points_[*i]);
946 template <
class Basis>
956 points_[*i] = t.
project(points_[*i]);
963 template <
class Basis>
977 result += (points_[*i] - points_[*i1]).length();
985 template <
class Basis>
995 template <
class Basis>
999 result = points_[idx];
1003 template <
class Basis>
1014 template <
class Basis>
1025 if (alpha < 0.0) { point = p0; alpha = 0.0; }
1026 else if (alpha > 1.0) { point = p1; alpha = 1.0; }
1027 else { point = (alpha*p0 + (1.0-alpha)*p1).asPoint(); }
1029 if ((point - p).length2() < epsilon2_)
return (
true);
1035 template <
class Basis>
1037 StructCurveMesh<Basis>::distance2_p(
index_type i,
1038 const Core::Geometry::Point &p,
1039 Core::Geometry::Point& result,
1040 double& alpha)
const
1042 const Core::Geometry::Point &p0 = points_[i];
1043 const Core::Geometry::Point &p1 = points_[i+1];
1045 const Core::Geometry::Vector v = p1-p0;
1046 alpha =
Dot(p0-p,v)/v.length2();
1048 if (alpha < 0.0) { result = p0; alpha = 0.0; }
1049 else if (alpha > 1.0) { result = p1; alpha = 1.0; }
1050 else { result = (alpha*p0 + (1.0-alpha)*p1).asPoint(); }
1052 double dist = (result - p).length2();
1053 return (sqrt(dist));
1057 template <
class Basis>
1067 std::vector<double> coords(1);
1068 if (get_coords(coords, p, idx))
1070 this->basis_.get_weights(coords, w);
1071 return this->basis_.dofs();
1078 template <
class Basis>
1096 template <
class Basis>
1105 p = p0 + (p1 - p0) * rng();
1109 template <
class Basis>
1113 synchronize_lock_.lock();
1121 synchronize_lock_.unlock();
1125 template <
class Basis>
1133 template <
class Basis>
1137 synchronize_lock_.lock();
1144 synchronize_lock_.unlock();
1149 #define STRUCT_CURVE_MESH_VERSION 1
1151 template <
class Basis>
1159 Pio(stream, points_);
1168 template <
class Basis>
1172 ASSERT((n >= -1) && n <= 1);
1180 static const std::string nm(
"StructCurveMesh");
1190 template <
class Basis>
1201 std::string(__FILE__),
1209 template <
class Basis>
1210 const TypeDescription*
static const std::string type_name(int n=-1)
Core functionality for getting the name of a templated mesh class.
Definition: StructCurveMesh.h:1170
VMesh * CreateVStructCurveMesh(MESH *mesh)
Definition: StructCurveMesh.h:73
int get_valence(typename ScanlineMesh< Basis >::Node::index_type idx) const
Definition: StructCurveMesh.h:171
bool reading() const
Definition: Persistent.h:164
Distinct type for node FieldIterator.
Definition: FieldIterator.h:89
void get_normal(Core::Geometry::Vector &, std::vector< double > &, typename ScanlineMesh< Basis >::Elem::index_type, unsigned int)
Definition: StructCurveMesh.h:235
Definition: FieldRNG.h:37
virtual ~StructCurveMesh()
Definition: StructCurveMesh.h:105
virtual const TypeDescription * get_type_description() const
Definition: StructCurveMesh.h:1211
void end(typename Node::iterator &) const
Definition: ScanlineMesh.h:1118
void jacobian(const VECTOR &coords, typename ScanlineMesh< Basis >::Elem::index_type idx, double *J) const
Definition: StructCurveMesh.h:360
bool locate_node(INDEX &idx, const Core::Geometry::Point &p) const
Definition: StructCurveMesh.h:472
Definition: Persistent.h:89
Declarations for virtual interface.
Definition: StructCurveMesh.h:67
int get_valence(typename ScanlineMesh< Basis >::Face::index_type) const
Definition: StructCurveMesh.h:176
SCIRun::mask_type mask_type
Definition: StructCurveMesh.h:99
boost::shared_ptr< VMesh > vmesh_
Definition: ScanlineMesh.h:806
double get_size(typename ScanlineMesh< Basis >::Cell::index_type) const
Definition: StructCurveMesh.h:162
int get_weights(const Core::Geometry::Point &, typename ScanlineMesh< Basis >::Face::array_type &, double *)
Definition: StructCurveMesh.h:215
virtual void io(Piostream &)
Export this class using the old Pio system.
Definition: StructCurveMesh.h:1153
double get_area(typename ScanlineMesh< Basis >::Face::index_type idx) const
Definition: StructCurveMesh.h:166
Definition: Persistent.h:187
int get_weights(const Core::Geometry::Point &, typename ScanlineMesh< Basis >::Cell::array_type &, double *)
Definition: StructCurveMesh.h:218
virtual int topology_geometry() const
Definition: StructCurveMesh.h:127
BBox & extend(const Point &p)
Expand the bounding box to include point p.
Definition: BBox.h:98
SCIRun::size_type size_type
Definition: ScanlineMesh.h:109
Definition: TypeDescription.h:50
T Dot(const ColumnMatrixGeneric< T > &a, const ColumnMatrixGeneric< T > &b)
Definition: ColumnMatrixFunctions.h:155
void interpolate(Core::Geometry::Point &pt, const VECTOR &coords, INDEX idx) const
Definition: StructCurveMesh.h:325
Definition: TypeDescription.h:45
#define SCISHARE
Definition: share.h:39
std::vector< const TypeDescription * > td_vec
Definition: TypeDescription.h:56
std::vector< index_type > array_type
Definition: ScanlineMesh.h:141
Definition: ScanlineMesh.h:76
NodeIndex< under_type > index_type
Definition: ScanlineMesh.h:117
bool clear_synchronization()
Definition: StructCurveMesh.h:1135
bool locate(typename ScanlineMesh< Basis >::Edge::index_type &idx, const Core::Geometry::Point &point) const
Definition: StructCurveMesh.h:196
void get_center(Core::Geometry::Point &, const typename ScanlineMesh< Basis >::Cell::index_type &) const
Definition: StructCurveMesh.h:189
double scaled_jacobian_metric(INDEX idx) const
Definition: StructCurveMesh.h:409
boost::shared_ptr< Mesh > MeshHandle
Definition: DatatypeFwd.h:67
unsigned int mask_type
Definition: Types.h:45
static MeshHandle structcurve_maker(size_type x)
This function returns a handle for the virtual interface.
Definition: StructCurveMesh.h:805
Definition: StructCurveMesh.h:240
Point & asPoint() const
Definition: Vector.h:457
#define ASSERT(condition)
Definition: Assert.h:110
bool find_closest_node(double &pdist, Core::Geometry::Point &result, INDEX &idx, const Core::Geometry::Point &point, double maxdist) const
Find the closest element to a point.
Definition: StructCurveMesh.h:589
void get_nodes(typename ScanlineMesh< Basis >::Node::array_type &, typename ScanlineMesh< Basis >::Face::index_type) const
Definition: StructCurveMesh.h:135
bool find_closest_elem(double &pdist, Core::Geometry::Point &result, ARRAY &coords, INDEX &idx, const Core::Geometry::Point &p, double maxdist) const
Find the closest element to a point.
Definition: StructCurveMesh.h:664
void get_normal(Core::Geometry::Vector &, typename ScanlineMesh< Basis >::Node::index_type) const
Definition: StructCurveMesh.h:231
const Core::Geometry::Point & node1() const
Definition: StructCurveMesh.h:277
virtual int begin_class(const std::string &name, int current_version)
Definition: Persistent.cc:143
bool locate_elem(INDEX &idx, ARRAY &coords, const Core::Geometry::Point &p) const
Definition: StructCurveMesh.h:540
Core::Geometry::Vector diagonal() const
Definition: ScanlineMesh.h:869
index_type node0_index() const
the following designed to coordinate with ::get_nodes
Definition: StructCurveMesh.h:253
double DetMatrix3P(const VectorOfPoints &p)
Inline templated determinant of matrix.
Definition: Locate.h:120
bool locate(typename ScanlineMesh< Basis >::Node::index_type &idx, const Core::Geometry::Point &point) const
Definition: StructCurveMesh.h:193
const string find_type_name(float *)
Definition: TypeName.cc:63
virtual Core::Geometry::BBox get_bounding_box() const
Definition: StructCurveMesh.h:928
double get_size(typename ScanlineMesh< Basis >::Node::index_type) const
Get the size of an elemnt (length, area, volume)
Definition: StructCurveMesh.h:148
std::vector< Core::Geometry::Point > & get_points()
Definition: StructCurveMesh.h:807
double length2() const
Definition: Vector.h:248
void get_center(Core::Geometry::Point &, const typename ScanlineMesh< Basis >::Face::index_type &) const
Definition: StructCurveMesh.h:186
T DetMatrix3x3(const T *p)
Definition: Locate.h:95
double get_length(typename ScanlineMesh< Basis >::Edge::index_type idx) const
Definition: StructCurveMesh.h:164
void get_nodes(typename ScanlineMesh< Basis >::Node::array_type &, typename ScanlineMesh< Basis >::Edge::index_type) const
get the child elements of the given index
Definition: StructCurveMesh.h:987
double inverse_jacobian(const VECTOR &coords, typename ScanlineMesh< Basis >::Elem::index_type idx, double *Ji) const
Definition: StructCurveMesh.h:385
static PersistentTypeID scanline_typeid
Definition: StructCurveMesh.h:792
const char * name[]
Definition: BoostGraphExampleTests.cc:87
bool get_coords(VECTOR &coords, const Core::Geometry::Point &p, INDEX idx) const
Definition: StructCurveMesh.h:316
long long size_type
Definition: Types.h:40
void get_edges(typename ScanlineMesh< Basis >::Edge::array_type &a, typename ScanlineMesh< Basis >::Edge::index_type idx) const
Definition: StructCurveMesh.h:143
double get_size(typename ScanlineMesh< Basis >::Edge::index_type idx) const
Definition: StructCurveMesh.h:150
void pwl_approx_edge(std::vector< std::vector< double > > &coords, typename ScanlineMesh< Basis >::Elem::index_type, unsigned int, unsigned int div_per_unit) const
piecewise linear approximation of an edge.
Definition: StructCurveMesh.h:291
double ScaledDetMatrix3P(const VectorOfPoints &p)
Inline templated determinant of matrix.
Definition: Locate.h:132
SCISHARE void find_orthogonal(Vector &, Vector &) const
Definition: Vector.cc:59
int get_valence(typename ScanlineMesh< Basis >::Edge::index_type) const
Definition: StructCurveMesh.h:174
bool locate(typename ScanlineMesh< Basis >::Cell::index_type &, const Core::Geometry::Point &) const
Definition: StructCurveMesh.h:202
SCIRun::index_type under_type
Types that change depending on 32 or 64bits.
Definition: StructCurveMesh.h:96
Persistent i/o for STL containers.
bool find_closest_node(double &pdist, Core::Geometry::Point &result, INDEX &idx, const Core::Geometry::Point &point) const
Definition: StructCurveMesh.h:581
double jacobian_metric(INDEX idx) const
Definition: StructCurveMesh.h:441
int get_weights(const Core::Geometry::Point &, typename ScanlineMesh< Basis >::Node::array_type &, double *w)
Definition: StructCurveMesh.h:1059
void get_point(Core::Geometry::Point &p, typename ScanlineMesh< Basis >::Node::index_type i) const
Definition: StructCurveMesh.h:222
Distinct type for face index.
Definition: FieldIndex.h:90
void get_edges(typename ScanlineMesh< Basis >::Edge::array_type &, typename ScanlineMesh< Basis >::Face::index_type) const
Definition: StructCurveMesh.h:139
void pwl_approx_face(std::vector< std::vector< std::vector< double > > > &, typename ScanlineMesh< Basis >::Elem::index_type, typename ScanlineMesh< Basis >::Face::index_type, unsigned int) const
Definition: StructCurveMesh.h:303
void x(double)
Definition: Vector.h:175
Basis basis_
the basis fn
Definition: ScanlineMesh.h:804
StructCurveMesh()
Definition: StructCurveMesh.h:838
bool find_closest_elems(double &pdist, Core::Geometry::Point &result, ARRAY &elems, const Core::Geometry::Point &p) const
Find the closest elements to a point.
Definition: StructCurveMesh.h:741
static const std::string make_template_id(const std::string &templateName, const std::string &templateParam)
Definition: TypeName.h:62
void derivate(const VECTOR1 &coords, typename ScanlineMesh< Basis >::Elem::index_type idx, VECTOR2 &J) const
Definition: StructCurveMesh.h:336
v
Definition: readAllFields.py:42
index_type edge0_index() const
the following designed to coordinate with ::get_edges
Definition: StructCurveMesh.h:266
double get_epsilon() const
Definition: StructCurveMesh.h:913
double get_cord_length() const
get the mesh statistics
Definition: StructCurveMesh.h:965
bool find_closest_elem(double &pdist, Core::Geometry::Point &result, ARRAY &coords, INDEX &idx, const Core::Geometry::Point &p) const
Find the closest element to a point.
Definition: StructCurveMesh.h:653
virtual bool synchronize(mask_type sync)
Definition: StructCurveMesh.h:1111
void y(double)
Definition: Vector.h:185
void begin(typename Node::iterator &) const
Definition: ScanlineMesh.h:1110
virtual void io(Piostream &)
Export this class using the old Pio system.
Definition: ScanlineMesh.h:1044
Distinct type for edge Iterator.
Definition: FieldIterator.h:105
#define ASSERTFAIL(string)
Definition: Assert.h:52
std::vector< index_type > array_type
Definition: ScanlineMesh.h:134
virtual void set_dim(std::vector< size_type > dims)
Definition: StructCurveMesh.h:116
bool locate_elem(INDEX &idx, const Core::Geometry::Point &p) const
Definition: StructCurveMesh.h:502
void Pio(Piostream &stream, Array1< T > &array)
Definition: Array1.h:65
virtual bool get_dim(std::vector< size_type > &) const
Definition: StructCurveMesh.h:900
#define STRUCT_CURVE_MESH_VERSION
Definition: StructCurveMesh.h:1149
void get_center(Core::Geometry::Point &, const typename ScanlineMesh< Basis >::Node::index_type &) const
get the center point (in object space) of an element
Definition: StructCurveMesh.h:997
double length() const
Definition: Vector.h:365
virtual void end_class()
Definition: Persistent.cc:178
std::vector< index_type > array_type
Definition: ScanlineMesh.h:127
friend class VStructCurveMesh
Make sure the virtual interface has access.
Definition: StructCurveMesh.h:92
int get_valence(typename ScanlineMesh< Basis >::Cell::index_type) const
Definition: StructCurveMesh.h:178
long long index_type
Definition: Types.h:39
const Core::Geometry::Point & node0() const
Definition: StructCurveMesh.h:272
void resize(size_t size, const value_type &val=value_type())
Definition: StackVector.h:61
Templated Mesh defined on a 3D Regular Grid.
static Persistent * maker()
This function returns a maker for Pio.
Definition: StructCurveMesh.h:801
bool locate(typename ScanlineMesh< Basis >::Face::index_type &, const Core::Geometry::Point &) const
Definition: StructCurveMesh.h:199
bool find_closest_elem(double &pdist, Core::Geometry::Point &result, INDEX &elem, const Core::Geometry::Point &p) const
Definition: StructCurveMesh.h:730
StructCurveMesh< Basis >::index_type index_type
Definition: StructCurveMesh.h:243
void set_point(const Core::Geometry::Point &p, typename ScanlineMesh< Basis >::Node::index_type i)
Definition: StructCurveMesh.h:224
double det_jacobian(const VECTOR &coords, typename ScanlineMesh< Basis >::Elem::index_type idx) const
Definition: StructCurveMesh.h:348
void size(typename Node::size_type &) const
Definition: ScanlineMesh.h:1126
double get_volume(typename ScanlineMesh< Basis >::Cell::index_type idx) const
Definition: StructCurveMesh.h:168
Definition: Persistent.h:64
ElemData(const StructCurveMesh< Basis > &msh, const typename ScanlineMesh< Basis >::Elem::index_type ind)
Definition: StructCurveMesh.h:245
void get_random_point(Core::Geometry::Point &p, const typename ScanlineMesh< Basis >::Elem::index_type idx, FieldRNG &rng) const
Definition: StructCurveMesh.h:1098
virtual StructCurveMesh * clone() const
Definition: StructCurveMesh.h:104
void get_nodes(typename ScanlineMesh< Basis >::Node::array_type &, typename ScanlineMesh< Basis >::Cell::index_type) const
Definition: StructCurveMesh.h:137
Distinct type for edge index.
Definition: FieldIndex.h:81
int n
Definition: eab.py:9
bool locate(typename ScanlineMesh< Basis >::Elem::index_type &idx, std::vector< double > &coords, const Core::Geometry::Point &point)
Definition: StructCurveMesh.h:206
T InverseMatrix3x3(const T *p, T *q)
Definition: Locate.h:47
double get_size(typename ScanlineMesh< Basis >::Face::index_type) const
Definition: StructCurveMesh.h:160
SCIRun::size_type size_type
Definition: StructCurveMesh.h:98
#define DEBUG_CONSTRUCTOR(type)
Definition: Debug.h:64
virtual void transform(const Core::Geometry::Transform &t)
Definition: StructCurveMesh.h:948
SCIRun::index_type index_type
Definition: StructCurveMesh.h:97
static MeshHandle mesh_maker()
This function returns a handle for the virtual interface.
Definition: StructCurveMesh.h:803
index_type node1_index() const
Definition: StructCurveMesh.h:258
void get_edges(typename ScanlineMesh< Basis >::Edge::array_type &, typename ScanlineMesh< Basis >::Cell::index_type) const
Definition: StructCurveMesh.h:141
void z(double)
Definition: Vector.h:195
virtual bool unsynchronize(mask_type sync)
Definition: StructCurveMesh.h:1127
SCIRun::mask_type mask_type
Definition: ScanlineMesh.h:110
#define DEBUG_DESTRUCTOR(type)
Definition: Debug.h:65
const TypeDescription * get_type_description(Core::Basis::ConstantBasis< T > *)
Definition: Constant.h:209
Interface to dynamic 2D array class.
bool elem_locate(INDEX &elem, MESH &msh, const Core::Geometry::Point &p)
General case locate, search each elem.
Definition: Mesh.h:188