38 #ifndef BGEOT_CONVEX_H__ 39 #define BGEOT_CONVEX_H__ 50 template<
class PT,
class PT_TAB = std::vector<PT> >
class convex {
53 typedef PT point_type;
54 typedef PT_TAB point_tab_type;
70 ref_convex_pt_ct points_of_face(
short_type i)
const {
71 return ref_convex_pt_ct(pts.begin(), cvs->ind_points_of_face(i).begin(),
72 cvs->ind_points_of_face(i).end());
79 return ref_convex_pt_ct(pts.begin(), cvs->ind_dir_points().begin(),
80 cvs->ind_dir_points().end());
86 return dref_convex_pt_ct(pts.begin(),
87 cvs->ind_dir_points_of_face(i).begin(),
88 cvs->ind_dir_points_of_face(i).end());
92 const PT_TAB &points()
const {
return pts; }
93 PT_TAB &points() {
return pts; }
94 short_type nb_points()
const {
return cvs->nb_points(); }
152 template<
class PT,
class PT_TAB>
153 std::ostream &operator <<(std::ostream &o, const convex<PT, PT_TAB> &cv)
155 o << *(cv.structure());
157 for (size_type i = 0; i < cv.nb_points(); ++i) o << cv.points()[i] <<
" ";
166 template<
class PT,
class PT_TAB>
171 template<
class PT,
class PT_TAB1,
class PT_TAB2>
175 typename convex<PT>::point_tab_type tab;
176 tab.resize(cv1.nb_points() * cv2.nb_points());
178 for (i = 0, k = 0; i < cv1.nb_points(); ++i)
179 for (j = 0; j < cv2.nb_points(); ++j, ++k)
180 { tab[k] = (cv1.points())[i]; tab[k] += (cv2.points())[j]; }
185 struct special_convex_structure_key_ :
virtual public dal::static_stored_object_key {
187 virtual bool compare(
const static_stored_object_key &oo)
const {
188 const special_convex_structure_key_ &o
189 =
dynamic_cast<const special_convex_structure_key_ &
>(oo);
190 if (p < o.p)
return true;
196 template<
class PT,
class PT_TAB1,
class PT_TAB2>
199 if (cv1.nb_points() == 0 || cv2.nb_points() == 0)
200 throw std::invalid_argument(
201 "convex_direct_product : null convex product");
204 dal::pstatic_stored_object_key
205 pcs = std::make_shared<special_convex_structure_key_>(cv1.structure());
207 dal::AUTODELETE_STATIC_OBJECT);
210 dal::pstatic_stored_object_key
211 pcs = std::make_shared<special_convex_structure_key_>(cv2.structure());
213 dal::AUTODELETE_STATIC_OBJECT);
216 r.points().resize(r.nb_points());
217 std::fill(r.points().begin(), r.points().end(), PT(r.structure()->dim()));
218 dim_type dim1 = cv1.structure()->dim();
219 typename PT_TAB1::const_iterator it1, it1e = cv1.points().end();
220 typename PT_TAB2::const_iterator it2, it2e = cv2.points().end();
222 for (it2 = cv2.points().begin(); it2 != it2e; ++it2)
223 for (it1 = cv1.points().begin() ; it1 != it1e; ++it1, ++it)
225 std::copy((*it1).begin(), (*it1).end(), (*it).begin());
226 std::copy((*it2).begin(), (*it2).end(), (*it).begin()+dim1);
231 template<
class PT,
class PT_TAB>
234 if (cv.nb_points() == 0 || n == 0)
235 throw std::invalid_argument(
236 "convex_multiply : null convex product");
237 convex<PT> r(multiply_convex_structure(cv.structure(), n));
238 r.points().resize(r.nb_points());
239 std::fill(r.points().begin(), r.points().end(), PT(r.structure()->dim()));
240 dim_type dim1 = cv.structure()->dim();
242 typename PT_TAB::const_iterator it1 = cv.points().begin(), it2,
243 it1e = cv.points().end();
244 for (dim_type k = 0; k < n; ++k)
245 for (it2 = it1; it2 != it1e; ++it2) *it++ = *it2;
indexed array reference (given a container X, and a set of indexes I, this class provides a pseudo-co...
iterator over a gmm::tab_ref_index_ref<ITER,ITER_INDEX>
dref_convex_pt_ct dir_points_of_face(short_type i) const
Direct points for a given face.
Definition of convex structures.
convex(pconvex_structure c, const PT_TAB &t)
Build a convex object.
generic definition of a convex ( bgeot::convex_structure + vertices coordinates ) ...
std::shared_ptr< const convex_structure > pconvex_structure
Pointer on a convex structure description.
size_t size_type
used as the common size type in the library
void add_stored_object(pstatic_stored_object_key k, pstatic_stored_object o, permanence perm)
Add an object with two optional dependencies.
pconvex_structure convex_product_structure(pconvex_structure a, pconvex_structure b)
Give a pointer on the structures of a convex which is the direct product of the convexes represented ...
ref_convex_pt_ct dir_points() const
Return "direct" points.
gmm::uint16_type short_type
used as the common short type integer in the library
bool exists_stored_object(pstatic_stored_object o)
Test if an object is stored.
pconvex_structure simplex_structure(dim_type nc)
Give a pointer on the structures of a simplex of dimension d.