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;
72 cvs->ind_points_of_face(i).end());
80 cvs->ind_dir_points().end());
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>
167 convex<PT, PT_TAB> simplex(
const PT_TAB &t,
int nc)
171 template<
class PT,
class PT_TAB1,
class PT_TAB2>
172 convex<PT> convex_product(
const convex<PT, PT_TAB1> &cv1,
173 const convex<PT, PT_TAB2> &cv2)
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 bool compare(
const static_stored_object_key &oo)
const override {
188 auto &o =
dynamic_cast<const special_convex_structure_key_ &
>(oo);
191 bool equal(
const static_stored_object_key &oo)
const override {
192 auto &o =
dynamic_cast<const special_convex_structure_key_ &
>(oo);
193 if (p == o.p)
return true;
195 auto pkey = dal::key_of_stored_object(p);
196 auto poo_key = dal::key_of_stored_object(o.p);
197 return *pkey == *poo_key;
202 template<
class PT,
class PT_TAB1,
class PT_TAB2>
203 convex<PT> convex_direct_product(
const convex<PT, PT_TAB1> &cv1,
204 const convex<PT, PT_TAB2> &cv2) {
205 if (cv1.nb_points() == 0 || cv2.nb_points() == 0)
206 throw std::invalid_argument(
207 "convex_direct_product : null convex product");
210 dal::pstatic_stored_object_key
211 pcs = std::make_shared<special_convex_structure_key_>(cv1.structure());
213 dal::AUTODELETE_STATIC_OBJECT);
216 dal::pstatic_stored_object_key
217 pcs = std::make_shared<special_convex_structure_key_>(cv2.structure());
219 dal::AUTODELETE_STATIC_OBJECT);
222 r.points().resize(r.nb_points());
223 std::fill(r.points().begin(), r.points().end(), PT(r.structure()->dim()));
224 dim_type dim1 = cv1.structure()->dim();
225 typename PT_TAB1::const_iterator it1, it1e = cv1.points().end();
226 typename PT_TAB2::const_iterator it2, it2e = cv2.points().end();
227 typename convex<PT>::point_tab_type::iterator it = r.points().begin();
228 for (it2 = cv2.points().begin(); it2 != it2e; ++it2)
229 for (it1 = cv1.points().begin() ; it1 != it1e; ++it1, ++it)
231 std::copy((*it1).begin(), (*it1).end(), (*it).begin());
232 std::copy((*it2).begin(), (*it2).end(), (*it).begin()+dim1);
237 template<
class PT,
class PT_TAB>
238 convex<PT> convex_multiply(
const convex<PT, PT_TAB> &cv, dim_type n)
240 if (cv.nb_points() == 0 || n == 0)
241 throw std::invalid_argument(
242 "convex_multiply : null convex product");
243 convex<PT> r(multiply_convex_structure(cv.structure(), n));
244 r.points().resize(r.nb_points());
245 std::fill(r.points().begin(), r.points().end(), PT(r.structure()->dim()));
246 dim_type dim1 = cv.structure()->dim();
247 typename convex<PT>::point_tab_type::iterator it = r.points().begin();
248 typename PT_TAB::const_iterator it1 = cv.points().begin(), it2,
249 it1e = cv.points().end();
250 for (dim_type k = 0; k < n; ++k)
251 for (it2 = it1; it2 != it1e; ++it2) *it++ = *it2;
Definition of convex structures.
generic definition of a convex ( bgeot::convex_structure + vertices coordinates )
ref_convex_pt_ct dir_points() const
Return "direct" points.
dref_convex_pt_ct dir_points_of_face(short_type i) const
Direct points for a given face.
convex(pconvex_structure c, const PT_TAB &t)
Build a convex object.
indexed array reference (given a container X, and a set of indexes I, this class provides a pseudo-co...
gmm::uint16_type short_type
used as the common short type integer in the library
std::ostream & operator<<(std::ostream &o, const convex_structure &cv)
Print the details of the convex structure cvs to the output stream o.
std::shared_ptr< const convex_structure > pconvex_structure
Pointer on a convex structure description.
pconvex_structure simplex_structure(dim_type nc)
Give a pointer on the structures of a simplex of dimension d.
size_t size_type
used as the common size type in the library
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 ...
void add_stored_object(pstatic_stored_object_key k, pstatic_stored_object o, permanence perm)
Add an object with two optional dependencies.
bool exists_stored_object(pstatic_stored_object o)
Test if an object is stored.
iterator over a gmm::tab_ref_index_ref<ITER,ITER_INDEX>