-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added: test code for arc drawing (needs more work for generic version)
- Loading branch information
1 parent
947d46c
commit 5808019
Showing
5 changed files
with
318 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
|
||
#include "Geodesic_arcs.h" | ||
|
||
#include <qvector3d.h> | ||
|
||
#include <iostream> | ||
#include <iterator> | ||
#include <vector> | ||
using namespace std; | ||
|
||
|
||
#include <CGAL/Exact_predicates_exact_constructions_kernel.h> | ||
#include <CGAL/Arrangement_on_surface_2.h> | ||
#include <CGAL/Arr_geodesic_arc_on_sphere_traits_2.h> | ||
#include <CGAL/Arr_spherical_topology_traits_2.h> | ||
#include "arr_print.h" | ||
|
||
typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel; | ||
typedef CGAL::Arr_geodesic_arc_on_sphere_traits_2<Kernel> Geom_traits; | ||
typedef Geom_traits::Point_2 Point; | ||
typedef Geom_traits::Curve_2 Curve; | ||
typedef CGAL::Arr_spherical_topology_traits_2<Geom_traits> Topol_traits; | ||
typedef CGAL::Arrangement_on_surface_2<Geom_traits, Topol_traits> Arrangement; | ||
|
||
|
||
typedef Kernel::Direction_3 Dir3; | ||
ostream& operator << (ostream& os, const Dir3& d) | ||
{ | ||
os << d.dx() << ", " << d.dy() << ", " << d.dz(); | ||
return os; | ||
} | ||
|
||
typedef Geom_traits::Approximate_point_2 Approximate_point_2; | ||
ostream& operator << (ostream& os, const Approximate_point_2& d) | ||
{ | ||
os << d.dx() << ", " << d.dy() << ", " << d.dz(); | ||
return os; | ||
} | ||
|
||
#include <CGAL/Vector_3.h> | ||
typedef Geom_traits::Approximate_number_type Approximate_number_type; | ||
typedef Geom_traits::Approximate_kernel Approximate_kernel; | ||
typedef CGAL::Vector_3<Approximate_kernel> Approximate_Vector_3; | ||
typedef Approximate_kernel::Direction_3 Approximate_Direction_3; | ||
|
||
typedef Kernel::Direction_3 Direction_3; | ||
|
||
|
||
ostream& operator << (ostream& os, const Approximate_Vector_3& v) | ||
{ | ||
os << v.x() << ", " << v.y() << ", " << v.z(); | ||
//os << v.hx() << ", " << v.hy() << ", " << v.hz() << ", " << v.hw(); | ||
return os; | ||
} | ||
|
||
|
||
Geodesic_arcs::Geodesic_arcs() | ||
{ | ||
initializeOpenGLFunctions(); | ||
|
||
// Construct the arrangement from 12 geodesic arcs. | ||
Geom_traits traits; | ||
Arrangement arr(&traits); | ||
|
||
|
||
auto ctr_p = traits.construct_point_2_object(); | ||
auto ctr_cv = traits.construct_curve_2_object(); | ||
|
||
|
||
vector<Curve> xcvs; | ||
xcvs.push_back(ctr_cv(ctr_p(1, 0, 0), ctr_p(0, 1, 0))); | ||
xcvs.push_back(ctr_cv(ctr_p(1, 0, 0), ctr_p(0, 1, 0), Dir3(0, 0, -1))); | ||
|
||
auto approx = traits.approximate_2_object(); | ||
|
||
const double error = 0.001; | ||
std::vector<Approximate_point_2> v; | ||
|
||
const auto& xcv = xcvs[0]; | ||
//for (const auto& xcv : xcvs) | ||
{ | ||
auto oi2 = approx(xcv, error, std::back_insert_iterator(v)); | ||
|
||
for (auto it = v.begin(); it != v.end(); ++it) | ||
cout << *it << endl; | ||
cout << "num points output = " << v.size() << endl; | ||
} | ||
|
||
|
||
//const float c = 0.0; | ||
//std::vector<QVector3D> vertex_data { | ||
// QVector3D(0,0,0), QVector3D(1,0,0), | ||
// QVector3D(a,0,0), QVector3D(1,0,0), | ||
|
||
// QVector3D(0,0,0), QVector3D(0,1,0), | ||
// QVector3D(0,a,0), QVector3D(0,1,0), | ||
|
||
// QVector3D(0,0,0), QVector3D(c,c,1), | ||
// QVector3D(0,0,a), QVector3D(c,c,1) | ||
//}; | ||
|
||
std::vector<QVector3D> vertex_data; | ||
const QVector3D red(1, 0, 0); | ||
for (const auto& p : v) | ||
{ | ||
const QVector3D arc_point(p.dx(), p.dy(), p.dz()); | ||
vertex_data.push_back(arc_point); | ||
vertex_data.push_back(red); | ||
} | ||
m_num_arc_points = v.size(); // CAREFUL: not size of vertex_data!!! | ||
|
||
|
||
// DEFINE OPENGL BUFFERS | ||
glGenVertexArrays(1, &m_vao); | ||
glBindVertexArray(m_vao); | ||
|
||
|
||
// Vertex Buffer | ||
glGenBuffers(1, &m_vbo); | ||
glBindBuffer(GL_ARRAY_BUFFER, m_vbo); | ||
auto vertex_buffer_size = sizeof(QVector3D) * vertex_data.size(); | ||
auto vertex_buffer_data = reinterpret_cast<const void*>(vertex_data.data()); | ||
glBufferData(GL_ARRAY_BUFFER, | ||
vertex_buffer_size, | ||
vertex_buffer_data, | ||
GL_STATIC_DRAW); | ||
|
||
// Position Vertex-Attribute | ||
GLint position_attrib_index = 0; | ||
const void* position_offset = 0; | ||
GLsizei stride = 6 * sizeof(float); | ||
glVertexAttribPointer(position_attrib_index, | ||
3, | ||
GL_FLOAT, GL_FALSE, | ||
stride, | ||
position_offset); | ||
glEnableVertexAttribArray(position_attrib_index); | ||
|
||
// Color Vertex-Attribute | ||
GLint color_attrib_index = 1; | ||
auto* color_offset = reinterpret_cast<const void*>(3 * sizeof(float)); | ||
glVertexAttribPointer(color_attrib_index, | ||
3, | ||
GL_FLOAT, | ||
GL_FALSE, | ||
stride, | ||
color_offset); | ||
glEnableVertexAttribArray(color_attrib_index); | ||
|
||
glBindBuffer(GL_ARRAY_BUFFER, 0); | ||
glBindVertexArray(0); | ||
} | ||
|
||
void Geodesic_arcs::draw() | ||
{ | ||
glBindVertexArray(m_vao); | ||
{ | ||
glDrawArrays(GL_LINES, 0, m_num_arc_points); | ||
} | ||
glBindVertexArray(0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
|
||
#ifndef GEODESIC_ARCS_H | ||
#define GEODESIC_ARCS_H | ||
|
||
#include "Common_defs.h" | ||
|
||
|
||
class Geodesic_arcs : protected OpenGLFunctionsBase | ||
{ | ||
public: | ||
Geodesic_arcs(); | ||
|
||
void draw(); | ||
|
||
private: | ||
GLuint m_vao, m_vbo, m_num_arc_points; | ||
}; | ||
|
||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
#ifndef _PRINT_ARR_H_ | ||
#define _PRINT_ARR_H_ | ||
|
||
//----------------------------------------------------------------------------- | ||
// Print all neighboring vertices to a given arrangement vertex. | ||
// | ||
template<class Arrangement> | ||
void print_neighboring_vertices(typename Arrangement::Vertex_const_handle v) { | ||
if (v->is_isolated()) { | ||
std::cout << "The vertex (" << v->point() << ") is isolated\n"; | ||
return; | ||
} | ||
|
||
std::cout << "The neighbors of the vertex (" << v->point() << ") are:"; | ||
typename Arrangement::Halfedge_around_vertex_const_circulator first, curr; | ||
first = curr = v->incident_halfedges(); | ||
do std::cout << " (" << curr->source()->point() << ")"; | ||
while (++curr != first); | ||
std::cout << std::endl; | ||
} | ||
|
||
//----------------------------------------------------------------------------- | ||
// Print all vertices (points) and edges (curves) along a connected component | ||
// boundary. | ||
// | ||
template <typename Arrangement> | ||
void print_ccb(typename Arrangement::Ccb_halfedge_const_circulator circ) { | ||
std::cout << "(" << circ->source()->point() << ")"; | ||
typename Arrangement::Ccb_halfedge_const_circulator curr = circ; | ||
do { | ||
typename Arrangement::Halfedge_const_handle e = curr; | ||
std::cout << " [" << e->curve() << "] " | ||
<< "(" << e->target()->point() << ")"; | ||
} while (++curr != circ); | ||
std::cout << std::endl; | ||
} | ||
|
||
//----------------------------------------------------------------------------- | ||
// Print the boundary description of an arrangement face. | ||
// | ||
template <typename Arrangement> | ||
void print_face(typename Arrangement::Face_const_handle f) { | ||
// Print the outer boundary. | ||
if (f->is_unbounded()) std::cout << "Unbounded face.\n"; | ||
else { | ||
std::cout << "Outer boundary: "; | ||
print_ccb<Arrangement>(f->outer_ccb()); | ||
} | ||
|
||
// Print the boundary of each of the holes. | ||
size_t index = 1; | ||
for (auto hole = f->holes_begin(); hole != f->holes_end(); ++hole, ++index) { | ||
std::cout << " Hole #" << index << ": "; | ||
// The following statement pacifies msvc. | ||
typename Arrangement::Ccb_halfedge_const_circulator circ = *hole; | ||
print_ccb<Arrangement>(circ); | ||
} | ||
|
||
// Print the isolated vertices. | ||
index = 1; | ||
for (auto iv = f->isolated_vertices_begin(); | ||
iv != f->isolated_vertices_end(); ++iv, ++index) | ||
{ | ||
std::cout << " Isolated vertex #" << index << ": " | ||
<< "(" << iv->point() << ")" << std::endl; | ||
} | ||
} | ||
|
||
//----------------------------------------------------------------------------- | ||
// Print the given arrangement. | ||
// | ||
template <typename Arrangement> | ||
void print_arrangement(const Arrangement& arr) { | ||
CGAL_precondition(arr.is_valid()); | ||
|
||
// Print the arrangement vertices. | ||
std::cout << arr.number_of_vertices() << " vertices:\n"; | ||
for (auto vit = arr.vertices_begin(); vit != arr.vertices_end(); ++vit) { | ||
std::cout << "(" << vit->point() << ")"; | ||
if (vit->is_isolated()) std::cout << " - Isolated.\n"; | ||
else std::cout << " - degree " << vit->degree() << std::endl; | ||
} | ||
|
||
// Print the arrangement edges. | ||
std::cout << arr.number_of_edges() << " edges:\n"; | ||
for (auto eit = arr.edges_begin(); eit != arr.edges_end(); ++eit) | ||
std::cout << "[" << eit->curve() << "]\n"; | ||
|
||
// Print the arrangement faces. | ||
std::cout << arr.number_of_faces() << " faces:\n"; | ||
for (auto fit = arr.faces_begin(); fit != arr.faces_end(); ++fit) | ||
print_face<Arrangement>(fit); | ||
} | ||
|
||
//----------------------------------------------------------------------------- | ||
// Print the size of the given arrangement. | ||
// | ||
template <typename Arrangement> | ||
void print_arrangement_size(const Arrangement& arr) { | ||
std::cout << "The arrangement size:\n" | ||
<< " |V| = " << arr.number_of_vertices() | ||
<< ", |E| = " << arr.number_of_edges() | ||
<< ", |F| = " << arr.number_of_faces() << std::endl; | ||
} | ||
|
||
//----------------------------------------------------------------------------- | ||
// Print the size of the given unbounded arrangement. | ||
// | ||
template <typename Arrangement> | ||
void print_unbounded_arrangement_size(const Arrangement& arr) { | ||
std::cout << "The arrangement size:\n" | ||
<< " |V| = " << arr.number_of_vertices() | ||
<< " (plus " << arr.number_of_vertices_at_infinity() | ||
<< " at infinity)" | ||
<< ", |E| = " << arr.number_of_edges() | ||
<< ", |F| = " << arr.number_of_faces() | ||
<< " (" << arr.number_of_unbounded_faces() << " unbounded)\n\n"; | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters