Skip to content

Instantly share code, notes, and snippets.

@twxia
Created December 2, 2013 15:43
Show Gist options
  • Select an option

  • Save twxia/7751377 to your computer and use it in GitHub Desktop.

Select an option

Save twxia/7751377 to your computer and use it in GitHub Desktop.
#include "stdafx.h"
#include "GUA_OM.h"
#include <math.h>
#include <opencv2/core/core.hpp>
#include <opencv/cv.h>
#include <highgui.h>
using namespace cv;
namespace OMT
{
/*======================================================================*/
Model::Model()
{
request_vertex_status();
request_edge_status();
request_face_status();
}
Model::~Model()
{
release_vertex_status();
release_edge_status();
release_face_status();
}
void Model::RenderSpecifiedPoint()
{
glPushAttrib(GL_LIGHTING_BIT);
glDisable(GL_LIGHTING);
glEnable(GL_DEPTH_TEST);
glPointSize(10.0f);
glBegin(GL_POINTS);
vector<sp_p>::iterator p_itr = sp_p_list.begin();
for (p_itr; p_itr != sp_p_list.end(); ++p_itr)
{
glColor3f(p_itr->r, p_itr->g, p_itr->b);
glVertex3dv(p_itr->pt.data());
}
glEnd();
glEnable(GL_LIGHTING);
glDisable(GL_POLYGON_OFFSET_FILL);
}
void Model::RenderSpecifiedFace()
{
glPushAttrib(GL_LIGHTING_BIT);
glDisable(GL_LIGHTING);
glEnable(GL_COLOR_MATERIAL);
glBegin(GL_TRIANGLES);
FVIter fv_itr;
vector< sp_f >::iterator f_itr;
VHandle vh[2];
std::vector<VHandle> vs;
int i =0;
for (f_itr = sp_f_list.begin(); f_itr != sp_f_list.end(); ++f_itr)
{
glColor4f(f_itr->r, f_itr->g, f_itr->b,1.0 );
int check = 0;
for (fv_itr=fv_iter(f_itr->fh); fv_itr; ++fv_itr)
{
glNormal3dv(normal(fv_itr.handle()).data());
glVertex3dv(point(fv_itr.handle()).data());
}
}
glEnd();
}
void Model::clear_sp_p()
{
sp_p_list.clear();
}
void Model::clear_sp_f()
{
sp_f_list.clear();
}
void Model::add_sp_p(Point _p, float _r, float _g, float _b)
{
sp_p input_data;
input_data.pt = _p;
input_data.r = _r;
input_data.g = _g;
input_data.b = _b;
if(!check_sp_p(_p))
sp_p_list.push_back(input_data);
}
void Model::add_sp_v(VHandle _v, float _r, float _g, float _b)
{
sp_v input_data;
input_data.vh = _v;
input_data.r = _r;
input_data.g = _g;
input_data.b = _b;
if(!check_sp_v(_v))
sp_v_list.push_back(input_data);
}
void Model::add_sp_f(FHandle _f, float _r, float _g, float _b)
{
sp_f input_data;
input_data.fh = _f;
input_data.r = _r;
input_data.g = _g;
input_data.b = _b;
if(!check_sp_f(_f))
sp_f_list.push_back(input_data);
}
/* void Model::add_b_p(Point _p, float _r, float _g, float _b)
{
sp_p input_data;
input_data.pt = _p;
input_data.r = _r;
input_data.g = _g;
input_data.b = _b;
}*/
bool Model::check_sp_v(VHandle v){
vector<sp_v>::iterator v_itr = sp_v_list.begin();
double *checkp = point(v).data();
for (v_itr; v_itr != sp_v_list.end(); ++v_itr)
{
double *p= point(v_itr->vh).data();
if(p[0] == checkp[0] && p[1] == checkp[1] && p[2] == checkp[2])
return true;
}
return false;
}
bool Model::check_sp_p(Point p){
vector<sp_p>::iterator p_itr = sp_p_list.begin();
for (p_itr; p_itr != sp_p_list.end(); ++p_itr)
{
double *checkp= &p_itr->pt[0];
if(p[0] == checkp[0] && p[1] == checkp[1] && p[2] == checkp[2])
return true;
}
return false;
}
VHandle Model::findVH(Point p){
vector<sp_v>::iterator v_itr = sp_v_list.begin();
for (v_itr; v_itr != sp_v_list.end(); ++v_itr)
{
double *checkp= point(v_itr->vh).data();
if(p[0] == checkp[0] && p[1] == checkp[1] && p[2] == checkp[2])
return v_itr->vh;
}
}
bool Model::check_sp_f(FHandle f){
double *checkp[3];
int count =0, check=0;
FVIter fv_itr;
vector< sp_f >::iterator f_itr;
for (fv_itr=fv_iter(f); fv_itr; ++fv_itr)
{
checkp[count] = point(fv_itr.handle()).data();
count++;
}
for (f_itr = sp_f_list.begin(); f_itr != sp_f_list.end(); ++f_itr)
{
count=0;
check=0;
for (fv_itr=fv_iter(f_itr->fh); fv_itr; ++fv_itr)
{
double *temp = point(fv_itr.handle()).data();
if(checkp[count][0] == temp[0] && checkp[count][1] == temp[1] && checkp[count][2] == temp[2]){
check++;
}
count++;
}
if(check == 3) return true;
}
return false;
}
FHandle Model::addFace(VHandle _v0, VHandle _v1, VHandle _v2){
std::vector<VHandle> face_vhandles;
face_vhandles.clear();
face_vhandles.push_back(_v0);
face_vhandles.push_back(_v1);
face_vhandles.push_back(_v2);
return OMT::MyMesh::add_face(face_vhandles);;
}
}
void Tri_Mesh::Render_Solid()
{
FIter f_it;
FVIter fv_it;
glEnable(GL_POLYGON_OFFSET_FILL);
glEnable(GL_LIGHTING);
glPolygonOffset(2.0, 2.0);
glBegin(GL_TRIANGLES);
glColor4f(0.81, 0.74, 0.33, 0.3);
for (f_it = faces_begin(); f_it != faces_end(); ++f_it)
{
for (fv_it = fv_iter( f_it ); fv_it; ++fv_it)
{
glNormal3dv(normal(fv_it.handle()).data());
glVertex3dv(point(fv_it.handle()).data());
}
}
glEnd();
glDisable(GL_POLYGON_OFFSET_FILL);
}
void Tri_Mesh::Render_SolidWireframe()
{
FIter f_it;
FVIter fv_it;
glDisable(GL_LIGHTING);
glPushAttrib(GL_LIGHTING_BIT);
glEnable(GL_POLYGON_OFFSET_FILL);
glEnable(GL_DEPTH_TEST);
glPolygonOffset(2.0, 2.0);
glBegin(GL_TRIANGLES);
glColor4f(1.0, 0.96, 0.49, 0.0);
for (f_it = faces_begin(); f_it != faces_end(); ++f_it)
{
for (fv_it = fv_iter( f_it ); fv_it; ++fv_it)
{
glVertex3dv(point(fv_it.handle()).data());
}
}
glEnd();
//glDisable(GL_POLYGON_OFFSET_FILL);
glPushAttrib(GL_LIGHTING_BIT);
glDisable(GL_LIGHTING);
glLineWidth(1.0);
glColor3f(0.0, 0.0, 0.0);
glBegin(GL_LINES);
for(OMT::EIter e_it = edges_begin(); e_it != edges_end(); ++e_it)
{
OMT::HEHandle _hedge = halfedge_handle(e_it.handle(),1);
OMT::Point curVertex = point(from_vertex_handle(_hedge));
glVertex3dv(curVertex.data());
curVertex = point(to_vertex_handle(_hedge));
glVertex3dv(curVertex.data());
}
glEnd();
glPopAttrib();
}
void Tri_Mesh::Render_Wireframe()
{
//glPushAttrib(GL_LIGHTING_BIT);
glDisable(GL_LIGHTING);
glLineWidth(1);
glColor3f(0.0, 0.0, 0.0);
glBegin(GL_LINES);
for(OMT::EIter e_it = edges_begin(); e_it != edges_end(); ++e_it)
{
OMT::HEHandle _hedge = halfedge_handle(e_it.handle(),1);
OMT::Point curVertex = point(from_vertex_handle(_hedge));
glVertex3dv(curVertex.data());
curVertex = point(to_vertex_handle(_hedge));
glVertex3dv(curVertex.data());
}
glEnd();
}
double Tri_Mesh::getArea(double *p0,double *p1,double *p2){ // I ' m Heron's formula
double line1=sqrt( pow((p0[0] - p1[0]), 2) + pow((p0[1] - p1[1]), 2) + pow((p0[2] - p1[2]), 2) );
double line2=sqrt( pow((p1[0] - p2[0]), 2) + pow((p1[1] - p2[1]), 2) + pow((p1[2] - p2[2]), 2) );
double line3=sqrt( pow((p2[0] - p0[0]), 2) + pow((p2[1] - p0[1]), 2) + pow((p2[2] - p0[2]), 2) );
double p = (line1 + line2 + line3) / 2;
return sqrt(p * (p-line1) * (p-line2) * (p-line3));
}
void Tri_Mesh::FindNeighborFace(GLdouble posx, GLdouble posy, GLdouble posz){
FIter f_it;
FVIter fv_it;
typedef struct p2fdistance{
FHandle fv;
VHandle v[3];
double areaGap;
}p2fdistance;
std::vector<p2fdistance> face;
for (f_it = faces_begin(); f_it != faces_end(); ++f_it)
{
p2fdistance temp;
temp.fv = f_it.handle();
int count = 0;
double *p[3];
for (fv_it = fv_iter( f_it ); fv_it; ++fv_it){
temp.v[count] = fv_it.handle();
p[count] = point(temp.v[count]).data();
count++;
}
double mousep[3] = {posx, posy, posz};
double area = getArea(p[0], p[1], p[2]);
double areaPart1 = getArea(mousep, p[1], p[2]);
double areaPart2 = getArea(mousep, p[0], p[2]);
double areaPart3 = getArea(mousep, p[0], p[1]);
temp.areaGap = fabs(area - (areaPart1 + areaPart2 + areaPart3));
face.push_back(temp);
}
p2fdistance smallest;
smallest = face[0];
for(int i=0; i<face.size() - 1; i++){
if(face[i].areaGap < smallest.areaGap){
smallest = face[i];
}
}
for(int i=0; i<3; i++){
VHandle v = smallest.v[i];
add_sp_v(v, 0.0f, 0.0f, 1.0f);
//add_sp_p(point(v), 0.0f, 0.0f, 1.0f);
}
add_sp_f(smallest.fv, 1.0f, 0.0f, 0.0f);
for(int i=0; i<3; i++){
double *p = point(smallest.v[i]).data();
std::cout << "The Closest face's x["<<i<<"]:" << p[0] << " y["<<i<<"]:" << p[1] << " z["<<i<<"]:" << p[2] <<std::endl;
}
}
void Tri_Mesh::FindEdgeDiagonalPoint(VHandle _v1, VHandle _v2, double **p){
FIter f_it;
FEIter fe_it;
FVIter fv_it;
VHandle DiagonalVertex[2];
int i = 0;
for (f_it = faces_begin(); f_it != faces_end(); ++f_it)
{
int check=0;
for(fv_it = fv_iter(f_it); fv_it; ++fv_it){
if(fv_it.handle() == _v1 || fv_it.handle() == _v2){
check++;
}else{
DiagonalVertex[i] = fv_it.handle();
}
}
if(check == 2) i++;
}
p[0] = point(DiagonalVertex[0]).data();
p[1] = point(DiagonalVertex[1]).data();
}
void getDinganlAngle(double* da0, double* da1, double* p0, double* p1, double* angle){
// /\
// --- b is middle line
// \/
double a = sqrt( pow((p0[0] - da0[0]), 2) + pow((p0[1] - da0[1]), 2) + pow((p0[2] - da0[2]), 2) );
double b = sqrt( pow((da0[0] - da1[0]), 2) + pow((da0[1] - da1[1]), 2) + pow((da0[2] - da1[2]), 2) );
double c = sqrt( pow((da1[0] - p0[0]), 2) + pow((da1[1] - p0[1]), 2) + pow((da1[2] - p0[2]), 2) );
angle[0] = acos((pow(a,2) + pow(c,2) - pow(b,2)) / (2 * a * c));
a = sqrt( pow((p1[0] - da0[0]), 2) + pow((p1[1] - da0[1]), 2) + pow((p1[2] - da0[2]), 2) );
c = sqrt( pow((da1[0] - p1[0]), 2) + pow((da1[1] - p1[1]), 2) + pow((da1[2] - p1[2]), 2) );
angle[1] = acos((pow(a,2) + pow(c,2) - pow(b,2)) / (2 * a * c));
}
std::vector<OMT::VHandle> Tri_Mesh::FindPointRing(VHandle _v){
int i = 0;
std::vector<VHandle> vs;
for (VVIter vv_it = vv_iter( _v ); vv_it; ++vv_it)
{
double *p = point(vv_it.handle()).data();
vs.push_back(vv_it.handle());
}
return vs;
}
double TwoPointDistance(double* p1, double* p2){
double distance = sqrt( pow((p1[0] - p2[0]), 2) + pow((p1[1] - p2[1]), 2) + pow((p1[2] - p2[2]), 2) );
return distance;
}
void Tri_Mesh::FindNeighborPoint(GLdouble posx, GLdouble posy, GLdouble posz){
typedef struct p2pdistance{
VHandle v;
double *p;
double distance;
}p2pdistance;
std::vector<p2pdistance> distance;
for (OMT::VIter v_it = vertices_begin() ; v_it != vertices_end() ; ++v_it)
{
p2pdistance temp;
GLdouble *p = point(v_it).data();
GLdouble p2[3] = {posx,posy,posz};
temp.distance = TwoPointDistance(p, p2);
temp.p = p;
temp.v = v_it.handle();
distance.push_back(temp);
}
p2pdistance smallest;
smallest.distance = distance[0].distance;
smallest.p = distance[0].p;
for(int i=1; i<distance.size() - 1; i++){
if(distance[i].distance < smallest.distance){
smallest = distance[i];
}
}
//FindPointRing(smallest.v);
add_sp_p( Point(smallest.p[0], smallest.p[1], smallest.p[2]), 1.0f, 0.0f, 0.0f);
std::cout << "The Closest vertex x:" << smallest.p[0] << " y:" << smallest.p[1] << " z:" << smallest.p[2] <<std::endl;
}
void Tri_Mesh::Render_Point()
{
glPointSize ( 8.0 ) ;
glColor3f( 0.0, 1.0, 0.0 );
glBegin(GL_POINTS);
for (OMT::VIter v_it = vertices_begin() ; v_it != vertices_end() ; ++v_it)
{
glVertex3dv(point(v_it).data());
}
glEnd();
}
bool Tri_Mesh::LoadSelectArea(Tri_Mesh *_mesh){
std::vector<OMT::sp_v> list_v = OMT::Model::sp_v_list;
std::vector<OMT::sp_v>::iterator v_itr = list_v.begin();
printf("list_v Size:%d", list_v.size());
//if(list.size() == 0) return false;
for (v_itr; v_itr != list_v.end(); ++v_itr)
{
if(!_mesh->check_sp_p(point(v_itr->vh))){
VHandle vh = _mesh->add_vertex(point(v_itr->vh));
_mesh->add_sp_p(point(v_itr->vh), v_itr->r, v_itr->g, v_itr->b);
_mesh->add_sp_v(vh, v_itr->r, v_itr->g, v_itr->b);
}
}
OMT::FVIter fv_itr;
std::vector<OMT::sp_f> list_f = OMT::Model::sp_f_list;
std::vector<OMT::sp_f>::iterator f_itr = list_f.begin();
//if(list.size() == 0) return false;
for (f_itr; f_itr != list_f.end(); ++f_itr)
{
std::vector<OMT::VHandle> face_vhandles;
face_vhandles.clear();
for (fv_itr=fv_iter(f_itr->fh); fv_itr; ++fv_itr)
{
VHandle v = _mesh->findVH(point(fv_itr.handle()));
face_vhandles.push_back(v);
}
_mesh->add_face(face_vhandles);
}
return true;
}
bool ReadFile(std::string _fileName,Tri_Mesh *_mesh)
{
bool isRead = false;
OpenMesh::IO::Options opt;
if ( OpenMesh::IO::read_mesh(*_mesh, _fileName, opt) )
{
//read mesh from filename OK!
isRead = true;
}
if(isRead)
{
// If the file did not provide vertex normals and mesh has vertex normal ,then calculate them
if (!opt.check( OpenMesh::IO::Options::VertexNormal ) && _mesh->has_vertex_normals())
{
_mesh->update_normals();
}
}
return isRead;
}
void Tri_Mesh::map_transform(){
FIter f_it;
FVIter fv_it;
glDisable(GL_LIGHTING);
glPushAttrib(GL_LIGHTING_BIT);
glEnable(GL_POLYGON_OFFSET_FILL);
glEnable(GL_DEPTH_TEST);
glBegin(GL_QUADS);
glColor4f(0.0, 0, 0.0,0.5);
glVertex3f(-0.5f,0.5f,0);
glVertex3f(-0.5f,-0.5f,0);
glVertex3f(0.5f,-0.5f,0);
glVertex3f(0.5f,0.5f,0);
glEnd();
int k = 0;
std::vector<double *> boundary;
GLdouble color[7][3] = {{1.0,0.0,0.0},{1.0,0.5,0.0},{1.0,1.0,0.0},{0.0,1.0,0.0},{0.0,0.5,1.0},{0.0,0.0,1.0},{0.5,0.0,1.0}};
boundary_v_list.clear();
for(EIter e_it = edges_begin(); e_it != edges_end(); ++e_it)
{
OMT::HEHandle _hedge = halfedge_handle(e_it.handle(),1);
VHandle toV = to_vertex_handle(_hedge);
VHandle fromV = from_vertex_handle(_hedge);
OMT::sp_v data;
if(is_boundary(_hedge) && is_boundary(fromV)){
int index = findBoundaryPoint(point(fromV).data());
if(index == -1){
data.vh = toV;
boundary_v_list.push_back(data);
}else{
data.vh = toV;
boundary_v_list.insert(boundary_v_list.begin()+index,data);
}
}
}
glPolygonOffset(2.0, 2.0);
glPointSize ( 8.0 ) ;
glBegin(GL_POINTS);
for(int i=0; i< boundary_v_list.size(); i++){
boundary_v_list[i].r = color[k][0];
boundary_v_list[i].g = color[k][1];
boundary_v_list[i].b = color[k][2];
glColor4f(boundary_v_list[i].r, boundary_v_list[i].g, boundary_v_list[i].b, 1);
double *p = point(boundary_v_list[i].vh).data();
glVertex3dv(p);
std::cout << "x:" << p[0] << " y:" << p[1] << " z:" << p[2] << " k:" << k <<std::endl;
std::cout << "R:" << boundary_v_list[i].r << " G:" << boundary_v_list[i].g << " B:" << boundary_v_list[i].b <<std::endl;
if(k == 6) k=0;
else k++;
}
glEnd();
std::vector<double> length;
double totalLength = 0;
for(int i=0; i< boundary_v_list.size();i++){
int nextPointIndex = i + 1;
if(i == (boundary_v_list.size() - 1)){
nextPointIndex = 0;
}
double *p1 =point(boundary_v_list[i].vh).data();
double *p2 =point(boundary_v_list[nextPointIndex].vh).data();
double len = TwoPointDistance(p1, p2);
length.push_back(len);
totalLength += len;
}
double rate = 4 / totalLength;
double x=0.5,y=0.5,z=0;
int i = 0;
std::vector<VHandle> insideP;
for (VIter v_it = vertices_begin() ; v_it != vertices_end() ; ++v_it)
{
double *p = point(v_it).data();
int index = findBoundaryPoint(p);
OMT::sp_p data;
data.r = 0.2;
data.g = 0.2;
data.b = 0.7;
data.pt = Point(0,0,0);
if(index == -1){
property(VProp, v_it.handle()) = data;
insideP.push_back(v_it.handle());
}
}
for(int i=0; i<boundary_v_list.size(); i++){
OMT::sp_p data;
if(i!=0)
quadBoundary(&x,&y, length[i]* rate);
data.r = boundary_v_list[i].r;
data.g = boundary_v_list[i].g;
data.b = boundary_v_list[i].b;
data.pt = Point(x,y,z);
property(VProp, boundary_v_list[i].vh) = data;
}
processInsidePoint(insideP);
glPolygonOffset(2.0, 2.0);
glPointSize ( 8.0 ) ;
glBegin(GL_POINTS);
for (VIter v_it = vertices_begin() ; v_it != vertices_end() ; ++v_it)
{
OMT::sp_p data = property(VProp, v_it.handle());
glColor4f(data.r, data.g, data.b, 1);
glVertex3dv(data.pt.data());
}
glEnd();
glLineWidth(1);
glColor3f(0.7, 0.7, 0.7);
glBegin(GL_LINES);
for(OMT::EIter e_it = edges_begin(); e_it != edges_end(); ++e_it)
{
OMT::HEHandle _hedge = halfedge_handle(e_it.handle(),1);
OMT::sp_p data = property(VProp, from_vertex_handle(_hedge));
glVertex3dv(data.pt.data());
data =property(VProp, to_vertex_handle(_hedge));
glVertex3dv(data.pt.data());
}
glEnd();
}
void Tri_Mesh::processInsidePoint(std::vector<OMT::VHandle> v){
if(v.size()==0) return;
CvMat* ma = cvCreateMat(v.size(),v.size(),CV_32FC1);
CvMat* mbx = cvCreateMat(v.size(),1,CV_32FC1);
CvMat* mby = cvCreateMat(v.size(),1,CV_32FC1);
CvMat* mcx = cvCreateMat(v.size(),1,CV_32FC1);
CvMat* mcy = cvCreateMat(v.size(),1,CV_32FC1);
CvMat *InverseMatrix=cvCreateMat(v.size(),v.size(),CV_32FC1);
std::vector<OMT::VHandle> temp;
double num[2];
int index=0;
for(int i=0; i<v.size(); i++){
for(int j=0; j<v.size(); j++){
if(index == j){
temp = FindPointRing(v[i]);
cvmSet(ma,i,j, temp.size());
}else{
cvmSet(ma,i,j, -1);
}
}
index++;
}
cvInvert(ma,InverseMatrix,CV_LU);
index = 0;
for(int i=0; i<v.size(); i++){
temp = FindPointRing(v[i]);
num[0] = 0;
num[1] = 0;
for(int j=0; j<temp.size(); j++){
for(int k=0; k< boundary_v_list.size(); k++){
if(boundary_v_list[k].vh == temp[j]){
OMT::sp_p data = property(VProp, boundary_v_list[k].vh);
double *p = data.pt.data();
double **diagonalPoint;
double *angle;
FindEdgeDiagonalPoint(v[i], temp[j], diagonalPoint);
getDinganlAngle(point(v[i]).data(),point(temp[j]).data(),diagonalPoint[0], diagonalPoint[1], angle);
double *radians;
radians[0] = angle[0] * 180.0 / 3.141592653589793238462;
radians[1] = angle[0] * 180.0 / 3.141592653589793238462;
num[0] += p[0] * ((1 / tan(radians[0])) + (1 / tan(radians[1])));
num[1] += p[1] * ((1 / tan(radians[0])) + (1 / tan(radians[1])));
}
}
}
cvmSet(mbx, i, 0, num[0]);
cvmSet(mby, i, 0, num[1]);
}
//printMatrix(ma,v.size(),v.size());
//printMatrix(InverseMatrix,v.size(),v.size());
//printf("bx: \n");
//printMatrix(mbx,v.size(),1);
//printf("by: \n");
//printMatrix(mby,v.size(),1);
cvmMul(InverseMatrix, mbx, mcx);
//printMatrix(mcx,1,1);
cvmMul(InverseMatrix, mby, mcy);
//printMatrix(mcy,1,1);
for(int i=0; i<v.size(); i++){
OMT::sp_p data,temp = property(VProp, v[i]);
data = temp;
double x = cvGet2D(InverseMatrix,i,0).val[0];
double y = cvGet2D(InverseMatrix,i,0).val[0];
data.pt = Point(cvGet2D(mcx,i,0).val[0], cvGet2D(mcy,i,0).val[0], 0);
if(cvGet2D(mcx,i,0).val[0] == 0 && cvGet2D(mcy,i,0).val[0] == 0){
std::cout << "The VHandle was inside point's inside point x:" << cvGet2D(mcx,i,0).val[0] << " y:" << cvGet2D(mcy,i,0).val[0] << " !!"<<std::endl;
}
property(VProp, v[i]) = data;
}
/*
matrix test
float Array[]={2,3,1,4,1,4,3,4,6};
CvMat *InverseMatrix=cvCreateMat(3,3,CV_32FC1);
CvMat *Matrix1=cvCreateMat(3,3,CV_32FC1);
cvSetData(Matrix1,Array,Matrix1->step);
printf("\nThe Invert Matrix is:\n");
cvInvert(Matrix1,InverseMatrix,CV_LU);
for(int i=0;i<InverseMatrix->rows;i++)
{
for(int j=0;j<InverseMatrix->cols;j++)
{
printf("%.1f ",cvGet2D(InverseMatrix,i,j).val[0]);
}
printf("\n");
}*/
}
void printMatrix(CvMat* mat, int row , int col ){
int i ;
int j ;
for ( i = 0 ; i < row ; i++ )
{
float* ptr = (float*)( mat->data.ptr + i * mat->step ) ;
for ( j = 0 ; j < col ; j++ )
{
printf("\t%f",ptr[j]);
}
printf("\n");
}
printf("\n\n");
}
void quadBoundary(double *x,double *y,double length){
if(*x == -0.5 && *y >= -0.5){ //left
*y -= length;
if(*y < -0.5){
double temp = -0.5 - *y;
*x += temp;
*y = -0.5;
}
}else if(*y ==-0.5 && *x >= -0.5 ){ //down
*x += length;
if(*x > 0.5){
double temp = *x - 0.5;
*x = 0.5;
*y += temp;
}
}else if(*x == 0.5 && *y >= -0.5){ //right
*y += length;
if(*y > 0.5){
double temp = *y - 0.5;
*x -= temp;
*y = 0.5;
}
}else if(*y == 0.5 && *x >= -0.5){ //up
*x -= length;
if(*x < -0.5){
double temp = -0.5 - *x;
*x = -0.5;
*y -= temp;
}
}
}
void Tri_Mesh::selectBoundaryTransfom(Tri_Mesh *_mesh){
std::vector<OMT::sp_v>::iterator v_itr = boundary_v_list.begin();
printf("selectBoundaryTransfom! ");
for (v_itr; v_itr != boundary_v_list.end(); ++v_itr)
{
std::vector<OMT::sp_p>::iterator mp_itr = _mesh->sp_p_list.begin();
double *p= point(v_itr->vh).data();
for (mp_itr; mp_itr != _mesh->sp_p_list.end(); ++mp_itr)
{
double *checkp= mp_itr->pt.data();
if(p[0] == checkp[0] && p[1] == checkp[1] && p[2] == checkp[2]){
mp_itr->r = v_itr->r;
mp_itr->g = v_itr->g;
mp_itr->b = v_itr->b;
}
}
}
}
int Tri_Mesh::findBoundaryPoint(double *p){
for(int i=0;i<boundary_v_list.size();i++){
double *temp = point(boundary_v_list[i].vh).data();
if(temp[0] == p[0] && temp[1] == p[1] && temp[2] == p[2]){
return i;
}
}
return -1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment