mirror of https://github.com/CGAL/cgal
Rework image from/to operators
This commit is contained in:
parent
932098c897
commit
23687c02ae
|
|
@ -102,23 +102,36 @@ public:
|
||||||
*/
|
*/
|
||||||
Cartesian_grid_3(const Image_3& image)
|
Cartesian_grid_3(const Image_3& image)
|
||||||
{
|
{
|
||||||
from_image(image);
|
// compute bounding box
|
||||||
}
|
const FT max_x = image.tx() + (image.xdim() - 1) * image.vx();
|
||||||
|
const FT max_y = image.ty() + (image.ydim() - 1) * image.vy();
|
||||||
|
const FT max_z = image.tz() + (image.zdim() - 1) * image.vz();
|
||||||
|
m_bbox = Bbox_3{image.tx(), image.ty(), image.tz(), max_x, max_y, max_z};
|
||||||
|
|
||||||
/**
|
// get spacing
|
||||||
* \brief creates a Cartesian_grid_3 object from a `CGAL::Image_3`.
|
m_spacing = make_array(image.vx(), image.vy(), image.vz());
|
||||||
*
|
|
||||||
* The dimensions and bounding box are read from the image. The values stored
|
// get sizes
|
||||||
* in the image must be of type `Geom_traits::FT` or implicitly convertible to it.
|
m_sizes[0] = image.xdim();
|
||||||
*
|
m_sizes[1] = image.ydim();
|
||||||
* \param image the image providing the data
|
m_sizes[2] = image.zdim();
|
||||||
*/
|
|
||||||
void from_image(const Image_3& image);
|
// pre-allocate
|
||||||
|
const std::size_t nv = m_sizes[0] * m_sizes[1] * m_sizes[2];
|
||||||
|
m_values.resize(nv);
|
||||||
|
m_gradients.resize(nv);
|
||||||
|
|
||||||
|
// copy values
|
||||||
|
for(std::size_t x=0; x<m_sizes[0]; ++x)
|
||||||
|
for(std::size_t y=0; y<m_sizes[1]; ++y)
|
||||||
|
for(std::size_t z=0; z<m_sizes[2]; ++z)
|
||||||
|
value(x, y, z) = image.value(x, y, z);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief creates a `CGAL::Image_3` from the %Cartesian grid.
|
* \brief creates a `CGAL::Image_3` from the %Cartesian grid.
|
||||||
*/
|
*/
|
||||||
Image_3 to_image() const;
|
explicit operator Image_3() const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
|
|
@ -281,40 +294,8 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename GeomTraits>
|
template <typename GeomTraits>
|
||||||
void
|
|
||||||
Cartesian_grid_3<GeomTraits>::
|
Cartesian_grid_3<GeomTraits>::
|
||||||
from_image(const Image_3& image)
|
operator Image_3() const
|
||||||
{
|
|
||||||
// compute bounding box
|
|
||||||
const FT max_x = image.tx() + (image.xdim() - 1) * image.vx();
|
|
||||||
const FT max_y = image.ty() + (image.ydim() - 1) * image.vy();
|
|
||||||
const FT max_z = image.tz() + (image.zdim() - 1) * image.vz();
|
|
||||||
m_bbox = Bbox_3{image.tx(), image.ty(), image.tz(), max_x, max_y, max_z};
|
|
||||||
|
|
||||||
// get spacing
|
|
||||||
m_spacing = make_array(image.vx(), image.vy(), image.vz());
|
|
||||||
|
|
||||||
// get sizes
|
|
||||||
m_sizes[0] = image.xdim();
|
|
||||||
m_sizes[1] = image.ydim();
|
|
||||||
m_sizes[2] = image.zdim();
|
|
||||||
|
|
||||||
// pre-allocate
|
|
||||||
const std::size_t nv = m_sizes[0] * m_sizes[1] * m_sizes[2];
|
|
||||||
m_values.resize(nv);
|
|
||||||
m_gradients.resize(nv);
|
|
||||||
|
|
||||||
// copy values
|
|
||||||
for(std::size_t x=0; x<m_sizes[0]; ++x)
|
|
||||||
for(std::size_t y=0; y<m_sizes[1]; ++y)
|
|
||||||
for(std::size_t z=0; z<m_sizes[2]; ++z)
|
|
||||||
value(x, y, z) = image.value(x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename GeomTraits>
|
|
||||||
Image_3
|
|
||||||
Cartesian_grid_3<GeomTraits>::
|
|
||||||
to_image() const
|
|
||||||
{
|
{
|
||||||
// select number type
|
// select number type
|
||||||
WORD_KIND wordkind;
|
WORD_KIND wordkind;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue