Created
June 8, 2018 14:05
-
-
Save afabri/4ac12bdc89fead1f009fe878c3b2e0f0 to your computer and use it in GitHub Desktop.
Copying or reinterpret_cast
This file contains hidden or 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
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h> | |
#include <Eigen/Dense> | |
#include <vector> | |
#include <algorithm> | |
typedef CGAL::Exact_predicates_inexact_constructions_kernel K; | |
typedef K::Point_3 Point_3; | |
int main() | |
{ | |
const Eigen::MatrixXd cubeV= (Eigen::MatrixXd(8,3)<< | |
0.0,0.0,0.0, | |
0.0,0.0,1.0, | |
0.0,1.0,0.0, | |
0.0,1.0,1.0, | |
1.0,0.0,0.0, | |
1.0,0.0,1.0, | |
1.0,1.0,0.0, | |
1.0,1.0,1.0).finished(); | |
std::vector<Point_3> points(8); | |
for(int i = 0; i < 8; i++){ | |
points[i] = Point_3(cubeV(i,0), cubeV(i,1), cubeV(i,2)); | |
std::cout << points[i]<< std::endl; | |
} | |
return 0; | |
{ | |
const Eigen::Matrix<double,8,3,Eigen::RowMajor> cubeV= (Eigen::Matrix<double,8,3,Eigen::RowMajor>(8,3)<< | |
2.0,0.0,0.0, | |
4.0,0.0,1.0, | |
8.0,1.0,0.0, | |
5.0,1.0,1.0, | |
6.0,0.0,0.0, | |
3.0,0.0,1.0, | |
0.0,1.0,0.0, | |
1.0,1.0,1.0).finished(); | |
Point_3* points = reinterpret_cast<Point_3*>(const_cast<double*>(cubeV.data())); | |
for(int i = 0; i < 8; i++){ | |
std::cout << points[i] << std::endl; | |
} | |
std::sort(points,points+8, K::Less_xyz_3()); | |
std::cout << cubeV << std::endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment