mirror of https://github.com/CGAL/cgal
Correction for draw triangulation 3
This commit is contained in:
parent
c1037f9040
commit
a569437a14
|
|
@ -23,62 +23,25 @@
|
|||
#include <CGAL/Qt/init_ogl_context.h>
|
||||
#include <CGAL/Random.h>
|
||||
#include <CGAL/Triangulation_3.h>
|
||||
#include <CGAL/GraphicBuffer.h>
|
||||
|
||||
namespace CGAL {
|
||||
|
||||
// Default color functor; user can change it to have its own face color
|
||||
struct DefaultColorFunctorT3 {
|
||||
template <typename T3>
|
||||
static CGAL::IO::Color run(const T3 &,
|
||||
const typename T3::Finite_facets_iterator *fh) {
|
||||
if (fh == nullptr) // use to get the mono color
|
||||
return CGAL::IO::Color(100, 125, 200); // R G B between 0-255
|
||||
namespace draw_function_for_t3
|
||||
{
|
||||
|
||||
CGAL::Random random((unsigned int)((std::size_t)(&*((*fh)->first)) +
|
||||
(std::size_t)((*fh)->second)));
|
||||
return get_random_color(random);
|
||||
}
|
||||
};
|
||||
|
||||
namespace draw_function_for_t3 {
|
||||
|
||||
template <typename BufferType = float, class T3, class ColorFunctor>
|
||||
template <typename BufferType = float, class T3, class DrawingFunctor>
|
||||
void compute_face(typename T3::Finite_facets_iterator fh,
|
||||
GraphicBuffer<BufferType> &graphic_buffer, const T3 *t3,
|
||||
const ColorFunctor &m_fcolor) {
|
||||
|
||||
/*
|
||||
// QUESTION: I would like to assign custom color functor during run time, which one down is right?
|
||||
|
||||
// Solution 1 to assign custom color functor.
|
||||
// m_fcolor.face_color = DefaultColorFunctorT3::run;
|
||||
|
||||
// Solution 2 to assign custom color functor.
|
||||
// m_fcolor.face_color =
|
||||
// [](const T3 &,
|
||||
// const typename T3::Finite_facets_iterator *fh) -> CGAL::IO::Color {
|
||||
// if (fh == nullptr) // use to get the mono color
|
||||
// return CGAL::IO::Color(100, 125, 200); // R G B between 0-255
|
||||
|
||||
// CGAL::Random random((unsigned int)((std::size_t)(&*((*fh)->first)) +
|
||||
// (std::size_t)((*fh)->second)));
|
||||
|
||||
// return get_random_color(random);
|
||||
// };
|
||||
// CGAL::IO::Color c = m_fcolor.face_color(*t3, &fh);
|
||||
|
||||
|
||||
// Solution 3 to assign custom color functor.
|
||||
m_fcolor.test_m = []() -> void {std::cout << "Hello\n";};
|
||||
std::invoke(&ColorFunctor::test_m, m_fcolor);
|
||||
|
||||
I tried the above solutions but they don't work.
|
||||
*/
|
||||
|
||||
// TODO: change it to m_fcolor.face_color(*t3, fh)
|
||||
CGAL::IO::Color c = m_fcolor.run(*t3, &fh);
|
||||
|
||||
graphic_buffer.face_begin(c);
|
||||
const DrawingFunctor &drawing_functor,
|
||||
CGAL::GraphicBuffer<BufferType> &graphic_buffer, const T3 *t3)
|
||||
{
|
||||
if(drawing_functor.face_color)
|
||||
{
|
||||
CGAL::IO::Color c = drawing_functor.face_color(*t3, fh);
|
||||
graphic_buffer.face_begin(c);
|
||||
}
|
||||
else
|
||||
{ graphic_buffer.face_begin(); }
|
||||
|
||||
graphic_buffer.add_point_in_face(
|
||||
fh->first->vertex((fh->second + 1) % 4)->point());
|
||||
|
|
@ -92,71 +55,95 @@ void compute_face(typename T3::Finite_facets_iterator fh,
|
|||
|
||||
template <typename BufferType = float, class T3>
|
||||
void compute_edge(typename T3::Finite_edges_iterator eh,
|
||||
GraphicBuffer<BufferType> &graphic_buffer) {
|
||||
CGAL::GraphicBuffer<BufferType> &graphic_buffer) {
|
||||
graphic_buffer.add_segment(eh->first->vertex(eh->second)->point(),
|
||||
eh->first->vertex(eh->third)->point());
|
||||
}
|
||||
|
||||
template <typename BufferType = float, class T3>
|
||||
void compute_vertex(typename T3::Vertex_handle vh,
|
||||
GraphicBuffer<BufferType> &graphic_buffer) {
|
||||
CGAL::GraphicBuffer<BufferType> &graphic_buffer) {
|
||||
graphic_buffer.add_point(vh->point());
|
||||
}
|
||||
|
||||
template <typename BufferType = float, class T3, class ColorFunctor>
|
||||
void compute_elements(GraphicBuffer<BufferType> &graphic_buffer, const T3 *t3,
|
||||
const ColorFunctor &m_color_functor,
|
||||
template <typename BufferType = float, class T3, class DrawingFunctor>
|
||||
void compute_elements(CGAL::GraphicBuffer<BufferType> &graphic_buffer, const T3 *t3,
|
||||
const DrawingFunctor &drawing_functor,
|
||||
bool m_nofaces = false) {
|
||||
|
||||
if (!m_nofaces) {
|
||||
for (typename T3::Finite_facets_iterator it = t3->finite_facets_begin();
|
||||
it != t3->finite_facets_end(); ++it) {
|
||||
compute_face(it, graphic_buffer, t3, m_color_functor);
|
||||
it != t3->finite_facets_end(); ++it)
|
||||
{
|
||||
// TODO TEST draw_face
|
||||
compute_face(it, drawing_functor, graphic_buffer, t3);
|
||||
}
|
||||
}
|
||||
|
||||
for (typename T3::Finite_edges_iterator it = t3->finite_edges_begin();
|
||||
it != t3->finite_edges_end(); ++it) {
|
||||
it != t3->finite_edges_end(); ++it)
|
||||
{ // TODO TEST draw_edge + edge color
|
||||
compute_edge<float, T3>(it, graphic_buffer);
|
||||
}
|
||||
|
||||
for (typename T3::Finite_vertices_iterator it = t3->finite_vertices_begin();
|
||||
it != t3->finite_vertices_end(); ++it) {
|
||||
it != t3->finite_vertices_end(); ++it)
|
||||
{ // TODO TEST draw_vertex + vertex color
|
||||
compute_vertex<float, T3>(it, graphic_buffer);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace draw_function_for_t3
|
||||
|
||||
template <typename BufferType = float, class T3, class ColorFunctor>
|
||||
void add_in_graphic_buffer_t3(GraphicBuffer<BufferType> &graphic_buffer,
|
||||
const ColorFunctor &m_color_functor,
|
||||
const T3 *at3 = nullptr, bool m_nofaces = false) {
|
||||
if (at3 != nullptr) {
|
||||
draw_function_for_t3::compute_elements(graphic_buffer, at3, m_color_functor,
|
||||
m_nofaces);
|
||||
template <typename BufferType = float, class T3, class DrawingFunctor>
|
||||
void add_in_graphic_buffer_t3(CGAL::GraphicBuffer<BufferType> &graphic_buffer,
|
||||
const DrawingFunctor &drawing_functor,
|
||||
const T3 *at3 = nullptr)
|
||||
{
|
||||
if (at3 != nullptr)
|
||||
{
|
||||
draw_function_for_t3::compute_elements(graphic_buffer, at3, drawing_functor);
|
||||
}
|
||||
}
|
||||
|
||||
// Specialization of draw function.
|
||||
#define CGAL_T3_TYPE CGAL::Triangulation_3<Gt, Tds, Lock_data_structure>
|
||||
|
||||
template <class Gt, class Tds, class Lock_data_structure,
|
||||
class ColorFunctor =
|
||||
GenericFunctor<CGAL_T3_TYPE, typename CGAL_T3_TYPE::Vertex_handle,
|
||||
typename CGAL_T3_TYPE::Finite_edges_iterator,
|
||||
typename CGAL_T3_TYPE::Finite_facets_iterator>>
|
||||
void draw(const CGAL_T3_TYPE &at3, const char *title = "T3 Basic Viewer",
|
||||
const ColorFunctor &color_functor = ColorFunctor(),
|
||||
bool nofill = false) {
|
||||
|
||||
GraphicBuffer<float> buffer;
|
||||
// add_in_graphic_buffer_t3(buffer, color_functor, &at3, false);
|
||||
add_in_graphic_buffer_t3(buffer, DefaultColorFunctorT3(), &at3, false);
|
||||
|
||||
template<class Gt, class Tds, class Lock_data_structure, class DrawingFunctor>
|
||||
void draw(const CGAL_T3_TYPE &at3, const DrawingFunctor &drawingfunctor,
|
||||
const char *title = "T3 Basic Viewer")
|
||||
{
|
||||
CGAL::GraphicBuffer<float> buffer;
|
||||
add_in_graphic_buffer_t3(buffer, drawingfunctor, &at3);
|
||||
draw_buffer(buffer);
|
||||
}
|
||||
|
||||
template <class Gt, class Tds, class Lock_data_structure>
|
||||
void draw(const CGAL_T3_TYPE &at3, const char *title = "T3 Basic Viewer")
|
||||
{
|
||||
CGAL::GraphicBuffer<float> buffer;
|
||||
CGAL::GenericFunctor<CGAL_T3_TYPE,
|
||||
typename CGAL_T3_TYPE::Vertex_handle,
|
||||
typename CGAL_T3_TYPE::Finite_edges_iterator,
|
||||
typename CGAL_T3_TYPE::Finite_facets_iterator>
|
||||
drawingfunctor;
|
||||
|
||||
drawingfunctor.face_color =
|
||||
[](const CGAL_T3_TYPE &at3, const typename CGAL_T3_TYPE::Finite_facets_iterator fh)
|
||||
-> CGAL::IO::Color
|
||||
{
|
||||
if (fh==at3.finite_facets_end()) // use to get the mono color
|
||||
return CGAL::IO::Color(100, 125, 200); // R G B between 0-255
|
||||
|
||||
CGAL::Random random((unsigned int)((std::size_t)(&*(fh->first)) +
|
||||
(std::size_t)(fh->second)));
|
||||
|
||||
return get_random_color(random);
|
||||
};
|
||||
|
||||
draw(at3, drawingfunctor, title);
|
||||
}
|
||||
|
||||
#undef CGAL_T3_TYPE
|
||||
|
||||
} // End namespace CGAL
|
||||
|
|
|
|||
Loading…
Reference in New Issue