📄 dataview.cpp
字号:
/* Context : Graphic Display Utility Functions Author : Frank Hoeppner, see also AUTHORS file Description : implementation of class module DataView History : dataview.nw: 980702 fh: first version 980720 fh: changed display modes; DataView stores no more point/line lists any longer, display lists are now supported by generic_display 980722 fh: substituted individual Rectangle class with generic Box class 980909 fh: SCALE command moves focus into center of bounding box 980915 fh: explicit focussing button 981015 fh: additional, proportional scaling button (SP) 981105 fh: included set_focus Comment : This file was generated automatically. DO NOT EDIT. Copyright : Copyright (C) 1999-2000 Frank Hoeppner This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA*/#ifndef DataView_SOURCE#define DataView_SOURCE/* configuration include */#ifdef HAVE_CONFIG_H/*//FILETREE_IFDEF HAVE_CONFIG_H*/#include "config.h"/*//FILETREE_ENDIF*/#endif// necessary includes#include "DataView.hpp"// data#define DATAVIEW_CONTROL_MODES 5#define DATAVIEW_CONTROL_EYE 0#define DATAVIEW_CONTROL_FOCUS 1#define DATAVIEW_CONTROL_RED 2#define DATAVIEW_CONTROL_BLUE 3#define DATAVIEW_CONTROL_GREEN 4const float sensitivityMap[5] = { 0.01, 0.05, 0.1, 0.5, 1.0 };template <class DATA>DataView<DATA>* DataView<DATA>::p_DV;#define DATAVIEW_BUTTON_CONTROL_BASE 980#define DATAVIEW_BUTTON_MOMO 100#define DATAVIEW_BUTTON_SCALEFAC 1000#define DATAVIEW_BUTTON_SCALEFAC1 DATAVIEW_BUTTON_SCALEFAC+0#define DATAVIEW_BUTTON_SCALEFAC2 DATAVIEW_BUTTON_SCALEFAC+1#define DATAVIEW_BUTTON_SCALEFAC3 DATAVIEW_BUTTON_SCALEFAC+2#define DATAVIEW_BUTTON_SCALEFAC4 DATAVIEW_BUTTON_SCALEFAC+3#define DATAVIEW_BUTTON_SCALEFAC5 DATAVIEW_BUTTON_SCALEFAC+4#define DATAVIEW_BUTTON_BOUNDING_BOX 2000#define DATAVIEW_BUTTON_CENTER_FOCUS 2001#define DATAVIEW_BUTTON_DISPLAY_STATISTICS 2002#define DATAVIEW_BUTTON_SCALE_BB_4AXES 2010#define DATAVIEW_BUTTON_SCALE_BB_PROP 2011#define DATAVIEW_BUTTON_EXIT 9999const char DATAVIEW_ID[] = "DataView";// implementationtemplate <class DATA>DataView<DATA>::DataView ( ) : displayAppMenu(false) , displayDispMenu(false) , perspectiveView(true) , statisticsView(true) , estimateBoundBox(true) , controlMode(DATAVIEW_CONTROL_EYE) , mouse_button(DISPLAY_LEFT_BUTTON) , sensitivityGrade(2) , appButtonHandler(NULL) , appTimeHandler(NULL) , appDisplayFunc(NULL) , appExitHandler(NULL) { CONSTRUCTOR_LOG(DATAVIEW_ID,"DataView",this); int row; view_coord(DATAVIEW_AXIS_DISTANCE) = 5.0; view_coord(DATAVIEW_AXIS_ELEVATION) = 0.0; view_coord(DATAVIEW_AXIS_TWIST) = 0.0; view_coord(DATAVIEW_AXIS_AZIMUTH) = 0.0; focus_coord(DATAVIEW_AXIS_X) = 0.0; focus_coord(DATAVIEW_AXIS_Y) = 0.0; focus_coord(DATAVIEW_AXIS_Z) = 0.0; focus_coord(DATAVIEW_AXIS_T) = 0.0; for (row=0;row<4;++row) { scalefac(row)=1.0; scaletext[row][0]=scaletext[row][DISPLAY_SCALE_OUTPUT_LENGTH]='\0'; ostrstream output(scaletext[row],DISPLAY_SCALE_OUTPUT_LENGTH,ios::trunc); output << scalefac(row) << '\0'; } { DATA dummy; data_size = dummy.rows(); } for (row=0;row<4;++row) { red_coord(row)=0.0; blue_coord(row)=0.0; green_coord(row)=0.0; } red_coord(0)=1.0; green_coord(1)=1.0; blue_coord(2)=1.0; cart_coord = &focus_coord; for (row=0;row<4;++row) { axis[row]= (row<data_size) ? row : -1; cartesian[row] = row; rotate[row] = row; } sensitivity = sensitivityMap[sensitivityGrade]; }template <class DATA>DataView<DATA>::~DataView ( ) { DESTRUCTOR_LOG(DATAVIEW_ID,"DataView",this); }template <class DATA>void DataView<DATA>::Menu::add ( const DataView<DATA>::Button& a_button ) { m_buttons[a_button.idno] = a_button; m_bbox.include(a_button.area); }template <class DATA>intDataView<DATA>::Menu::evaluate_click ( int x, int y ) { MenuCoord coord(x,y); ButtonMap::iterator i_button; for (i_button=m_buttons.begin();i_button!=m_buttons.end();++i_button) { if ((*i_button).second.area.encloses(coord)) { switch ((*i_button).second.state) { case ButtonPassive : break; case ButtonOn : (*i_button).second.state = ButtonOff; break; case ButtonOff : (*i_button).second.state = ButtonOn; break; } return (*i_button).first; } } return -1; }template <class DATA>void DataView<DATA>::Menu::display ( int& x, int& y ) { { int w = get_window_width(); int h = get_window_height(); if (x+m_bbox.RIGHT > w) x = w - m_bbox.RIGHT; if (y+m_bbox.BOTTOM > h) y = h - m_bbox.BOTTOM; } display_mode_menu(); display_color(0.5,0.5,0.5,0.5); display_rect ( x+m_bbox.LEFT-DATAVIEW_MENUFRAME, y+m_bbox.TOP-DATAVIEW_MENUFRAME, x+m_bbox.RIGHT+DATAVIEW_MENUFRAME, y+m_bbox.BOTTOM+DATAVIEW_MENUFRAME, true ); ButtonMap::iterator i_button; for (i_button=m_buttons.begin();i_button!=m_buttons.end();++i_button) { if ((*i_button).second.state==ButtonOn) { display_color(0.8,0.0,0.0,0.6); } else { display_color(1.0,1.0,1.0,0.6); } if ((*i_button).second.state!=ButtonPassive) { display_rect ( x+(*i_button).second.area.LEFT+DATAVIEW_MENUSPACE, y+(*i_button).second.area.TOP+DATAVIEW_MENUSPACE, x+(*i_button).second.area.RIGHT-DATAVIEW_MENUSPACE, y+(*i_button).second.area.BOTTOM-DATAVIEW_MENUSPACE, (*i_button).second.state==ButtonOn ); display_color(COLOR_WHITE); display_text ( x+(*i_button).second.area.LEFT+DATAVIEW_MENUSPACE+DATAVIEW_TEXTSPACE, y+(*i_button).second.area.BOTTOM-DATAVIEW_MENUSPACE-DATAVIEW_TEXTSPACE, 0, (*i_button).second.title, ((*i_button).second.area.RIGHT-(*i_button).second.area.LEFT)/10 ); } else { display_color(COLOR_WHITE); display_text ( x+(*i_button).second.area.LEFT+DATAVIEW_TEXTSPACE, y+(*i_button).second.area.BOTTOM-DATAVIEW_MENUSPACE-DATAVIEW_TEXTSPACE, 0, (*i_button).second.title, ((*i_button).second.area.RIGHT-(*i_button).second.area.LEFT)/10 ); } } }template <class DATA>void DataView<DATA>::display_point ( const DATA& a_start, float a_radius ) { DispCoord scoord; convert_coord(a_start,scoord); display_point_intern(scoord,a_radius); if (estimateBoundBox) { boundBox.include(scoord); } }template <class DATA>void DataView<DATA>::display_disc ( const DATA& a_start, float a_radius ) { DispCoord scoord; convert_coord(a_start,scoord); ::display_disc ( scoord(DATAVIEW_AXIS_X),scoord(DATAVIEW_AXIS_Y),scoord(DATAVIEW_AXIS_Z), a_radius ); if (estimateBoundBox) { boundBox.include(scoord); } }template <class DATA>void DataView<DATA>::display_ball ( const DATA& a_start, float a_radius ) { DispCoord scoord; convert_coord(a_start,scoord); ::display_ball ( scoord(DATAVIEW_AXIS_X),scoord(DATAVIEW_AXIS_Y),scoord(DATAVIEW_AXIS_Z), a_radius ); if (estimateBoundBox) { boundBox.include(scoord); } }template <class DATA>void DataView<DATA>::display_line ( const DATA& a_start, const DATA& a_final, float a_radius ) { DispCoord scoord; DispCoord fcoord; convert_coord(a_start,scoord); convert_coord(a_final,fcoord); display_line_intern(scoord,fcoord,a_radius); if (estimateBoundBox) { boundBox.include(scoord); boundBox.include(fcoord); } }template <class DATA>void DataView<DATA>::display_cylinder ( const DATA& a_start, const DATA& a_final, float a_radius ) { DispCoord scoord; DispCoord fcoord; convert_coord(a_start,scoord); convert_coord(a_final,fcoord); ::display_cylinder ( scoord(DATAVIEW_AXIS_X), scoord(DATAVIEW_AXIS_Y), scoord(DATAVIEW_AXIS_Z), fcoord(DATAVIEW_AXIS_X), fcoord(DATAVIEW_AXIS_Y), fcoord(DATAVIEW_AXIS_Z), a_radius ); if (estimateBoundBox) { boundBox.include(scoord); boundBox.include(fcoord); } }template <class DATA>void DataView<DATA>::notify_size ( const DATA& a_start ) { if (data_size > a_start.rows()) { for (int row=a_start.rows();row<data_size;++row) { axis[row]= -1; } } data_size = a_start.rows(); }template <class DATA>void DataView<DATA>::registrate_button ( int x, int y, int dx, int dy, const char* title, ButtonState s, int no ) { appMenu.add( Button(x,y,dx,dy,title,s,no) ); }template <class DATA>void DataView<DATA>::registrate_button_handler ( void (*f)(int) ) { appButtonHandler = f; }template <class DATA>void DataView<DATA>::registrate_exit_handler ( void (*f)() ) { appExitHandler = f; }template <class DATA>void DataView<DATA>::registrate_display_func ( void (*f)() ) { appDisplayFunc = f; }template <class DATA>void DataView<DATA>::registrate_time_handler ( void (*f)(float) ) { appTimeHandler = f; }template <class DATA>ButtonState& DataView<DATA>::application_button_state ( int button ) { return appMenu.m_buttons[button].state; }template <class DATA>void DataView<DATA>::statistics ( ) { int h = get_window_height(); char buffer[100]; ostrstream coord(buffer,100); // menu display in 2D ortho view and with alphablending display_mode_menu(); display_color(0.7,0.7,0.7,0.6); //coord << setprecision(5); for (int i = DATAVIEW_AXIS_X; i<=DATAVIEW_AXIS_T; ++i) { float x = (*cart_coord)(i) / scalefac(i); if (ZERO(x)) x=0.0; coord << x << " "; } coord << '\0'; display_text(2,h-1,0,buffer); }template <class DATA>void DataView<DATA>::mouse_move ( int x, int y ) { float oldTime( focus_coord(DATAVIEW_AXIS_T) ); int dx = x_mouse_move-x; int dy = y_mouse_move-y; if (controlMode == DATAVIEW_CONTROL_EYE) // change view parameter { if (mouse_button==DISPLAY_LEFT_BUTTON) { if (rotate[0]>=0) view_coord(rotate[0]) += sensitivity*dx; if (rotate[1]>=0) view_coord(rotate[1]) += sensitivity*dy; } else if (mouse_button==DISPLAY_RIGHT_BUTTON) { if (rotate[2]>=0) view_coord(rotate[2]) += sensitivity*dx; if (rotate[3]>=0) view_coord(rotate[3]) += sensitivity*dy; } } else // change cartesian parameter { float sign = (controlMode == DATAVIEW_CONTROL_EYE) ? 1.0 : -1.0; if (mouse_button==DISPLAY_LEFT_BUTTON) { if (cartesian[0]>=0) (*cart_coord)(cartesian[0]) += sign*sensitivity*dx; if (cartesian[1]>=0) (*cart_coord)(cartesian[1]) -= sign*sensitivity*dy; } else if (mouse_button==DISPLAY_RIGHT_BUTTON) { if (cartesian[2]>=0) (*cart_coord)(cartesian[2]) += sign*sensitivity*dx; if (cartesian[3]>=0) (*cart_coord)(cartesian[3]) += sign*sensitivity*dy; } } if (focus_coord(DATAVIEW_AXIS_T) != oldTime) { if (appTimeHandler!=NULL) { appTimeHandler(focus_coord(DATAVIEW_AXIS_T)/scalefac(DATAVIEW_AXIS_T)); } } display_again();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -