/************************************************************************ Yutaka Ohtake CMeshEditorView.cpp Window Copyright (c) 1999-2001 The University of Aizu. All Rights Reserved. ************************************************************************/ #include "stdafx.h" #include "MeshEditor.h" #include "MeshEditorDoc.h" #include "MeshEditorView.h" #include "MeshData.h" #include #include #include #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CMeshEditorView IMPLEMENT_DYNCREATE(CMeshEditorView, CView) BEGIN_MESSAGE_MAP(CMeshEditorView, CView) //{{AFX_MSG_MAP(CMeshEditorView) ON_WM_SIZE() ON_WM_DESTROY() ON_WM_CREATE() ON_WM_RBUTTONUP() ON_WM_RBUTTONDOWN() ON_WM_LBUTTONDOWN() ON_WM_LBUTTONUP() ON_WM_KEYDOWN() ON_WM_MOUSEWHEEL() ON_WM_MOUSEMOVE() ON_WM_LBUTTONDBLCLK() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CMeshEditorView クラスの構築/消滅 CMeshEditorView::CMeshEditorView() { eye[0] = 26; eye[1] = -48; eye[2] = 40; center[0] = 0.0; center[1] = 0.0; center[2] = 0.0; //5.0; Rx = 0; Ry = 0; Rz = 0; //bunny //Ry = -462; //Rz = 209; //venus //Ry = -564; //Rz = -57; //Ry = -573; //Rz = 692; //2tori //Ry = -433; //Rz = 15; //Ry = -797; //Rz = 209; //Ry = -433; //Rz = 79; //teeth //Ry = -807; //Rz = 337; //dino //Ry = -572 - 180 - 40; //Rz = 129; //buuny2 //Ry = -515.000000; //Rz = 708.000000; vx[0] = 0; vx[1] = 0; vx[2] = 1; vy[0] = -(float)(eye[1]/sqrt(eye[0]*eye[0]+eye[1]*eye[1])); vy[1] = (float)(eye[0]/sqrt(eye[0]*eye[0]+eye[1]*eye[1])); vy[2] = 0; vz[0] = -vy[1]; vz[1] = vy[0]; vz[2] = 0; //bunny //view_angle = 25.0f; //venus //view_angle = 8.65; view_angle = 22.5; //2tori //view_angle = 21.3; //view_angle = 9.9; //dino //view_angle = 7.35; //view_angle = 16.85; isLPressed = FALSE; isRPressed = FALSE; shift_x = 0; shift_y = 0; shift_z = 0; vertex_count = 0; face_count = 0; color_type = 0; } CMeshEditorView::~CMeshEditorView() { //glDeleteLists(1,1); } BOOL CMeshEditorView::PreCreateWindow(CREATESTRUCT& cs) { cs.style |= WS_CLIPCHILDREN | WS_CLIPSIBLINGS/* | WS_MAXIMIZE*/; return CView::PreCreateWindow(cs); } ///////////////////////////////////////////////////////////////////////////// // CMeshEditorView クラスの描画 void CMeshEditorView::OnDraw(CDC* pDC) { CMeshEditorDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); wglMakeCurrent(pDC->m_hDC, m_hRC); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //TRACE("%f, %f\n", Ry, Rz); //TRACE("%f\n", view_angle); glPushMatrix(); //glCallList(2); glTranslatef(shift_x,shift_y,shift_z); glRotatef(Rx,vz[0],vz[1],vz[2]); glRotatef(Ry,vy[0],vy[1],vy[2]); glRotatef(Rz,vx[0],vx[1],vx[2]); //glCallList(1); pDoc->drawMesh(); //drawPickedPoint(); glPopMatrix(); glFlush(); SwapBuffers(wglGetCurrentDC()); wglMakeCurrent(pDC->m_hDC, NULL); pDC->SetBkColor(RGB(255,255,255)); pDC->SetTextColor(RGB(0,0,0)); int v = vertex_count; if(v == 0) return; CString str = ""; for(int i=v; i!= 0; i = i/10) str = (char)((int)'0'+i%10) + str; pDC->TextOut(8,8,"Vertex:" + str); v = face_count; str = ""; for(i=v; i!= 0; i = i/10) str = (char)((int)'0'+i%10) + str; pDC->TextOut(8,25,"Face :" + str); //TRACE("%f,%f\n", Ry, Rz); } ///////////////////////////////////////////////////////////////////////////// // CMeshEditorView クラスの診断 #ifdef _DEBUG void CMeshEditorView::AssertValid() const { CView::AssertValid(); } void CMeshEditorView::Dump(CDumpContext& dc) const { CView::Dump(dc); } CMeshEditorDoc* CMeshEditorView::GetDocument() // 非デバッグ バージョンはインラインです。 { ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMeshEditorDoc))); return (CMeshEditorDoc*)m_pDocument; } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CMeshEditorView クラスのメッセージ ハンドラ void CMeshEditorView::flatShade(MeshData *mesh) { //CClientDC clientDC(this); //wglMakeCurrent(clientDC.m_hDC, m_hRC); //glDeleteLists(1,1); //glNewList(1, GL_COMPILE); glShadeModel(GL_SMOOTH); int face_N = mesh->face_N; int (*face)[3] = mesh->face; float (*normal_f)[3] = mesh->normal_f; float (*vertex)[3] = mesh->vertex; for(int i=0; iselected_triangle != NULL){ glDisable(GL_LIGHTING); int f = mesh->selected_triangle->f; glBegin(GL_POINTS); glColor3f(1,0,0); glVertex3fv(vertex[face[f][0]]); glVertex3fv(vertex[face[f][1]]); glVertex3fv(vertex[face[f][2]]); glEnd(); glEnable(GL_LIGHTING); } //glEndList(); //wglMakeCurrent(clientDC.m_hDC, NULL); //CClientDC* dc = new CClientDC(this); //OnDraw(dc); //delete dc; } void CMeshEditorView::OnSize(UINT nType, int cx, int cy) { CView::OnSize(nType, cx, cy); // TODO: この位置にメッセージ ハンドラ用のコードを追加してください int i; GLdouble up[3]; GLdouble vector[3]; GLdouble norm; CClientDC clientDC(this); wglMakeCurrent(clientDC.m_hDC, m_hRC); glViewport(0, 0, cx, cy); glMatrixMode(GL_PROJECTION); glLoadIdentity(); //gluPerspective(3, (GLfloat)cx/(GLfloat)cy, 10.0, 4000.0); gluPerspective(view_angle, (GLfloat)cx/(GLfloat)cy, 10.0, 4000.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); for(i=0; i<3; i++) vector[i] = center[i] - eye[i]; up[0] = -vector[0] * vector[2]; up[1] = -vector[1] * vector[2]; up[2] = vector[0] * vector[0] + vector[1] * vector[1]; norm = up[0] * up[0] + up[1] * up[1] + up[2] * up[2]; norm = sqrt(norm); for(i=0; i<3; i++) up[i] = up[i] / norm; gluLookAt(eye[0], eye[1], eye[2], center[0], center[1], center[2], up[0], up[1], up[2]); wglMakeCurrent(clientDC.m_hDC, NULL); //TRACE("(%d, %d), %f\n", cx, cy, 2.0*MeshData::DIST(eye, center)*tan(0.5*view_angle*PI/180)); } void CMeshEditorView::OnDestroy() { CView::OnDestroy(); // TODO: この位置にメッセージ ハンドラ用のコードを追加してください wglDeleteContext(m_hRC); } int CMeshEditorView::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CView::OnCreate(lpCreateStruct) == -1) return -1; // TODO: この位置に固有の作成用コードを追加してください PIXELFORMATDESCRIPTOR pfd = { sizeof(PIXELFORMATDESCRIPTOR), 1, PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER, PFD_TYPE_RGBA, 16, 0,0,0,0,0,0, 0,0,0,0,0,0,0, 32, 0,0, PFD_MAIN_PLANE, 0, 0,0,0 }; CClientDC clientDC(this); int pixelFormat = ChoosePixelFormat(clientDC.m_hDC, &pfd); if(!SetPixelFormat(clientDC.m_hDC, pixelFormat, &pfd)) return -1; m_hRC = wglCreateContext(clientDC.m_hDC); //wglMakeCurrent(clientDC.m_hDC,m_hRC); initGL(); /*************************** glDeleteLists(2,1); glNewList(2, GL_COMPILE); glShadeModel(GL_SMOOTH); glDisable(GL_LIGHTING); glColor3f(0,0,0); glBegin(GL_LINES); glVertex3f(0,0,0); glVertex3f(20*vx[0],20*vx[1],20*vx[2]); glEnd(); glBegin(GL_LINES); glVertex3f(0,0,0); glVertex3f(20*vy[0],20*vy[1],20*vy[2]); glEnd(); glBegin(GL_LINES); glVertex3f(0,0,0); glVertex3f(20*vz[0],20*vz[1],20*vz[2]); glEnd(); glEndList(); glEnable(GL_LIGHTING); *******************************/ //wglMakeCurrent(clientDC.m_hDC,NULL); return 0; } void CMeshEditorView::initGL() { CClientDC clientDC(this); wglMakeCurrent(clientDC.m_hDC, m_hRC); GLfloat light_position1[4] = {-52, -16, -50, 0}; GLfloat light_position2[4] = {-26, -48, -50, 0}; GLfloat light_position3[4] = { 16, -52, -50, 0}; GLfloat direction1[3] = {52,16,50}; GLfloat direction2[3] = {26,48,50}; GLfloat direction3[3] = {-16,52,50}; GLfloat light_position4[4] = {52, 16, 50, 0}; GLfloat light_position5[4] = {26, 48, 50, 0}; GLfloat light_position6[4] = {-16, 52, 50, 0}; GLfloat direction4[3] = {-52,-16,-50}; GLfloat direction5[3] = {-26,-48,-50}; GLfloat direction6[3] = {16,-52,-50}; GLfloat color1[4], color2[4], color3[4], color4[4], color5[4], color6[4]; //color_type = 5; if(color_type == 0){ color1[0] = 1; color1[1] = 0; color1[2] = 0; color1[3] = 1; color2[0] = 0; color2[1] = 1; color2[2] = 0; color2[3] = 1; color3[0] = 0; color3[1] = 0; color3[2] = 1; color3[3] = 1; color4[0] = 1; color4[1] = 0; color4[2] = 0; color4[3] = 1; color5[0] = 0; color5[1] = 1; color5[2] = 0; color5[3] = 1; color6[0] = 0; color6[1] = 0; color6[2] = 1; color6[3] = 1; } else if(color_type == 2){ color1[0] = 0; color1[1] = 1; color1[2] = 0; color1[3] = 1; color2[0] = 0.4f; color2[1] = 0.4f; color2[2] = 0.4f; color2[3] = 1; color3[0] = 0.4f; color3[1] = 0.4f; color3[2] = 0.4f; color3[3] = 1; color4[0] = 0; color4[1] = 1; color4[2] = 0; color4[3] = 1; color5[0] = 0.4f; color5[1] = 0.4f; color5[2] = 0.4f; color5[3] = 1; color6[0] = 0.4f; color6[1] = 0.4f; color6[2] = 0.4f; color6[3] = 1; } else if(color_type == 1){ color1[0] = 1; color1[1] = 0; color1[2] = 0; color1[3] = 1; color2[0] = 0.4f; color2[1] = 0.4f; color2[2] = 0.4f; color2[3] = 1; color3[0] = 0.4f; color3[1] = 0.4f; color3[2] = 0.4f; color3[3] = 1; color4[0] = 1; color4[1] = 0; color4[2] = 0; color4[3] = 1; color5[0] = 0.4f; color5[1] = 0.4f; color5[2] = 0.4f; color5[3] = 1; color6[0] = 0.4f; color6[1] = 0.4f; color6[2] = 0.4f; color6[3] = 1; } else if(color_type == 4){ color1[0] = 0; color1[1] = 0; color1[2] = 1; color1[3] = 1; color2[0] = 0.4f; color2[1] = 0.4f; color2[2] = 0.4f; color2[3] = 1; color3[0] = 0.4f; color3[1] = 0.4f; color3[2] = 0.4f; color3[3] = 1; color4[0] = 0; color4[1] = 0; color4[2] = 1; color4[3] = 1; color5[0] = 0.4f; color5[1] = 0.4f; color5[2] = 0.4f; color5[3] = 1; color6[0] = 0.4f; color6[1] = 0.4f; color6[2] = 0.4f; color6[3] = 1; } else{ color1[0] = 0.7f; color1[1] = 0.7f; color1[2] = 0.7f; color1[3] = 1; color2[0] = 0.7f; color2[1] = 0.7f; color2[2] = 0.7f; color2[3] = 1; color3[0] = 0.7f; color3[1] = 0.7f; color3[2] = 0.7f; color3[3] = 1; color4[0] = 0.7f; color4[1] = 0.7f; color4[2] = 0.7f; color4[3] = 1; color5[0] = 0.7f; color5[1] = 0.7f; color5[2] = 0.7f; color5[3] = 1; color6[0] = 0.7f; color6[1] = 0.7f; color6[2] = 0.7f; color6[3] = 1; } GLfloat ambient[4] = {0.3f,0.3f,0.3f,1.0f}; GLfloat material_color[4] = {1,1,1,0.5f}; GLfloat material_specular[4] = {0.5f,0.5f,0.5f,0.5f}; GLfloat material_ambient[4] = {0.0,0.0,0.0,0.0}; glClearColor(1,1,1,0); //glClearColor(0.7,0.7,0.7,0); glLightfv(GL_LIGHT0, GL_POSITION, light_position1); glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, direction1); glLightfv(GL_LIGHT0, GL_DIFFUSE, color1); glLightfv(GL_LIGHT0, GL_SPECULAR, color1); glLightfv(GL_LIGHT1, GL_POSITION, light_position2); glLightfv(GL_LIGHT1, GL_SPOT_DIRECTION, direction2); glLightfv(GL_LIGHT1, GL_DIFFUSE, color2); glLightfv(GL_LIGHT1, GL_SPECULAR, color2); glLightfv(GL_LIGHT2, GL_POSITION, light_position3); glLightfv(GL_LIGHT2, GL_SPOT_DIRECTION, direction3); glLightfv(GL_LIGHT2, GL_DIFFUSE, color3); glLightfv(GL_LIGHT2, GL_SPECULAR, color3); glLightfv(GL_LIGHT3, GL_POSITION, light_position4); glLightfv(GL_LIGHT3, GL_SPOT_DIRECTION, direction4); glLightfv(GL_LIGHT3, GL_DIFFUSE, color4); glLightfv(GL_LIGHT3, GL_SPECULAR, color4); glLightfv(GL_LIGHT4, GL_POSITION, light_position5); glLightfv(GL_LIGHT4, GL_SPOT_DIRECTION, direction5); glLightfv(GL_LIGHT4, GL_DIFFUSE, color5); glLightfv(GL_LIGHT4, GL_SPECULAR, color5); glLightfv(GL_LIGHT5, GL_POSITION, light_position6); glLightfv(GL_LIGHT5, GL_SPOT_DIRECTION, direction6); glLightfv(GL_LIGHT5, GL_DIFFUSE, color6); glLightfv(GL_LIGHT5, GL_SPECULAR, color6); glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambient); glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, material_specular); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, material_color); glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, material_ambient); glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 128); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_LIGHT1); glEnable(GL_LIGHT2); glEnable(GL_LIGHT3); glEnable(GL_LIGHT4); glEnable(GL_LIGHT5); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LESS); glEnable(GL_POINT_SMOOTH); glHint(GL_POINT_SMOOTH_HINT, GL_NICEST); //glEnable(GL_LINE_SMOOTH); //glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST); glLineWidth(1.0); glPointSize(3.0); wglMakeCurrent(clientDC.m_hDC, NULL); //glEnable(GL_BLEND); //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } void CMeshEditorView::smoothShade(MeshData *mesh) { //CClientDC clientDC(this); //wglMakeCurrent(clientDC.m_hDC, m_hRC); //glDeleteLists(1,1); //glNewList(1, GL_COMPILE); glShadeModel(GL_SMOOTH); int face_N = mesh->getFaceCount(); for(int i=0; iface[i]; if(f[0] < 0) continue; glBegin(GL_POLYGON); glNormal3fv(mesh->normal[f[0]]); glVertex3fv(mesh->vertex[f[0]]); glNormal3fv(mesh->normal[f[1]]); glVertex3fv(mesh->vertex[f[1]]); glNormal3fv(mesh->normal[f[2]]); glVertex3fv(mesh->vertex[f[2]]); glEnd(); } //glEndList(); //wglMakeCurrent(clientDC.m_hDC, NULL); //CClientDC* dc = new CClientDC(this); //OnDraw(dc); //delete dc; } void CMeshEditorView::OnRButtonUp(UINT nFlags, CPoint point) { // TODO: この位置にメッセージ ハンドラ用のコードを追加するかまたはデフォルトの処理を呼び出してください isRPressed = false; CView::OnRButtonUp(nFlags, point); } void CMeshEditorView::OnRButtonDown(UINT nFlags, CPoint point) { // TODO: この位置にメッセージ ハンドラ用のコードを追加するかまたはデフォルトの処理を呼び出してください isRPressed = true; px = point.x; py = point.y; CView::OnRButtonDown(nFlags, point); } void CMeshEditorView::OnLButtonDown(UINT nFlags, CPoint point) { // TODO: この位置にメッセージ ハンドラ用のコードを追加するかまたはデフォルトの処理を呼び出してください isLPressed = TRUE; px = point.x; py = point.y; CView::OnLButtonDown(nFlags, point); } void CMeshEditorView::OnLButtonUp(UINT nFlags, CPoint point) { // TODO: この位置にメッセージ ハンドラ用のコードを追加するかまたはデフォルトの処理を呼び出してください isLPressed = FALSE; CView::OnLButtonUp(nFlags, point); } void CMeshEditorView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) { // TODO: この位置にメッセージ ハンドラ用のコードを追加するかまたはデフォルトの処理を呼び出してください float ex[3], ey[3], v[3]; for(int i=0; i<3; i++) v[i] = (float)(center[i] - eye[i]); ey[0] = -v[0] * v[2]; ey[1] = -v[1] * v[2]; ey[2] = v[0] * v[0] + v[1] * v[1]; double norm = ey[0] * ey[0] + ey[1] * ey[1] + ey[2] * ey[2]; norm = 5*sqrt(norm); for(i=0; i<3; i++) ey[i] = (float)(ey[i] / norm); MeshData::CROSS(ex, v, ey); norm = 5*MeshData::LENGTH(ex); ex[0] = (float)(ex[0]/norm); ex[1] = (float)(ex[1]/norm); ex[2] = (float)(ex[2]/norm); switch(nChar){ case VK_UP: shift_x += ey[0]; shift_y += ey[1]; shift_z += ey[2]; break; case VK_DOWN: shift_x -= ey[0]; shift_y -= ey[1]; shift_z -= ey[2]; break; case VK_RIGHT: shift_x += ex[0]; shift_y += ex[1]; shift_z += ex[2]; break; case VK_LEFT: shift_x -= ex[0]; shift_y -= ex[1]; shift_z -= ex[2]; break; } /* switch(nChar){ case VK_UP: shift_z += 1; break; case VK_DOWN: shift_z -= 1; break; case VK_RIGHT: shift_x += 1; break; case VK_LEFT: shift_x -= 1; break; } */ CClientDC* dc = new CClientDC(this); OnDraw(dc); delete dc; CView::OnKeyDown(nChar, nRepCnt, nFlags); } BOOL CMeshEditorView::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt) { // TODO: この位置にメッセージ ハンドラ用のコードを追加するかまたはデフォルトの処理を呼び出してください Rx += zDelta/20; CClientDC* dc = new CClientDC(this); OnDraw(dc); delete dc; return CView::OnMouseWheel(nFlags, zDelta, pt); } void CMeshEditorView::OnMouseMove(UINT nFlags, CPoint point) { // TODO: この位置にメッセージ ハンドラ用のコードを追加するかまたはデフォルトの処理を呼び出してください if(isLPressed){ int nx = point.x; int ny = point.y; int aZ, aY; Rz += aZ = (nx - px)/3; Ry += aY = (ny - py)/3; px = nx; py = ny; CClientDC* dc = new CClientDC(this); OnDraw(dc); delete dc; /* float tmp2[3]; tmp2[0] = 0; tmp2[1] = 0; tmp2[2] = 1; //vx[0] = cos(aZ)*tmp2[0] - sin(aZ)*tmp2[1]; //vx[1] = sin(aZ)*tmp2[0] + cos(aZ)*tmp2[1]; float tmp1[3]; tmp1[0] = -(float)(eye[1]/sqrt(eye[0]*eye[0]+eye[1]*eye[1])); tmp1[1] = (float)(eye[0]/sqrt(eye[0]*eye[0]+eye[1]*eye[1])); tmp1[2] = 0; vy[0] = cos(aZ)*tmp1[0] - sin(aZ)*tmp1[1]; vy[1] = sin(aZ)*tmp1[0] + cos(aZ)*tmp1[1]; vx[0] = cos(aZ)*tmp2[0] - sin(aZ)*tmp2[1]; vx[1] = sin(aZ)*tmp2[0] + cos(aZ)*tmp2[1]; */ } else if(isRPressed){ int nx = point.x; int ny = point.y; view_angle += (ny - py)/20.0f; px = nx; py = ny; CClientDC* dc = new CClientDC(this); RECT* rect = new RECT; GetClientRect(rect); OnSize(SIZE_RESTORED, rect->right, rect->bottom); delete rect; OnDraw(dc); delete dc; } CView::OnMouseMove(nFlags, point); } void CMeshEditorView::drawRidgeVertexAsSegmet(MeshData *mesh, BOOL transparent, BOOL gray_scale, BOOL principal_dir) { //CClientDC clientDC(this); //wglMakeCurrent(clientDC.m_hDC, m_hRC); //glDeleteLists(1,1); //glNewList(1, GL_COMPILE); glShadeModel(GL_SMOOTH); glDisable(GL_LIGHTING); int vertex_N = mesh->vertex_N; float (*vertex)[3] = mesh->vertex; double (*ridge_dir)[3], (*ravine_dir)[3]; if(!principal_dir){ ridge_dir = mesh->ridge_dir; ravine_dir = mesh->ravine_dir; } BOOL *isRidge = mesh->isRidge; BOOL *isRavine = mesh->isRavine; mesh->computeNormal(); float (*normal)[3] = mesh->normal; if(gray_scale) glColor3f(1,1,1); else glColor3f(1,0,0); float r[] = {0.1f, 0.03f, 0.01f}; float d[3][3]; //glPointSize(10.0); glBegin(GL_POINTS); for(int i=0; iface_N; int (*face)[3] = mesh->face; /* if(gray_scale) glColor3f(0.7f, 0.7f, 0.7f); else glColor3f(0.9f,0.9f,0.9f); */ for(i=0; inormal_f[i]); //glNormal3fv(normal[i1]); glVertex3fv(p1); //glNormal3fv(normal[i2]); glVertex3fv(p2); //glNormal3fv(normal[i3]); glVertex3fv(p3); glEnd(); } } glEnable(GL_LIGHTING); //glEndList(); //wglMakeCurrent(clientDC.m_hDC, NULL); //CClientDC* dc = new CClientDC(this); //OnDraw(dc); //delete dc; } void CMeshEditorView::drawPrincipalDir(MeshData *mesh, BOOL max, BOOL min, BOOL transparent, BOOL gray_scale) { //CClientDC clientDC(this); //wglMakeCurrent(clientDC.m_hDC, m_hRC); //glDeleteLists(1,1); //glNewList(1, GL_COMPILE); glShadeModel(GL_SMOOTH); glDisable(GL_LIGHTING); int vertex_N = mesh->vertex_N; float (*vertex)[3] = mesh->vertex; double (*t_max)[3] = mesh->t_max; double (*t_min)[3] = mesh->t_min; double* k_max = mesh->k_max; double* k_min = mesh->k_min; float len = 0.2f; if(max){ if(gray_scale) glColor3f(0,0,0); else glColor3f(1,0,0); for(int i=0; iface_N; int (*face)[3] = mesh->face; float (*normal)[3] = mesh->normal; if(gray_scale) glColor3f(0.85f, 0.85f, 0.85f); else glColor3f(0.9f,0.9f,0.9f); for(int i=0; ivertex_N; float (*vertex)[3] = mesh->vertex; int (*face)[3] = mesh->face; int face_N = mesh->face_N; BOOL *isRidge = mesh->isRidge; BOOL *isRavine = mesh->isRavine; if(grey_scale) glColor3f(0,0,0); else glColor3f(1,0,0); for(int i=0; i i2 && isRidge[i1] && isRidge[i2]){ glBegin(GL_LINES); glVertex3fv(vertex[i1]); glVertex3fv(vertex[i2]); glEnd(); } } } if(grey_scale) glColor3f(1,1,1); else glColor3f(0,0,1); for(i=0; i i2 && isRavine[i1] && isRavine[i2]){ glBegin(GL_LINES); glVertex3fv(vertex[i1]); glVertex3fv(vertex[i2]); glEnd(); } } } if(!transparent){ glEnable(GL_LIGHTING); int face_N = mesh->face_N; int (*face)[3] = mesh->face; float (*normal)[3] = mesh->normal; /* if(gray_scale) glColor3f(0.7f, 0.7f, 0.7f); else glColor3f(0.9f,0.9f,0.9f); */ for(i=0; inormal_f[i]); //glNormal3fv(normal[i1]); glVertex3fv(p1); //glNormal3fv(normal[i2]); glVertex3fv(p2); //glNormal3fv(normal[i3]); glVertex3fv(p3); glEnd(); } /* if(grey_scale) glColor3f(0.7f, 0.7f, 0.7f); else glColor3f(0.9f,0.9f,0.9f); for(int i=0; ivertex; int (*face)[3] = mesh->face; int face_N = mesh->face_N; int vertex_N = mesh->vertex_N; float (*color)[3] = new float[vertex_N][3]; if(gray) convertToColorG(vertex_N, v, color); else convertToColor(vertex_N, v, color); //CClientDC clientDC(this); //wglMakeCurrent(clientDC.m_hDC, m_hRC); //glDeleteLists(1,1); //glNewList(1, GL_COMPILE); glShadeModel(GL_SMOOTH); glDisable(GL_LIGHTING); for(int i=0; ivertex_N; float (*vertex)[3] = mesh->vertex; float (*normal)[3] = mesh->normal; if(grey_scale) glColor3f(0,0,0); else glColor3f(1,0,0); for(int i=0; iv > i) continue; //sphere(0.15f, vertex[ridge_path[i][j]->v], 6); for(Node* current=ridge_path[i][j]; current->next!=NULL && current->v != i; current=current->next){ glBegin(GL_LINES); glVertex3f(vertex[current->v][0] + 0.02f*normal[current->v][0], vertex[current->v][1] + 0.02f*normal[current->v][1], vertex[current->v][2] + 0.02f*normal[current->v][2]); glVertex3f(vertex[current->next->v][0] + 0.02f*normal[current->next->v][0], vertex[current->next->v][1] + 0.02f*normal[current->next->v][1], vertex[current->next->v][2] + 0.02f*normal[current->next->v][2]); glEnd(); } //sphere(0.15f, vertex[i], 6); } } if(grey_scale) glColor3f(1,1,1); else glColor3f(0,0,1); for(i=0; iv > i) continue; //sphere(0.15f, vertex[ravine_path[i][j]->v], 6); for(Node* current=ravine_path[i][j]; current->next!=NULL && current->v != i; current=current->next){ glBegin(GL_LINES); glVertex3fv(vertex[current->v]); glVertex3fv(vertex[current->next->v]); glEnd(); } //sphere(0.15f, vertex[i], 6); } } if(grey_scale) glColor3f(0.5,0.5,0.5); else glColor3f(0,1,0); for(i=0; iv > i || normal_path[i][j]->next == NULL) continue; //sphere(0.1f, vertex[normal_path[i][j]->v], 6); //glBegin(GL_LINES); //glVertex3fv(vertex[normal_path[i][j]->v]); //glVertex3fv(vertex[i]); //glEnd(); for(Node* current=normal_path[i][j]; current->v != i; current=current->next){ glBegin(GL_LINES); glVertex3fv(vertex[current->v]); glVertex3fv(vertex[current->next->v]); glEnd(); } //sphere(0.1f, vertex[i], 6); } } if(true){ int face_N = mesh->face_N; int (*face)[3] = mesh->face; if(grey_scale) glColor3f(0.7f, 0.7f, 0.7f); else glColor3f(0.9f,0.9f,0.9f); for(int i=0; ivertex_N; float (*vertex)[3] = mesh->vertex; int (*face)[3] = mesh->face; int face_N = mesh->face_N; mesh->computeFaceNormal(); mesh->computeNormal(); float (*normal)[3] = mesh->normal; int i; if(grey_scale) glColor3f(1,1,1); else glColor3f(1,0,0); //glLineWidth(3.0); for(i=0; inext != NULL; current = current->next){ if(current->v > i){ //cylinder(vertex[i], vertex[current->v], normal[i], normal[current->v], 0.025, 7); glBegin(GL_LINES); glVertex3fv(vertex[i]); glVertex3fv(vertex[current->v]); glEnd(); } } if(grey_scale) glColor3f(0,0,0); else glColor3f(0,0,1); //glLineWidth(3.0); for(i=0; inext != NULL; current = current->next){ if(current->v > i){ //cylinder(vertex[i], vertex[current->v], normal[i], normal[current->v], 0.025, 7); glBegin(GL_LINES); glVertex3fv(vertex[i]); glVertex3fv(vertex[current->v]); glEnd(); } } float d = (float)(0.05*view_angle/22.5); if(!transparent && shaded){ glEnable(GL_LIGHTING); int face_N = mesh->face_N; int (*face)[3] = mesh->face; //if(gray_scale) //glColor3f(0.7f, 0.7f, 0.7f); //else //glColor3f(0.9f,0.9f,0.9f); for(i=0; inormal_f[i]); //glNormal3fv(normal[i1]); glVertex3fv(p1); //glNormal3fv(normal[i2]); glVertex3fv(p2); //glNormal3fv(normal[i3]); glVertex3fv(p3); glEnd(); } } else if(!transparent && !shaded){ if(grey_scale) glColor3f(0.7f, 0.7f, 0.7f); else glColor3f(0.9f,0.9f,0.9f); for(int i=0; ivertex_N; int face_N = mesh->face_N; int (*face)[3] = mesh->face; float (*normal_f)[3] = mesh->normal_f; float (*normal)[3] = mesh->normal; float (*vertex)[3] = mesh->vertex; //glNewList(1, GL_COMPILE); glShadeModel(GL_SMOOTH); glDisable(GL_LIGHTING); //glColor3f(0.4f, 0.2f, 0.2f); glColor3f(0.0f, 0.0f, 0.0f); for(int i=0; i face[i][1]){ glBegin(GL_LINES); glVertex3fv(vertex[face[i][0]]); glVertex3fv(vertex[face[i][1]]); glEnd(); } if(face[i][1] > face[i][2]){ glBegin(GL_LINES); glVertex3fv(vertex[face[i][1]]); glVertex3fv(vertex[face[i][2]]); glEnd(); } if(face[i][2] > face[i][0]){ glBegin(GL_LINES); glVertex3fv(vertex[face[i][2]]); glVertex3fv(vertex[face[i][0]]); glEnd(); } } glEnable(GL_LIGHTING); //glColor3f(1.0f, 1.0f, 1.0f); float d = (float)(0.05*view_angle/22.5); /*0.05*sqrt((eye[0] - shift_x)*(eye[0] - shift_x) + (eye[1] - shift_y)*(eye[1] - shift_y) + (eye[2] - shift_z)*(eye[2] - shift_z))/sqrt(eye[0]*eye[0] + eye[1]*eye[1] + eye[2]*eye[2]);*/ for(i=0; iisFixed[i]) glVertex3fv(vertex[i]); glEnd(); */ //glEnable(GL_LIGHTING); /* //CClientDC clientDC(this); //wglMakeCurrent(clientDC.m_hDC, m_hRC); int face_N = mesh->face_N; int (*face)[3] = mesh->face; float (*normal_f)[3] = mesh->normal_f; float (*normal)[3] = mesh->normal; float (*vertex)[3] = mesh->vertex; //glDeleteLists(1,1); //glNewList(1, GL_COMPILE); glShadeModel(GL_SMOOTH); glDisable(GL_LIGHTING); glColor3f(0.0f, 0.0f, 0.0f); glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); for(int i=0; ivertex_N; float (*vertex)[3] = mesh->vertex; int face_N = mesh->face_N; int (*face)[3] = mesh->face; float (*normal)[3] = mesh->normal; float (*color)[3] = new float[vertex_N][3]; int *id = new int[vertex_N]; BOOL *valid = new BOOL[vertex_N]; int cluster_id = 0; for(int i=0; inext!=NULL; current=current->next){ valid[i] = true; id[current->v] = cluster_id; } if(valid[i]) cluster_id++; } if(gray_scale){ int gray_level = 0; for(int i=0; inext!=NULL; current=current->next){ int v = current->v; color[v][0] = 0.0125f*gray_level+0.7f; color[v][1] = 0.0125f*gray_level+0.7f; color[v][2] = 0.0125f*gray_level+0.7f; } if(valid[i]) gray_level = (gray_level+3)%20; } } else{ int C[3] = {1,0,0}; int index = 0; for(int i=0; inext!=NULL; current=current->next){ int v = current->v; color[v][0] = 0.1f*C[0]; color[v][1] = 0.1f*C[1]; color[v][2] = 0.1f*C[2]; } if(valid[i]){ C[index] = (C[index]+2)%11; index = (index+1)%3; } } } glBegin(GL_POINTS); for(i=0; ivertex_N; float (*vertex)[3] = mesh->vertex; if(max){ double *k_max = mesh->k_max; double (*t_max)[3] = mesh->t_max; float (*color)[3] = new float[vertex_N][3]; float (*v)[3] = new float[vertex_N][3]; for(int i=0; ik_min; double (*t_min)[3] = mesh->t_min; float (*color)[3] = new float[vertex_N][3]; float (*v)[3] = new float[vertex_N][3]; for(int i=0; iface_N; int (*face)[3] = mesh->face; float (*normal)[3] = mesh->normal; if(gray_scale) glColor3f(1.0f, 1.0f, 1.0f); else glColor3f(0.9f,0.9f,0.9f); for(int i=0; iisBound; float (*vertex)[3] = mesh->vertex; int (*face)[3] = mesh->face; int (*link)[3] = mesh->face_link_E; int vertex_N = mesh->vertex_N; int face_N = mesh->face_N; float (*normal)[3] = mesh->normal; glShadeModel(GL_SMOOTH); glDisable(GL_LIGHTING); glColor3f(1.0f, 0.0f, 0.0f); glBegin(GL_POINTS); for(int i=0; ivertex; int (*face)[3] = mesh->face; int face_N = mesh->face_N; int vertex_N = mesh->vertex_N; float (*normal)[3] = mesh->normal; float (*color)[3][3] = new float[face_N][3][3]; convertToEdgeColor(face_N, mesh->k_edge, color); glShadeModel(GL_SMOOTH); glDisable(GL_LIGHTING); for(int i=0; i face[i][(j+1)%3]) continue; glBegin(GL_LINES); glColor3fv(color[i][j]); glVertex3fv(vertex[ face[i][j] ]); glVertex3fv(vertex[ face[i][(j+1)%3] ]); glEnd(); } } delete[] color; glColor3f(1.0f, 1.0f, 1.0f); for(i=0; i 1) v = 1; else if(v < 0) v = 0; color[i][0] = v; color[i][1] = v; color[i][2] = v; } delete[] len; } void CMeshEditorView::drawRidgeTriangle(MeshData *mesh) { glShadeModel(GL_SMOOTH); glDisable(GL_LIGHTING); float (*vertex)[3] = mesh->vertex; int face_N = mesh->face_N; int (*face)[3] = mesh->face; double (*ridge_T)[3] = mesh->ridge_T; double (*ravine_T)[3] = mesh->ravine_T; BOOL *isRidge_T = mesh->isRidge_T; BOOL *isRavine_T = mesh->isRavine_T; glColor3f(1.0, 0, 0); for(int i=0; ivertex_N; float (*normal)[3] = mesh->normal; double (*t_max)[3] = mesh->t_max; double (*t_min)[3] = mesh->t_min; double *k_max = mesh->k_max; double *k_min = mesh->k_min; float (*x)[3] = mesh->vertex; int (*face)[3] = mesh->face; int face_N = mesh->face_N; BOOL *isRidge = mesh->isRidge; BOOL *isRavine = mesh->isRavine; double (*ridge_dir)[3] = mesh->ridge_dir; double (*ravine_dir)[3] = mesh->ravine_dir; float *d = new float[vertex_N]; glColor3f(0, 0, 0); glDisable(GL_LIGHTING); float R[3][3], R1[3][3], R2[3][3], R3[3][3], tmp[3][3], view[3]; GENERATE_MAT(R1, -(float)(PI*Rz/180.0f), vx); MAT_VEC(view, R1, vy); GENERATE_MAT(R2, -(float)(PI*Ry/180.0f), view); MAT_TIMES(tmp, R2, R1); MAT_VEC(view, tmp, vz); GENERATE_MAT(R3, -(float)(PI*Rx/180.0f), view); MAT_TIMES(R, R3, tmp); float eyei[3], eyef[3]; eyei[0] = (float)eye[0]; eyei[1] = (float)eye[1]; eyei[2] = (float)eye[2]; MAT_VEC(eyef, R, eyei); for(int i=0; i fabs(k_min[i])){ seg_dir[i][0] = (float)t_max[i][0]; seg_dir[i][1] = (float)t_max[i][1]; seg_dir[i][2] = (float)t_max[i][2]; } else{ seg_dir[i][0] = (float)t_min[i][0]; seg_dir[i][1] = (float)t_min[i][1]; seg_dir[i][2] = (float)t_min[i][2]; }*/ } for(int j=0; jsample_N; struct MeshData::TRI_POINT* sample_point = mesh->sample_point; int* t_max_line_N = mesh->t_max_line_N; int* t_min_line_N = mesh->t_min_line_N; struct MeshData::TRI_POINT** t_max_line = mesh->t_max_line; struct MeshData::TRI_POINT** t_min_line = mesh->t_min_line; for(i=0; i k2){ glBegin(GL_LINES); f = face[t_max_line[i][0].id]; t1 = t_max_line[i][0].u; t2 = t_max_line[i][0].v; t0 = 1.0 - t1 - t2; float last_p[3]; last_p[0] = (float)(t0*x[f[0]][0] + t1*x[f[1]][0] + t2*x[f[2]][0]); last_p[1] = (float)(t0*x[f[0]][1] + t1*x[f[1]][1] + t2*x[f[2]][1]); last_p[2] = (float)(t0*x[f[0]][2] + t1*x[f[1]][2] + t2*x[f[2]][2]); for(int j=1; jridge_line; int *ridge_line_N = mesh->ridge_line_N; int ridge_point_N = mesh->ridge_point_N; for(i=0; iridge_point[i].id]; double t1 = mesh->ridge_point[i].u; double t2 = mesh->ridge_point[i].v; double t0 = 1.0 - t1 - t2; float last_p[3]; last_p[0] = (float)(t0*x[f[0]][0] + t1*x[f[1]][0] + t2*x[f[2]][0]); last_p[1] = (float)(t0*x[f[0]][1] + t1*x[f[1]][1] + t2*x[f[2]][1]); last_p[2] = (float)(t0*x[f[0]][2] + t1*x[f[1]][2] + t2*x[f[2]][2]); glBegin(GL_POINTS); glVertex3fv(last_p); glEnd();*/ /* glBegin(GL_LINES); int *f = face[ridge_line[i][0].id]; double t1 = ridge_line[i][0].u; double t2 = ridge_line[i][0].v; double t0 = 1.0 - t1 - t2; float last_p[3]; last_p[0] = (float)(t0*x[f[0]][0] + t1*x[f[1]][0] + t2*x[f[2]][0]); last_p[1] = (float)(t0*x[f[0]][1] + t1*x[f[1]][1] + t2*x[f[2]][1]); last_p[2] = (float)(t0*x[f[0]][2] + t1*x[f[1]][2] + t2*x[f[2]][2]); for(int j=1; jravine_line; int *ravine_line_N = mesh->ravine_line_N; int ravine_point_N = mesh->ravine_point_N; for(i=0; iravine_point[i].id]; double t1 = mesh->ravine_point[i].u; double t2 = mesh->ravine_point[i].v; double t0 = 1.0 - t1 - t2; float last_p[3]; last_p[0] = (float)(t0*x[f[0]][0] + t1*x[f[1]][0] + t2*x[f[2]][0]); last_p[1] = (float)(t0*x[f[0]][1] + t1*x[f[1]][1] + t2*x[f[2]][1]); last_p[2] = (float)(t0*x[f[0]][2] + t1*x[f[1]][2] + t2*x[f[2]][2]); glBegin(GL_POINTS); glVertex3fv(last_p); glEnd();*/ /* glBegin(GL_LINES); int *f = face[ravine_line[i][0].id]; double t1 = ravine_line[i][0].u; double t2 = ravine_line[i][0].v; double t0 = 1.0 - t1 - t2; float last_p[3]; last_p[0] = (float)(t0*x[f[0]][0] + t1*x[f[1]][0] + t2*x[f[2]][0]); last_p[1] = (float)(t0*x[f[0]][1] + t1*x[f[1]][1] + t2*x[f[2]][1]); last_p[2] = (float)(t0*x[f[0]][2] + t1*x[f[1]][2] + t2*x[f[2]][2]); for(int j=1; jvertex_N; double *k_max = mesh->k_max; double *k_min = mesh->k_min; float (*vertex)[3] = mesh->vertex; int (*face)[3] = mesh->face; float (*normal)[3] = mesh->normal; int face_N = mesh->face_N; glDisable(GL_LIGHTING); for(int i=0; i T*dist){ if(grey_scale) glColor3f(1.0f, 1.0f, 1.0f); else glColor3f(1.0f, 0.0f, 0.0f); float p1[3], p2[3]; p1[0] = (vertex[f[0]][0] + vertex[f[1]][0] + vertex[f[2]][0])/3.0f; p1[1] = (vertex[f[0]][1] + vertex[f[1]][1] + vertex[f[2]][1])/3.0f; p1[2] = (vertex[f[0]][2] + vertex[f[1]][2] + vertex[f[2]][2])/3.0f; p2[0] = (vertex[i1][0] + vertex[i2][0])*0.5f; p2[1] = (vertex[i1][1] + vertex[i2][1])*0.5f; p2[2] = (vertex[i1][2] + vertex[i2][2])*0.5f; glBegin(GL_LINES); glVertex3fv(p1); glVertex3fv(p2); glEnd(); } if(fabs(k_min[i1]-k_min[i2]) > T*dist){ if(grey_scale) glColor3f(0.0f, 0.0f, 0.0f); else glColor3f(0.0f, 0.0f, 1.0f); float p1[3], p2[3]; p1[0] = (vertex[f[0]][0] + vertex[f[1]][0] + vertex[f[2]][0])/3.0f; p1[1] = (vertex[f[0]][1] + vertex[f[1]][1] + vertex[f[2]][1])/3.0f; p1[2] = (vertex[f[0]][2] + vertex[f[1]][2] + vertex[f[2]][2])/3.0f; p2[0] = (vertex[i1][0] + vertex[i2][0])*0.5f; p2[1] = (vertex[i1][1] + vertex[i2][1])*0.5f; p2[2] = (vertex[i1][2] + vertex[i2][2])*0.5f; glBegin(GL_LINES); glVertex3fv(p1); glVertex3fv(p2); glEnd(); } } } glColor3f(0.8f,0.8f,0.8f); for(i=0; ivertex_N; double (*t_max)[3] = mesh->t_max; double (*t_min)[3] = mesh->t_min; float (*vertex)[3] = mesh->vertex; int (*face)[3] = mesh->face; float (*normal)[3] = mesh->normal; int face_N = mesh->face_N; glDisable(GL_LIGHTING); for(int i=0; iparalellTrans(v, t_max[i2], i2, i1); double dot = MeshData::DOT(t_max[i1], v); if(dot > 1) dot = 1; else if(dot < -1) dot = -1; if(acos(fabs(dot)) > T*dist){ //if(grey_scale) glColor3f(0.0f, 0.0f, 0.0f); //else //glColor3f(1.0f, 0.0f, 0.0f); break; /* float p1[3], p2[3]; p1[0] = (vertex[f[0]][0] + vertex[f[1]][0] + vertex[f[2]][0])/3.0f; p1[1] = (vertex[f[0]][1] + vertex[f[1]][1] + vertex[f[2]][1])/3.0f; p1[2] = (vertex[f[0]][2] + vertex[f[1]][2] + vertex[f[2]][2])/3.0f; p2[0] = (vertex[i1][0] + vertex[i2][0])*0.5f; p2[1] = (vertex[i1][1] + vertex[i2][1])*0.5f; p2[2] = (vertex[i1][2] + vertex[i2][2])*0.5f; glBegin(GL_LINES); glVertex3fv(p1); glVertex3fv(p2); glEnd(); */ } /* mesh->paralellTrans(v, t_min[i2], i2, i1); if(acos(fabs(MeshData::DOT(t_min[i1], v))) > T*dist){ if(grey_scale) glColor3f(0.0f, 0.0f, 0.0f); else glColor3f(0.0f, 0.0f, 1.0f); float p1[3], p2[3]; p1[0] = (vertex[f[0]][0] + vertex[f[1]][0] + vertex[f[2]][0])/3.0f; p1[1] = (vertex[f[0]][1] + vertex[f[1]][1] + vertex[f[2]][1])/3.0f; p1[2] = (vertex[f[0]][2] + vertex[f[1]][2] + vertex[f[2]][2])/3.0f; p2[0] = (vertex[i1][0] + vertex[i2][0])*0.5f; p2[1] = (vertex[i1][1] + vertex[i2][1])*0.5f; p2[2] = (vertex[i1][2] + vertex[i2][2])*0.5f; glBegin(GL_LINES); glVertex3fv(p1); glVertex3fv(p2); glEnd(); }*/ } glBegin(GL_POLYGON); glVertex3fv(vertex[f[0]]); glVertex3fv(vertex[f[1]]); glVertex3fv(vertex[f[2]]); glEnd(); } /* glColor3f(0.8f,0.8f,0.8f); for(i=0; ivertex_N; float (*normal)[3] = mesh->normal; float (*x)[3] = mesh->vertex; int (*face)[3] = mesh->face; int face_N = mesh->face_N; float *d = new float[vertex_N]; glColor3f(0, 0, 0); glDisable(GL_LIGHTING); float R[3][3], R1[3][3], R2[3][3], R3[3][3], tmp[3][3], view[3]; GENERATE_MAT(R1, -(float)(PI*Rz/180.0f), vx); MAT_VEC(view, R1, vy); GENERATE_MAT(R2, -(float)(PI*Ry/180.0f), view); MAT_TIMES(tmp, R2, R1); MAT_VEC(view, tmp, vz); GENERATE_MAT(R3, -(float)(PI*Rx/180.0f), view); MAT_TIMES(R, R3, tmp); float eyei[3], eyef[3]; eyei[0] = (float)eye[0]; eyei[1] = (float)eye[1]; eyei[2] = (float)eye[2]; MAT_VEC(eyef, R, eyei); for(int i=0; isample_N; int* t_max_line_N = mesh->t_max_line_N; struct MeshData::TRI_POINT** t_max_line = mesh->t_max_line; for(i=0; ivertex_N; float (*normal)[3] = mesh->normal; float (*x)[3] = mesh->vertex; int (*face)[3] = mesh->face; int face_N = mesh->face_N; float *d = new float[vertex_N]; glColor3f(0, 0, 0); glDisable(GL_LIGHTING); float R[3][3], R1[3][3], R2[3][3], R3[3][3], tmp[3][3], view[3]; GENERATE_MAT(R1, -(float)(PI*Rz/180.0f), vx); MAT_VEC(view, R1, vy); GENERATE_MAT(R2, -(float)(PI*Ry/180.0f), view); MAT_TIMES(tmp, R2, R1); MAT_VEC(view, tmp, vz); GENERATE_MAT(R3, -(float)(PI*Rx/180.0f), view); MAT_TIMES(R, R3, tmp); float eyei[3], eyef[3]; eyei[0] = (float)eye[0]; eyei[1] = (float)eye[1]; eyei[2] = (float)eye[2]; MAT_VEC(eyef, R, eyei); for(int i=0; isample_N; int* t_min_line_N = mesh->t_min_line_N; struct MeshData::TRI_POINT** t_min_line = mesh->t_min_line; for(i=0; ivertex_N; float (*normal)[3] = mesh->normal; double (*t_max)[3] = mesh->t_max; double (*t_min)[3] = mesh->t_min; double *k_max = mesh->k_max; double *k_min = mesh->k_min; float (*x)[3] = mesh->vertex; int (*face)[3] = mesh->face; int face_N = mesh->face_N; float *d = new float[vertex_N]; glColor3f(0, 0, 0); glDisable(GL_LIGHTING); float R[3][3], R1[3][3], R2[3][3], R3[3][3], tmp[3][3], view[3]; GENERATE_MAT(R1, -(float)(PI*Rz/180.0f), vx); MAT_VEC(view, R1, vy); GENERATE_MAT(R2, -(float)(PI*Ry/180.0f), view); MAT_TIMES(tmp, R2, R1); MAT_VEC(view, tmp, vz); GENERATE_MAT(R3, -(float)(PI*Rx/180.0f), view); MAT_TIMES(R, R3, tmp); float eyei[3], eyef[3]; eyei[0] = (float)eye[0]; eyei[1] = (float)eye[1]; eyei[2] = (float)eye[2]; MAT_VEC(eyef, R, eyei); for(int i=0; isample_N; struct MeshData::TRI_POINT* sample_point = mesh->sample_point; int* t_max_line_N = mesh->t_max_line_N; int* t_min_line_N = mesh->t_min_line_N; struct MeshData::TRI_POINT** t_max_line = mesh->t_max_line; struct MeshData::TRI_POINT** t_min_line = mesh->t_min_line; for(i=0; i T2) both = true; double k1 = fabs(t0*k_max[f[0]] + t1*k_max[f[1]] + t2*k_max[f[2]]); double k2 = fabs(t0*k_min[f[0]] + t1*k_min[f[1]] + t2*k_min[f[2]]); if(both || k1 > k2){ f = face[t_max_line[i][0].id]; t1 = t_max_line[i][0].u; t2 = t_max_line[i][0].v; t0 = 1.0 - t1 - t2; float last_p[3]; last_p[0] = (float)(t0*x[f[0]][0] + t1*x[f[1]][0] + t2*x[f[2]][0]); last_p[1] = (float)(t0*x[f[0]][1] + t1*x[f[1]][1] + t2*x[f[2]][1]); last_p[2] = (float)(t0*x[f[0]][2] + t1*x[f[1]][2] + t2*x[f[2]][2]); for(int j=1; j k2){ if(t0*spe[f[0]] + t1*spe[f[1]] + t2*spe[f[2]] < T1){ draw = false; } } else{ if(t0*spe[f[0]] + t1*spe[f[1]] + t2*spe[f[2]] < T2) draw = false; } } else{ if(t0*spe[f[0]] + t1*spe[f[1]] + t2*spe[f[2]] < T1) draw = false; else if(fabs(t0*k_max[f[0]] + t1*k_max[f[1]] + t2*k_max[f[2]]) < fabs(t0*k_min[f[0]] + t1*k_min[f[1]] + t2*k_min[f[2]])) draw = false; } if(draw){ glBegin(GL_LINES); glVertex3fv(last_p); glVertex3fv(p); glEnd(); } last_p[0] = p[0]; last_p[1] = p[1]; last_p[2] = p[2]; } } if(both || k1 < k2){ f = face[t_min_line[i][0].id]; t1 = t_min_line[i][0].u; t2 = t_min_line[i][0].v; t0 = 1.0 - t1 - t2; float last_p[3]; last_p[0] = (float)(t0*x[f[0]][0] + t1*x[f[1]][0] + t2*x[f[2]][0]); last_p[1] = (float)(t0*x[f[0]][1] + t1*x[f[1]][1] + t2*x[f[2]][1]); last_p[2] = (float)(t0*x[f[0]][2] + t1*x[f[1]][2] + t2*x[f[2]][2]); for(int j=1; j fabs(t0*k_min[f[0]] + t1*k_min[f[1]] + t2*k_min[f[2]])) draw = false; } if(draw){ glBegin(GL_LINES); glVertex3fv(last_p); glVertex3fv(p); glEnd(); } last_p[0] = p[0]; last_p[1] = p[1]; last_p[2] = p[2]; } } } //glColor3f(1.0f, 1.0f, 1.0f); /* glColor3f(0.0f, 0.0f, 0.0f); MeshData::tri_point **ridge_line = mesh->ridge_line; int *ridge_line_N = mesh->ridge_line_N; int ridge_point_N = mesh->ridge_point_N; for(i=0; iravine_line; int *ravine_line_N = mesh->ravine_line_N; int ravine_point_N = mesh->ravine_point_N; for(i=0; ivertex_N; float (*normal)[3] = mesh->normal; double (*t_max)[3] = mesh->t_max; double (*t_min)[3] = mesh->t_min; double *k_max = mesh->k_max; double *k_min = mesh->k_min; float (*x)[3] = mesh->vertex; int (*face)[3] = mesh->face; int face_N = mesh->face_N; float *d = new float[vertex_N]; BOOL* is_hatch = mesh->is_hatch; glColor3f(0, 0, 0); glDisable(GL_LIGHTING); float R[3][3], R1[3][3], R2[3][3], R3[3][3], tmp[3][3], view[3]; GENERATE_MAT(R1, -(float)(PI*Rz/180.0f), vx); MAT_VEC(view, R1, vy); GENERATE_MAT(R2, -(float)(PI*Ry/180.0f), view); MAT_TIMES(tmp, R2, R1); MAT_VEC(view, tmp, vz); GENERATE_MAT(R3, -(float)(PI*Rx/180.0f), view); MAT_TIMES(R, R3, tmp); float eyei[3], eyef[3]; eyei[0] = (float)eye[0]; eyei[1] = (float)eye[1]; eyei[2] = (float)eye[2]; MAT_VEC(eyef, R, eyei); for(int i=0; isample_N; struct MeshData::TRI_POINT* sample_point = mesh->sample_point; int* t_max_line_N = mesh->t_max_line_N; int* t_min_line_N = mesh->t_min_line_N; struct MeshData::TRI_POINT** t_max_line = mesh->t_max_line; struct MeshData::TRI_POINT** t_min_line = mesh->t_min_line; for(i=0; i T2) is_cross = true; f = face[t_max_line[i][0].id]; t1 = t_max_line[i][0].u; t2 = t_max_line[i][0].v; t0 = 1.0 - t1 - t2; float last_p[3]; last_p[0] = (float)(t0*x[f[0]][0] + t1*x[f[1]][0] + t2*x[f[2]][0]); last_p[1] = (float)(t0*x[f[0]][1] + t1*x[f[1]][1] + t2*x[f[2]][1]); last_p[2] = (float)(t0*x[f[0]][2] + t1*x[f[1]][2] + t2*x[f[2]][2]); for(int j=1; j fabs(t0*k_min[f[0]] + t1*k_min[f[1]] + t2*k_min[f[2]])) draw = false; }*/ //else if(s1 < T1) //draw = false; if(s1 <= T2){ if(fabs(t0*k_max[f[0]] + t1*k_max[f[1]] + t2*k_max[f[2]]) > fabs(t0*k_min[f[0]] + t1*k_min[f[1]] + t2*k_min[f[2]])) draw = false; } if(draw){ glBegin(GL_LINES); glVertex3fv(last_p); glVertex3fv(p); glEnd(); } last_p[0] = p[0]; last_p[1] = p[1]; last_p[2] = p[2]; } } //glColor3f(1.0f, 1.0f, 1.0f); /* glColor3f(0.0f, 0.0f, 0.0f); MeshData::tri_point **ridge_line = mesh->ridge_line; int *ridge_line_N = mesh->ridge_line_N; int ridge_point_N = mesh->ridge_point_N; for(i=0; iravine_line; int *ravine_line_N = mesh->ravine_line_N; int ravine_point_N = mesh->ravine_point_N; for(i=0; ivertex_N; float (*vertex)[3] = mesh->vertex; float (*normal)[3] = mesh->normal; int (*face)[3] = mesh->face; int face_N = mesh->face_N; glDisable(GL_LIGHTING); glColor3f(0,0,0); //(0.4f, 0.2f, 0.2f); glBegin(GL_POINTS); for(int i=0; i 1) vv = 1; else if(v < 0) vv = 0; color[i][j][0] = vv; color[i][j][1] = vv; color[i][j][2] = vv; } } } void CMeshEditorView::drawColoredTriangle(MeshData *mesh, float (*v)[3], BOOL gray) { float (*vertex)[3] = mesh->vertex; int (*face)[3] = mesh->face; int face_N = mesh->face_N; int vertex_N = mesh->vertex_N; float (*color)[3] = new float[face_N][3]; if(gray) convertToColorG(face_N, v, color); else convertToColor(face_N, v, color); glShadeModel(GL_SMOOTH); glDisable(GL_LIGHTING); for(int i=0; iright; int sy = rect->bottom; delete rect; float oy = 2.0f*(float)(MeshData::DIST(eye, center)*PI*tan(view_angle/360.0)); float ox = oy*sx/sy; float lx = (x - sx/2)*ox/sx; float ly = (sy/2 - y)*oy/sy; float ex[3], ey[3], v[3]; for(int i=0; i<3; i++) v[i] = (float)(center[i] - eye[i]); ey[0] = -v[0] * v[2]; ey[1] = -v[1] * v[2]; ey[2] = v[0] * v[0] + v[1] * v[1]; double norm = ey[0] * ey[0] + ey[1] * ey[1] + ey[2] * ey[2]; norm = sqrt(norm); for(i=0; i<3; i++) ey[i] = (float)(ey[i] / norm); MeshData::CROSS(ex, v, ey); norm = MeshData::LENGTH(ex); ex[0] = (float)(ex[0]/norm); ex[1] = (float)(ex[1]/norm); ex[2] = (float)(ex[2]/norm); float ray_o[3]; ray_o[0] = lx*ex[0] + ly*ey[0]; ray_o[1] = lx*ex[1] + ly*ey[1]; ray_o[2] = lx*ex[2] + ly*ey[2]; float R[3][3], R1[3][3], R2[3][3], R3[3][3], tmp[3][3], view[3]; GENERATE_MAT(R1, -(float)(PI*Rz/180.0f), vx); MAT_VEC(view, R1, vy); GENERATE_MAT(R2, -(float)(PI*Ry/180.0f), view); MAT_TIMES(tmp, R2, R1); MAT_VEC(view, tmp, vz); GENERATE_MAT(R3, -(float)(PI*Rx/180.0f), view); MAT_TIMES(R, R3, tmp); MAT_VEC(ray, R, ray_o); float shift_o[] = {shift_x, shift_y, shift_z}; float shift[3]; MAT_VEC(shift, R, shift_o); ray[0] -= shift[0]; ray[1] -= shift[1]; ray[2] -= shift[2]; float start_o[3]; start_o[0] = (float)eye[0]; start_o[1] = (float)eye[1]; start_o[2] = (float)eye[2]; MAT_VEC(start, R, start_o); start[0] -= shift[0]; start[1] -= shift[1]; start[2] -= shift[2]; ray[0] = ray[0] - start[0]; ray[1] = ray[1] - start[1]; ray[2] = ray[2] - start[2]; double len = MeshData::LENGTH(ray); ray[0] = (float)(ray[0]/len); ray[1] = (float)(ray[1]/len); ray[2] = (float)(ray[2]/len); CMeshEditorDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); pDoc->selectTriangle(start, ray); /* CClientDC* dc = new CClientDC(this); OnDraw(dc); delete dc; */ CView::OnLButtonDblClk(nFlags, point); } void CMeshEditorView::drawPickedPoint() { glDisable(GL_LIGHTING); glColor3f(1.0f, 0.0f, 0.0f); glBegin(GL_POINTS); glVertex3fv(ray); glEnd(); glBegin(GL_LINES); glColor3f(1.0f, 0.0f, 0.0f); glVertex3fv(ray); glVertex3fv(start); glEnd(); glEnable(GL_LIGHTING); } void CMeshEditorView::drawGaussianSupport(MeshData *mesh) { glShadeModel(GL_SMOOTH); int face_N = mesh->face_N; int (*face)[3] = mesh->face; float (*normal_f)[3] = mesh->normal_f; float (*vertex)[3] = mesh->vertex; int *id = mesh->triangle_id; int (*link)[3] = mesh->face_link_E; float (*normal)[3] = mesh->normal; for(int i=0; i= 0) continue; glBegin(GL_POLYGON); glNormal3fv(normal_f[i]); glVertex3fv(vertex[face[i][0]]); glVertex3fv(vertex[face[i][1]]); glVertex3fv(vertex[face[i][2]]); glEnd(); } float d = (float)(0.05*view_angle/22.5); glDisable(GL_LIGHTING); for(i=0; i= 255.0f){ glEnable(GL_LIGHTING); glColor3f(0.5f, 0.5f, 0.5f); sphere(0.2f, mesh->center[i], 10); glDisable(GL_LIGHTING); //glBegin(GL_POINTS); //glVertex3fv(mesh->center[i]); //glEnd(); } int *l = link[i]; for(int j=0; j<3; j++){ if(l[j] < 0) continue; if(id[l[j]] >= 0) continue; float p1[3], p2[3]; int i1 = face[i][j]; int i2 = face[i][(j+1)%3]; p1[0] = vertex[i1][0] + d*normal[i1][0]; p1[1] = vertex[i1][1] + d*normal[i1][1]; p1[2] = vertex[i1][2] + d*normal[i1][2]; p2[0] = vertex[i2][0] + d*normal[i2][0]; p2[1] = vertex[i2][1] + d*normal[i2][1]; p2[2] = vertex[i2][2] + d*normal[i2][2]; glBegin(GL_LINES); glColor3f(0,0,0); glVertex3fv(p1); glVertex3fv(p2); glEnd(); } } glEnable(GL_LIGHTING); } void CMeshEditorView::drawScaleMap(MeshData *mesh, float *sigma) { glShadeModel(GL_SMOOTH); int face_N = mesh->face_N; int (*face)[3] = mesh->face; float (*vertex)[3] = mesh->vertex; glDisable(GL_LIGHTING); for(int i=0; iface_N; int (*face)[3] = mesh->face; float (*vertex)[3] = mesh->vertex; float (*normal)[3] = mesh->normal; float d = (float)(0.05*view_angle/22.5); float (*center)[3] = mesh->center; float (*normal_f)[3] = mesh->normal_f; glDisable(GL_LIGHTING); glColor3f(0,0,0); for(int i=0; iridge_L; RList* ravine = mesh->ravine_L; if(gray_scale) glColor3f(0,0,0); else glColor3f(1,0,0); for(RList* l=ridge; l->next!= NULL; l=l->next){ if(!l->vis) continue; glLineWidth(sqrt(l->k1*l->k2)); glBegin(GL_LINES); glVertex3fv(l->p1); glVertex3fv(l->p2); glEnd(); } if(gray_scale) glColor3f(1,1,1); else glColor3f(0,0,1); for(l=ravine; l->next!= NULL; l=l->next){ if(!l->vis) continue; glLineWidth(sqrt(l->k1*l->k2)); glBegin(GL_LINES); glVertex3fv(l->p1); glVertex3fv(l->p2); glEnd(); } if(!transparent){ glEnable(GL_LIGHTING); int vertex_N = mesh->vertex_N; float (*vertex)[3] = mesh->vertex; int face_N = mesh->face_N; int (*face)[3] = mesh->face; float (*normal)[3] = mesh->normal; /* if(gray_scale) glColor3f(0.7f, 0.7f, 0.7f); else glColor3f(0.9f,0.9f,0.9f); */ for(int i=0; inormal_f[i]); //glNormal3fv(normal[i1]); glVertex3fv(p1); //glNormal3fv(normal[i2]); glVertex3fv(p2); //glNormal3fv(normal[i3]); glVertex3fv(p3); glEnd(); } } } void CMeshEditorView::drawRidgeS(MeshData *mesh, BOOL transparent, BOOL gray_scale, float T_ridge, float T_ravine, float width) { glShadeModel(GL_SMOOTH); glDisable(GL_LIGHTING); RHead* ridge = mesh->ridge_S; RHead* ravine = mesh->ravine_S; if(gray_scale) glColor3f(1,1,1); else glColor3f(1,0,0); //glColor3f(0,0,0); for(RHead* l=ridge; l->next!= NULL; l=l->next){ if(l->strength < T_ridge) continue; for(REdge* e=l->head; e->next!=NULL; e=e->next){ float w = width*e->k; //if(w > 20.0f) // w = 20.0f; glLineWidth(w); //glLineWidth(width*e->k); //glBegin(GL_POINTS); glBegin(GL_LINES); glVertex3fv(e->p1); glVertex3fv(e->p2); glEnd(); } /* RPoint* p=l->head; do{ glLineWidth(0.5*sqrt(p->k*p->next->k)); glBegin(GL_LINES); glVertex3fv(p->p); glVertex3fv(p->next->p); glEnd(); p = p->next; }while(p->next != NULL && p != l->head);*/ } if(gray_scale) glColor3f(0,0,0); //glColor3f(0.5,0.5,0.5); //glColor3f(0.7,0.7,0.7); else glColor3f(0,0,1); //glColor3f(0,0,0); for(l=ravine; l->next!= NULL; l=l->next){ if(l->strength < T_ravine) continue; for(REdge* e=l->head; e->next!=NULL; e=e->next){ float w = -width*e->k; //if(w > 20.0f) // w = 20.0f; glLineWidth(w); //glBegin(GL_POINTS); glBegin(GL_LINES); glVertex3fv(e->p1); glVertex3fv(e->p2); glEnd(); } /* RPoint* p=l->head; do{ glLineWidth(0.5*sqrt(p->k*p->next->k)); glBegin(GL_LINES); glVertex3fv(p->p); glVertex3fv(p->next->p); glEnd(); p = p->next; }while(p->next != NULL && p != l->head);*/ } if(!transparent){ glEnable(GL_LIGHTING); int vertex_N = mesh->vertex_N; float (*vertex)[3] = mesh->vertex; int face_N = mesh->face_N; int (*face)[3] = mesh->face; float (*normal)[3] = mesh->normal; if(gray_scale) glColor3f(0.7f, 0.7f, 0.7f); else glColor3f(0.9f,0.9f,0.9f); //glColor3f(1,1,1); float d = (float)(0.05*view_angle/22.5); for(int i=0; inormal_f[i]); //glNormal3fv(normal[i1]); glVertex3fv(p1); //glNormal3fv(normal[i2]); glVertex3fv(p2); //glNormal3fv(normal[i3]); glVertex3fv(p3); glEnd(); } glEnable(GL_LIGHTING); } }