change / rewrite volume and object function

This commit is contained in:
Michael Kirsch 2019-06-02 21:07:57 +02:00 committed by Joseph Lenox
parent 4e148608eb
commit 8928678085
2 changed files with 30 additions and 30 deletions

View File

@ -801,6 +801,14 @@ ModelObject::mirror(const Axis &axis)
this->invalidate_bounding_box();
}
void
ModelObject::apply_transformation(const TransformationMatrix & trafo)
{
for (ModelVolumePtrs::const_iterator v = this->volumes.begin(); v != this->volumes.end(); ++v) {
(*v)->apply_transformation(trafo);
}
}
void
ModelObject::transform_by_instance(ModelInstance instance, bool dont_translate)
{
@ -1023,39 +1031,27 @@ ModelVolume::swap(ModelVolume &other)
}
TriangleMesh
ModelVolume::get_transformed_mesh(TransformationMatrix const * additional_trafo) const
ModelVolume::get_transformed_mesh(TransformationMatrix const & trafo) const
{
TransformationMatrix trafo = this->trafo;
if(additional_trafo)
{
trafo.applyLeft(*(additional_trafo));
}
return this->mesh.get_transformed_mesh(trafo);
}
BoundingBoxf3
ModelVolume::get_transformed_bounding_box(TransformationMatrix const * additional_trafo) const
ModelVolume::get_transformed_bounding_box(TransformationMatrix const & trafo) const
{
TransformationMatrix trafo = this->trafo;
if(additional_trafo)
{
trafo.applyLeft(*(additional_trafo));
}
BoundingBoxf3 bbox;
for (int i = 0; i < this->mesh.stl.stats.number_of_facets; ++ i) {
const stl_facet &facet = this->mesh.stl.facet_start[i];
for (int j = 0; j < 3; ++ j) {
double v_x = facet.vertex[j].x;
double v_y = facet.vertex[j].y;
double v_z = facet.vertex[j].z;
Pointf3 poi;
poi.x = float(trafo.m11*v_x + trafo.m12*v_y + trafo.m13*v_z + trafo.m14);
poi.y = float(trafo.m21*v_x + trafo.m22*v_y + trafo.m23*v_z + trafo.m24);
poi.z = float(trafo.m31*v_x + trafo.m32*v_y + trafo.m33*v_z + trafo.m34);
bbox.merge(poi);
}
}
return bbox;
return this->mesh.get_transformed_bounding_box(trafo);
}
BoundingBoxf3
ModelVolume::bounding_box() const
{
return this->mesh.bounding_box();
}
void ModelVolume::apply_transformation(TransformationMatrix const & trafo)
{
this->mesh.transform(trafo);
this->trafo.applyLeft(trafo);
}
t_model_material_id

View File

@ -444,6 +444,9 @@ class ModelObject
/// \param copy_volumes bool whether to also copy its volumes or not, by default = true
ModelObject(Model *model, const ModelObject &other, bool copy_volumes = true);
/// Apply transformation to all volumes
void apply_transformation(const TransformationMatrix & trafo);
/// = Operator overloading
/// \param other ModelObject the other ModelObject to be copied
/// \return ModelObject& the current ModelObject to enable operator cascading
@ -485,9 +488,10 @@ class ModelVolume
/// Get the ModelVolume's mesh, transformed by the ModelVolume's TransformationMatrix
/// \param additional_trafo additional transformation
/// \return TriangleMesh the transformed mesh
TriangleMesh get_transformed_mesh(TransformationMatrix const * additional_trafo = nullptr) const;
TriangleMesh get_transformed_mesh(TransformationMatrix const & trafo) const;
BoundingBoxf3 get_transformed_bounding_box(TransformationMatrix const * additional_trafo = nullptr) const;
BoundingBoxf3 get_transformed_bounding_box(TransformationMatrix const & trafo) const;
BoundingBoxf3 bounding_box() const;
//Transformation matrix manipulators
@ -515,7 +519,7 @@ class ModelVolume
void rotate(double angle_rad, const Axis &axis) { this->trafo.rotate(angle_rad,axis); };
/// apply whichever matrix is supplied, multiplied from the left
void apply(TransformationMatrix const &trafo) { this->trafo.applyLeft(trafo); };
void apply_transformation(TransformationMatrix const &trafo);
/// Get the material id of this ModelVolume object
/// \return t_model_material_id the material id string