├── .gitignore ├── CMakeLists.txt ├── README.md ├── cmake_config ├── qt_support.cmake └── utility.cmake └── src ├── CMakeLists.txt ├── cetest ├── cetest.cpp ├── cetest.h ├── cetest.qrc ├── cetest.ui └── main.cpp ├── curveeditor ├── GlobalData.cpp ├── GlobalData.h ├── SplineDisplayerWidget.cpp ├── SplineDisplayerWidget.h ├── graphiceditor.cpp ├── graphiceditor.h └── graphiceditor.ui └── libspline ├── aaCurve.cpp ├── aaCurve.h ├── spline.cpp └── spline.h /.gitignore: -------------------------------------------------------------------------------- 1 | *.DS_Store 2 | *.Thumbs.db 3 | .tmproj 4 | /.settings/ 5 | build 6 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8.12) 2 | 3 | set(MY_PROJECT_NAME qtCurveEditor) 4 | PROJECT(${MY_PROJECT_NAME}) 5 | 6 | set(MY_CMAKE_CONFIG ${CMAKE_CURRENT_SOURCE_DIR}/cmake_config) 7 | 8 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${MY_CMAKE_CONFIG}) 9 | include(utility) 10 | 11 | # find opengl and directx 12 | find_package(OpenGL) 13 | if(OPENGL_FOUND) 14 | message("OPENGL FOUND\n${OPENGL_INCLUDE_DIR}\n" ) 15 | else(OPENGL_FOUND) 16 | # create project failed 17 | message(FATAL_ERROR "OPENGL NOT FOUND") 18 | endif(OPENGL_FOUND) 19 | 20 | ########### Find QT5 packages ########### 21 | FIND_PACKAGE(Qt5Core REQUIRED) 22 | FIND_PACKAGE(Qt5Gui REQUIRED) 23 | FIND_PACKAGE(Qt5OpenGL REQUIRED) 24 | FIND_PACKAGE(Qt5Widgets REQUIRED) 25 | 26 | # Tell CMake to run moc when necessary: 27 | set(CMAKE_AUTOMOC ON) 28 | # As moc files are generated in the binary dir, tell CMake to always look for includes there: 29 | set(CMAKE_INCLUDE_CURRENT_DIR ON) 30 | 31 | #enable all warnings 32 | add_definitions(-Wall) 33 | 34 | add_subdirectory(src) 35 | 36 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Qt Curve Editor 2 | === 3 | A Qt OpenGL Widget for curve editing. The spline library is from 4 | [http://people.sc.fsu.edu/~jburkardt/c_src/spline/spline.html](http://people.sc.fsu.edu/~jburkardt/c_src/spline/spline.html). 5 | 6 | [![Qt Curve Editor](http://www.shannap.com/upload/2013/06/qt-curve-editor.jpg)](http://www.shannap.com/upload/2013/06/qt-curve-editor.jpg) 7 | 8 | ***Build*** 9 | 10 | You should have installed [cmake](http://www.cmake.org/) and [Qt](http://qt-project.org/), then use the following commands. 11 | 12 | ``` 13 | mkdir build 14 | cd build 15 | cmake -G Xcode .. 16 | ``` 17 | 18 | (for other compilers, please change the [cmake generator](http://www.cmake.org/cmake/help/v2.8.11/cmake.html#section_Generators)) 19 | -------------------------------------------------------------------------------- /cmake_config/qt_support.cmake: -------------------------------------------------------------------------------- 1 | include(FindQt4) 2 | 3 | # --------------------------------------------------------------------------- # 4 | # Qt support 5 | macro(compileWithQt) 6 | #find_package(Qt4 COMPONENTS QtCore QtGui QtOpenGL QtSql QtSvg Phonon REQUIRED) 7 | find_package(Qt4 REQUIRED) 8 | set(QT_USE_QTOPENGL 1) 9 | #set(QT_USE_QTSQL 1) 10 | #set(QT_USE_QTSVG 1) 11 | #set(QT_USE_PHONON 1) 12 | include(${QT_USE_FILE}) 13 | endmacro(compileWithQt) 14 | 15 | macro(doQtClassMOC sourceFileList moc_files_var) 16 | set(do_qt_moc_macro_files_to_moc) 17 | filterFilesContain(".*Q_OBJECT.*" do_qt_moc_macro_files_to_moc ${sourceFileList}) 18 | QT4_WRAP_CPP(${moc_files_var} ${do_qt_moc_macro_files_to_moc}) 19 | source_group("Qt Class MOC Generated" FILES ${${moc_files_var}}) 20 | endmacro(doQtClassMOC) 21 | 22 | macro(linkWithQt projectName) 23 | target_link_libraries(${projectName} ${QT_LIBRARIES}) 24 | endmacro(linkWithQt) 25 | 26 | macro(doQtUiMoc uiFileList moc_files_var) 27 | QT4_WRAP_UI(${moc_files_var} ${${uiFileList}}) 28 | source_group("Qt UI MOC Generated" FILES ${${moc_files_var}}) 29 | endmacro(doQtUiMoc) 30 | 31 | macro(addQtResources uiFileList res_file_var) 32 | QT4_ADD_RESOURCES(${res_file_var} ${${uiFileList}}) 33 | source_group("Qt Resources" FILES ${${res_files_var}}) 34 | endmacro(addQtResources) 35 | -------------------------------------------------------------------------------- /cmake_config/utility.cmake: -------------------------------------------------------------------------------- 1 | macro(source_group_by_dir source_files) 2 | set(sgbd_cur_dir ${CMAKE_CURRENT_SOURCE_DIR}) 3 | foreach(sgbd_file ${${source_files}}) 4 | string(REGEX REPLACE ${sgbd_cur_dir}/\(.*\) \\1 sgbd_fpath ${sgbd_file}) 5 | string(REGEX REPLACE "\(.*\)/.*" \\1 sgbd_group_name ${sgbd_fpath}) 6 | string(COMPARE EQUAL ${sgbd_fpath} ${sgbd_group_name} sgbd_nogroup) 7 | string(REPLACE "/" "\\" sgbd_group_name ${sgbd_group_name}) 8 | if(sgbd_nogroup) 9 | set(sgbd_group_name "\\") 10 | endif(sgbd_nogroup) 11 | source_group(${sgbd_group_name} FILES ${sgbd_file}) 12 | endforeach(sgbd_file) 13 | endmacro(source_group_by_dir) 14 | 15 | # parse files 16 | macro(filterFilesContain pattern out_var in_var) 17 | set(${out_var}) 18 | foreach(file_name ${${in_var}}) 19 | set(z_filter_file_contain_content) 20 | file(READ ${file_name} z_filter_file_contain_content) 21 | if(z_filter_file_contain_content MATCHES ${pattern}) 22 | list(APPEND ${out_var} ${file_name}) 23 | endif(z_filter_file_contain_content MATCHES ${pattern}) 24 | endforeach(file_name) 25 | endmacro(filterFilesContain) 26 | 27 | # Copy files from source directory to destination directory, substituting any 28 | # variables. Create destination directory if it does not exist. 29 | 30 | macro(copyDirectory srcDir destDir) 31 | message(STATUS "Configuring directory ${destDir}") 32 | file(MAKE_DIRECTORY ${destDir}) 33 | 34 | file(GLOB templateFiles RELATIVE ${srcDir} *.*) 35 | foreach(templateFile ${templateFiles}) 36 | set(srcTemplatePath ${srcDir}/${templateFile}) 37 | if(NOT IS_DIRECTORY ${srcTemplatePath}) 38 | message(STATUS "Configuring file ${templateFile}") 39 | configure_file( 40 | ${srcTemplatePath} 41 | ${destDir}/${templateFile} 42 | copyonly) 43 | endif(NOT IS_DIRECTORY ${srcTemplatePath}) 44 | endforeach(templateFile) 45 | endmacro(copyDirectory) 46 | 47 | -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include_directories(${CMAKE_CURRENT_BINARY_DIR}) 2 | 3 | set(headers) 4 | set(cpps) 5 | set(uis) 6 | set(qtmocs) 7 | set(qtuimocs) 8 | 9 | file(GLOB_RECURSE headers *.h) 10 | file(GLOB_RECURSE cpps *.cpp) 11 | file(GLOB_RECURSE uis *.ui) 12 | 13 | set(sources ${headers} ${cpps}) 14 | source_group_by_dir(sources) 15 | 16 | #qt5_wrap_cpp(qtmocs ${headers}) 17 | qt5_wrap_ui(qtuimocs ${uis}) 18 | 19 | add_executable(${MY_PROJECT_NAME} ${sources} ${qtuimocs}) 20 | target_link_libraries(${MY_PROJECT_NAME} ${OPENGL_LIBRARIES}) 21 | QT5_USE_MODULES(${MY_PROJECT_NAME} Core Gui OpenGL Widgets) 22 | 23 | -------------------------------------------------------------------------------- /src/cetest/cetest.cpp: -------------------------------------------------------------------------------- 1 | #include "cetest.h" 2 | #include "../curveeditor/graphiceditor.h" 3 | #include "../libspline/aaCurve.h" 4 | #include 5 | #include 6 | 7 | cetest::cetest(QWidget *parent, Qt::WindowFlags flags) 8 | : QMainWindow(parent, flags), ge(0) 9 | { 10 | ui.setupUi(this); 11 | 12 | connect(ui.pushButton_showGe, SIGNAL(clicked()), this, SLOT(onShowGeClicked())); 13 | } 14 | 15 | cetest::~cetest() 16 | { 17 | if(ge) 18 | delete ge; 19 | } 20 | 21 | void cetest::onShowGeClicked(void) 22 | { 23 | if(!ge) 24 | { 25 | std::vector splines; 26 | 27 | aaAaa::aaSpline spline; 28 | spline.addKnots(aaAaa::aaPoint(0, 0)); 29 | spline.addKnots(aaAaa::aaPoint(128, 150)); 30 | spline.addKnots(aaAaa::aaPoint(255, 255)); 31 | 32 | spline.name = "R"; 33 | splines.push_back(spline); 34 | 35 | spline.name = "G"; 36 | spline.setLimit(0, 255, 255, 0); 37 | splines.push_back(spline); 38 | 39 | ge = new graphiceditor(); 40 | ge->setSplines(splines); 41 | } 42 | ge->show(); 43 | } -------------------------------------------------------------------------------- /src/cetest/cetest.h: -------------------------------------------------------------------------------- 1 | #ifndef CETEST_H 2 | #define CETEST_H 3 | 4 | #include 5 | #include "ui_cetest.h" 6 | 7 | #include 8 | #include 9 | 10 | 11 | class graphiceditor; 12 | 13 | class cetest : public QMainWindow 14 | { 15 | Q_OBJECT 16 | 17 | public: 18 | cetest(QWidget *parent = 0, Qt::WindowFlags flags = 0); 19 | ~cetest(); 20 | 21 | private: 22 | Ui::cetestClass ui; 23 | 24 | graphiceditor *ge; 25 | 26 | 27 | protected slots: 28 | void onShowGeClicked(void); 29 | }; 30 | 31 | #endif // CETEST_H 32 | -------------------------------------------------------------------------------- /src/cetest/cetest.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /src/cetest/cetest.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | cetestClass 4 | 5 | 6 | 7 | 0 8 | 0 9 | 600 10 | 400 11 | 12 | 13 | 14 | cetest 15 | 16 | 17 | 18 | 19 | 20 | 160 21 | 110 22 | 161 23 | 23 24 | 25 | 26 | 27 | Show Curve Editor 28 | 29 | 30 | 31 | 32 | 33 | 34 | 0 35 | 0 36 | 600 37 | 22 38 | 39 | 40 | 41 | 42 | 43 | TopToolBarArea 44 | 45 | 46 | false 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /src/cetest/main.cpp: -------------------------------------------------------------------------------- 1 | #include "cetest.h" 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QApplication a(argc, argv); 7 | cetest w; 8 | w.show(); 9 | return a.exec(); 10 | } 11 | -------------------------------------------------------------------------------- /src/curveeditor/GlobalData.cpp: -------------------------------------------------------------------------------- 1 | #include "GlobalData.h" 2 | #include "graphiceditor.h" 3 | #include 4 | 5 | GlobalData::GlobalData(){ 6 | 7 | QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF8")); 8 | /* 9 | QTextCodec *codec = QTextCodec::codecForName("System"); 10 | QTextCodec::setCodecForTr(codec); 11 | QTextCodec::setCodecForLocale(codec); 12 | QTextCodec::setCodecForCStrings(codec);*/ 13 | } 14 | 15 | void GlobalData::addGe(graphiceditor *ge){ 16 | m_setGe.insert(ge); 17 | } 18 | 19 | void GlobalData::rmGe(graphiceditor *ge){ 20 | m_setGe.erase(ge); 21 | } 22 | 23 | void GlobalData::clear(unsigned int handle){ 24 | GeSet::iterator it = m_setGe.find((graphiceditor*)handle); 25 | if(it == m_setGe.end()){ 26 | return ; 27 | } 28 | (*it)->clearSplines(); 29 | } 30 | 31 | /* 32 | void GlobalData::addSpline(const std::string &name, const std::vector > &knot){ 33 | for(int i=0; iaddSpline(knot); 53 | } 54 | 55 | bool GlobalData::getSplines(unsigned int handle, std::vector &splines){ 56 | GeSet::const_iterator it = m_setGe.find((graphiceditor*)handle); 57 | if(it == m_setGe.end()){ 58 | return false; 59 | } 60 | splines = (*it)->getSplines(); 61 | return true; 62 | } 63 | 64 | int GlobalData::getCurrentSplineIndex(unsigned int handle){ 65 | GeSet::const_iterator it = m_setGe.find((graphiceditor*)handle); 66 | if(it == m_setGe.end()){ 67 | return -1; 68 | } 69 | return (*it)->getCurrentSplineIndex(); 70 | } 71 | 72 | void GlobalData::setSplines(unsigned int handle, const std::vector &splines){ 73 | GeSet::const_iterator it = m_setGe.find((graphiceditor*)handle); 74 | if(it == m_setGe.end()){ 75 | return ; 76 | } 77 | 78 | (*it)->setSplines(splines); 79 | } 80 | 81 | void GlobalData::addKnot(unsigned int handle, int index, const aaAaa::aaPoint &pt){ 82 | GeSet::const_iterator it = m_setGe.find((graphiceditor*)handle); 83 | if(it == m_setGe.end()){ 84 | return ; 85 | } 86 | 87 | (*it)->addKnot(index, pt); 88 | } 89 | 90 | void GlobalData::addKnot(unsigned int handle, int index, float t){ 91 | GeSet::const_iterator it = m_setGe.find((graphiceditor*)handle); 92 | if(it == m_setGe.end()){ 93 | return ; 94 | } 95 | 96 | (*it)->addKnot(index, t); 97 | } 98 | 99 | /* 100 | void GlobalData::setSplineLimit(const std::string &name, float left, float top, float right, float bottom){ 101 | for(int i=0; i 6 | 7 | 8 | class graphiceditor; 9 | 10 | class GlobalData{ 11 | private: 12 | GlobalData(); 13 | GlobalData(const GlobalData &gd); 14 | 15 | public: 16 | typedef std::set GeSet; 17 | GeSet m_setGe; 18 | 19 | public: 20 | ~GlobalData(){} 21 | 22 | static GlobalData &instance(void){ 23 | static GlobalData gd; 24 | return gd; 25 | } 26 | 27 | void addGe(graphiceditor *ge); 28 | void rmGe(graphiceditor *ge); 29 | 30 | void clear(unsigned int handle); 31 | 32 | // void addSpline(unsigned int handle, const std::string &name, const std::vector > &knot); 33 | void addSpline(unsigned int handle, const aaAaa::aaSpline &knot); 34 | // void setSplineLimit(const std::string &name, float left, float top, float right, float bottom); 35 | bool getSplines(unsigned int handle, std::vector &splines); 36 | void setSplines(unsigned int handle, const std::vector &splines); 37 | 38 | int getCurrentSplineIndex(unsigned int handle); 39 | 40 | void addKnot(unsigned int handle, int index, const aaAaa::aaPoint &pt); 41 | void addKnot(unsigned int handle, int index, float t); 42 | 43 | }; 44 | 45 | #endif // __GLOBALDATA_H__ 46 | 47 | -------------------------------------------------------------------------------- /src/curveeditor/SplineDisplayerWidget.cpp: -------------------------------------------------------------------------------- 1 | #include "SplineDisplayerWidget.h" 2 | #include "../libspline/aaCurve.h" 3 | 4 | #if defined(__APPLE_CC__) || defined(_APPLE_CC) 5 | #include 6 | #else 7 | #include 8 | #endif 9 | 10 | #include 11 | 12 | float const SplineDisplayerWidget::MY_PI = 3.1415926f; 13 | 14 | SplineDisplayerWidget::SplineDisplayerWidget(double deltaT, QWidget *parent /* = 0 */) 15 | : QGLWidget(parent), m_axis(0), lastPos(0, 0), 16 | ctrlSelected(-1), m_bIfModify(false), m_spline_data(0), 17 | m_deltaT(deltaT){ 18 | 19 | m_CameraPos = aaAaa::Vector3(122, 122, 127); 20 | 21 | setFocusPolicy(Qt::ClickFocus); 22 | } 23 | 24 | SplineDisplayerWidget::~SplineDisplayerWidget(void){ 25 | 26 | } 27 | 28 | void SplineDisplayerWidget::setAE(aaAaa::aaSpline *sdata){ 29 | m_spline_data = sdata; 30 | ctrlSelected = -1; 31 | updateGL(); 32 | emit selectValuesChanged(0, 0); 33 | } 34 | 35 | 36 | //void SplineDisplayerWidget::paintEvent(QPaintEvent *event){ 37 | // QPainter painter(this); 38 | // painter.setRenderHint(QPainter::Antialiasing, true); 39 | // painter.setPen(QPen(Qt::black, 12, Qt::DashDotLine, Qt::RoundCap)); 40 | // painter.setBrush(QBrush(Qt::green, Qt::SolidPattern)); 41 | // painter.drawEllipse(80, 80, 400, 240); 42 | 43 | //} 44 | void SplineDisplayerWidget::drawGrid(void){ 45 | double distance = m_CameraPos.z - Z_VALUE; 46 | //double halfwidth = distance; 47 | //double halfheight = halfwidth /** (double(this->width()) / double(this->height()))*/; 48 | 49 | if(distance > 300) 50 | distance = 80; 51 | else if(distance > 220) 52 | distance = 40; 53 | else if(distance > 80) 54 | distance = 20; 55 | else 56 | distance = 10; 57 | 58 | glColor3f(0, 0, 0); 59 | // draw axies 60 | glLineWidth(1.5); 61 | glBegin(GL_LINES); 62 | glVertex3f(-1000, 0, Z_VALUE); 63 | glVertex3f(1000, 0, Z_VALUE); 64 | 65 | glVertex3f(0, -1000, Z_VALUE); 66 | glVertex3f(0, 1000, Z_VALUE); 67 | glEnd(); 68 | 69 | aaAaa::Vector2 lt = screen2gl(1, 0); 70 | aaAaa::Vector2 rb = screen2gl(m_width, m_height-1); 71 | 72 | double val = 0; 73 | glColor3f(0.5f, 0.5f, 0.5f); 74 | glLineWidth(0.01); 75 | glBegin(GL_LINES); 76 | val = distance * Y_FACTOR; 77 | while(val <= lt.y){ 78 | glVertex3f(-1000, val, Z_VALUE); 79 | glVertex3f(1000, val, Z_VALUE); 80 | val += distance * Y_FACTOR; 81 | 82 | } 83 | val = -distance * Y_FACTOR; 84 | while(val >= rb.y){ 85 | glVertex3f(-1000, val, Z_VALUE); 86 | glVertex3f(1000, val, Z_VALUE); 87 | val -= distance * Y_FACTOR; 88 | } 89 | 90 | val = distance; 91 | while(val <= rb.t){ 92 | glVertex3f(val, -1000, Z_VALUE); 93 | glVertex3f(val, 1000, Z_VALUE); 94 | val += distance; 95 | } 96 | 97 | val = -distance; 98 | while(val >= lt.t){ 99 | glVertex3f(val, -1000, Z_VALUE); 100 | glVertex3f(val, 1000, Z_VALUE); 101 | val -= distance; 102 | } 103 | glEnd(); 104 | 105 | 106 | glColor3f(0.0f, 0.0f, 0.0f); 107 | 108 | renderText(lt.t, 0, Z_VALUE, "0"); 109 | val = distance * Y_FACTOR; 110 | while(val <= lt.y){ 111 | renderText(lt.t, val, Z_VALUE, QString("%1").arg(val)); 112 | val += distance * Y_FACTOR; 113 | } 114 | val = -distance * Y_FACTOR; 115 | while(val >= rb.y){ 116 | renderText(lt.t, val, Z_VALUE, QString("%1").arg(val)); 117 | val -= distance * Y_FACTOR; 118 | } 119 | 120 | renderText(0, rb.y, Z_VALUE, "0"); 121 | val = distance; 122 | while(val <= rb.t){ 123 | renderText(val, rb.y, Z_VALUE, QString("%1").arg(val)); 124 | val += distance; 125 | } 126 | 127 | val = -distance; 128 | while(val >= lt.t){ 129 | renderText(val, rb.y, Z_VALUE, QString("%1").arg(val)); 130 | val -= distance; 131 | } 132 | 133 | 134 | } 135 | 136 | 137 | void SplineDisplayerWidget::drawSpline(void){ 138 | 139 | if(!m_spline_data) 140 | return ; 141 | aaAaa::aaSpline &m_spline_data = *(this->m_spline_data); 142 | 143 | aaAaa::aaCurvePtr pspline; 144 | if(m_spline_data.size() <= 1){ 145 | return ; 146 | }else{ 147 | pspline = aaAaa::aaCurveFactory::createCurve(m_spline_data); 148 | if(!pspline.get()) 149 | return ; 150 | 151 | } 152 | 153 | if(m_spline_data.bLimited){ 154 | glColor3f(1.0f, 0.0f, 0.0f); 155 | glBegin(GL_LINE_STRIP); 156 | glVertex3f(m_spline_data.limit_left, m_spline_data.limit_bottom * Y_FACTOR, Z_VALUE); 157 | glVertex3f(m_spline_data.limit_left, m_spline_data.limit_top * Y_FACTOR, Z_VALUE); 158 | glVertex3f(m_spline_data.limit_right, m_spline_data.limit_top * Y_FACTOR, Z_VALUE); 159 | glVertex3f(m_spline_data.limit_right, m_spline_data.limit_bottom * Y_FACTOR, Z_VALUE); 160 | glVertex3f(m_spline_data.limit_left, m_spline_data.limit_bottom * Y_FACTOR, Z_VALUE); 161 | glEnd(); 162 | } 163 | 164 | 165 | glColor3f(0.0f, 1.0f, 0.0f); 166 | glBegin(GL_POINTS); 167 | aaAaa::aaSpline::KnotsList::iterator cit = m_spline_data.knots.begin(); 168 | aaAaa::aaSpline::KnotsList::iterator cend = m_spline_data.knots.end(); 169 | for(; cit!=cend; ++cit){ 170 | glVertex3f((*cit).t, (*cit).y * Y_FACTOR, Z_VALUE); 171 | } 172 | glEnd(); 173 | 174 | if(ctrlSelected >= 0 && ctrlSelected < m_spline_data.knots.size()){ 175 | glColor3f(1.0f, 1.0f, 0.0f); 176 | glBegin(GL_POINTS); 177 | glVertex3f(m_spline_data.knots[ctrlSelected].t, m_spline_data.knots[ctrlSelected].y * Y_FACTOR, Z_VALUE); 178 | glEnd(); 179 | } 180 | 181 | glColor3f(1.0f, 0.0f, 1.0f); 182 | glBegin(GL_LINE_STRIP); 183 | 184 | aaAaa::aaSpline::KnotsList::iterator beg = m_spline_data.knots.begin(); 185 | aaAaa::aaSpline::KnotsList::reverse_iterator rbeg = m_spline_data.knots.rbegin(); 186 | 187 | double t = (*beg).t; 188 | double v = (*beg).y; 189 | glVertex3f(t, v * Y_FACTOR, Z_VALUE); 190 | t += m_deltaT; 191 | 192 | while(t < (*rbeg).t - m_deltaT){ 193 | pspline->getValue(t, v); 194 | if(m_spline_data.bLimited){ 195 | if(v > m_spline_data.limit_top) 196 | v = m_spline_data.limit_top; 197 | else if(v < m_spline_data.limit_bottom) 198 | v = m_spline_data.limit_bottom; 199 | } 200 | glVertex3f(t, v * Y_FACTOR, Z_VALUE); 201 | t += m_deltaT; 202 | } 203 | 204 | t = (*rbeg).t; 205 | v = (*rbeg).y; 206 | glVertex3f(t, v * Y_FACTOR, Z_VALUE); 207 | 208 | glEnd(); 209 | 210 | 211 | } 212 | 213 | void SplineDisplayerWidget::initializeGL() 214 | { 215 | glClearColor(0.7f, 0.7f, 0.7f, 1.0f); 216 | glShadeModel(GL_FLAT); 217 | glEnable(GL_LINE_SMOOTH); 218 | //glEnable(GL_DEPTH_TEST); 219 | glLineWidth(1); 220 | glPointSize(7.0); 221 | } 222 | 223 | void SplineDisplayerWidget::paintGL() 224 | { 225 | glClear(GL_COLOR_BUFFER_BIT/* | GL_DEPTH_BUFFER_BIT*/); 226 | 227 | glMatrixMode(GL_MODELVIEW); 228 | glLoadIdentity(); 229 | gluLookAt(m_CameraPos.x, m_CameraPos.y, m_CameraPos.z, m_CameraPos.x, m_CameraPos.y, m_CameraPos.z-10, 0, 1, 0); 230 | /*glTranslated(0.0, 0.0, -10.0);*/ 231 | 232 | // glViewport(20, 20, m_width-20, m_height-20); 233 | glViewport(0, 0, m_width, m_height); 234 | drawGrid(); 235 | drawSpline(); 236 | 237 | 238 | } 239 | 240 | void SplineDisplayerWidget::resizeGL(int width, int height) 241 | { 242 | m_width = width; m_height = height; 243 | 244 | glMatrixMode(GL_PROJECTION); 245 | glLoadIdentity(); 246 | // glOrtho(-0.5, +0.5, +0.5, -0.5, 4.0, 15.0); 247 | // gluPerspective(90.0f, GLfloat(width)/GLfloat(height), CAMERA_D, 5000.0f); 248 | gluPerspective(90.0f, 1, 1, 5000.0f); 249 | glMatrixMode(GL_MODELVIEW); 250 | } 251 | 252 | aaAaa::Vector2 SplineDisplayerWidget::screen2gl(int x, int y){ 253 | int hw = this->width() * 0.5f; 254 | int hh = this->height() * 0.5f; 255 | double oglx = double(x - hw) / double(hw); 256 | double ogly = -double(y - hh) / double(hh); 257 | double realx = oglx * (m_CameraPos.z - Z_VALUE); 258 | double realy = ogly * (m_CameraPos.z - Z_VALUE); 259 | 260 | return aaAaa::Vector2(realx + m_CameraPos.x, (realy + m_CameraPos.y) / Y_FACTOR); 261 | } 262 | 263 | int SplineDisplayerWidget::checkSelected(aaAaa::Vector2 point){ 264 | if(!m_spline_data){ 265 | return -1; 266 | emit selectValuesChanged(0, 0); 267 | } 268 | aaAaa::aaSpline &m_spline_data = *(this->m_spline_data); 269 | 270 | float factor = (m_CameraPos.z - Z_VALUE) * 0.1f * 0.5f; 271 | for(size_t i=0; ibuttons() & Qt::MidButton) 285 | lastPos = event->pos(); 286 | 287 | // if(ctrlSelected == -1){ 288 | if(event->button() == Qt::LeftButton || event->button() == Qt::RightButton){ 289 | aaAaa::Vector2 glpoint = screen2gl(event->x(), event->y()); 290 | 291 | ctrlSelected = checkSelected(glpoint); 292 | 293 | emit selectValuesChanged(glpoint.t, glpoint.y); 294 | // std::cout << "glpoint: (" << glpoint.t << ", " << glpoint.y << "); ctrlSelected: " << ctrlSelected << "\n"; 295 | } 296 | 297 | updateGL(); 298 | } 299 | 300 | void SplineDisplayerWidget::mouseReleaseEvent(QMouseEvent *event){ 301 | if(!m_spline_data) 302 | return ; 303 | aaAaa::aaSpline &m_spline_data = *(this->m_spline_data); 304 | 305 | if(event->button() == Qt::RightButton){ 306 | aaAaa::aaSpline::KnotsList &ctrlpoints = m_spline_data.knots; 307 | if (ctrlSelected >= 0){ 308 | if(ctrlSelected != 0 && ctrlSelected != ctrlpoints.size()-1){ 309 | ctrlpoints.erase(ctrlpoints.begin() + ctrlSelected); 310 | } 311 | 312 | aaAaa::Vector2 glpoint = screen2gl(event->x(), event->y()); 313 | ctrlSelected = checkSelected(glpoint); 314 | 315 | }else{ 316 | aaAaa::Vector2 p = screen2gl(event->x(), event->y()); 317 | if(p.t > ctrlpoints[0].t && 318 | p.t < ctrlpoints[ctrlpoints.size()-1].t){ 319 | 320 | aaAaa::aaSpline::KnotsList::iterator it = ctrlpoints.begin(); 321 | ++it; 322 | for(; it!=ctrlpoints.end(); ++it){ 323 | if(p.t < (*it).t) 324 | break; 325 | } 326 | 327 | ctrlpoints.insert(it, p); 328 | 329 | aaAaa::Vector2 glpoint = screen2gl(event->x(), event->y()); 330 | ctrlSelected = checkSelected(glpoint); 331 | } 332 | } 333 | 334 | updateGL(); 335 | } 336 | //ctrlSelected = -1; 337 | } 338 | 339 | void SplineDisplayerWidget::mouseMoveEvent(QMouseEvent *event) 340 | { 341 | 342 | int dx = event->x() - lastPos.x(); 343 | int dy = event->y() - lastPos.y(); 344 | 345 | 346 | 347 | if (ctrlSelected >= 0 && 348 | event->buttons() & Qt::LeftButton && m_spline_data){ 349 | 350 | aaAaa::aaSpline &m_spline_data = *(this->m_spline_data); 351 | 352 | aaAaa::aaSpline::KnotsList &ctrlpoints = m_spline_data.knots; 353 | aaAaa::Vector2 npos = screen2gl(event->x(), event->y()); 354 | ctrlpoints[ctrlSelected].y = npos.y; 355 | ctrlpoints[ctrlSelected].t = npos.t; 356 | 357 | if(ctrlSelected < ctrlpoints.size() - 1){ 358 | if(ctrlpoints[ctrlSelected].t >= ctrlpoints[ctrlSelected+1].t) 359 | ctrlpoints[ctrlSelected].t = ctrlpoints[ctrlSelected+1].t - 1; 360 | } 361 | if(ctrlSelected > 0){ 362 | if(ctrlpoints[ctrlSelected].t <= ctrlpoints[ctrlSelected-1].t) 363 | ctrlpoints[ctrlSelected].t = ctrlpoints[ctrlSelected-1].t + 1; 364 | } 365 | 366 | if(m_spline_data.bLimited){ 367 | if(ctrlpoints[ctrlSelected].t < m_spline_data.limit_left){ 368 | ctrlpoints[ctrlSelected].t = m_spline_data.limit_left; 369 | }else if(ctrlpoints[ctrlSelected].t > m_spline_data.limit_right){ 370 | ctrlpoints[ctrlSelected].t = m_spline_data.limit_right; 371 | } 372 | 373 | if(ctrlpoints[ctrlSelected].y < m_spline_data.limit_bottom){ 374 | ctrlpoints[ctrlSelected].y = m_spline_data.limit_bottom; 375 | }else if(ctrlpoints[ctrlSelected].y > m_spline_data.limit_top){ 376 | ctrlpoints[ctrlSelected].y = m_spline_data.limit_top; 377 | } 378 | } 379 | 380 | emit selectValuesChanged(ctrlpoints[ctrlSelected].t, ctrlpoints[ctrlSelected].y); 381 | 382 | m_bIfModify = true; 383 | }else if(event->buttons() & Qt::MidButton){ 384 | m_CameraPos.x = (m_CameraPos.x - dx*0.3f); 385 | m_CameraPos.y = (m_CameraPos.y + dy*0.3f); 386 | } 387 | lastPos = event->pos(); 388 | updateGL(); 389 | } 390 | 391 | void SplineDisplayerWidget::wheelEvent(QWheelEvent *e) 392 | { 393 | if(e->delta() > 0) 394 | m_CameraPos.z -= 3; 395 | else if(e->delta() < 0) 396 | m_CameraPos.z += 3; 397 | //m_CameraPos.setZ(m_CameraPos.z() + e->delta()*0.3); 398 | if(m_CameraPos.z < 0) 399 | m_CameraPos.z = 0; 400 | 401 | // emit selectValuesChanged(m_CameraPos.z, m_CameraPos.z - Z_VALUE); 402 | updateGL(); 403 | } 404 | 405 | void SplineDisplayerWidget::setCurrentSelected(int index){ 406 | if(!m_spline_data) 407 | return ; 408 | if(index >= 0 && index < m_spline_data->knots.size()){ 409 | ctrlSelected = index; 410 | emit selectValuesChanged(m_spline_data->knots[ctrlSelected].t, m_spline_data->knots[ctrlSelected].y); 411 | } 412 | updateGL(); 413 | } 414 | 415 | -------------------------------------------------------------------------------- /src/curveeditor/SplineDisplayerWidget.h: -------------------------------------------------------------------------------- 1 | #ifndef __SPLINEDISPLAYERWIDGET_H__ 2 | #define __SPLINEDISPLAYERWIDGET_H__ 3 | 4 | #include "GlobalData.h" 5 | 6 | #include 7 | #include 8 | 9 | #include 10 | 11 | class SplineDisplayerWidget : public QGLWidget{ 12 | Q_OBJECT 13 | 14 | public: 15 | int m_axis; 16 | aaAaa::Vector3 m_CameraPos; 17 | 18 | static const int Z_VALUE = -10; 19 | static const int CAMERA_D = 1; 20 | static const int Y_FACTOR = 1; 21 | static const float MY_PI; 22 | 23 | QPoint lastPos; 24 | 25 | int ctrlSelected; 26 | 27 | std::vector *m_framedata; 28 | bool m_bIfModify; 29 | 30 | aaAaa::aaSpline *m_spline_data; 31 | double m_deltaT; 32 | 33 | int m_width, m_height; 34 | 35 | public: 36 | SplineDisplayerWidget(double deltaT, QWidget *parent = 0); 37 | ~SplineDisplayerWidget(void); 38 | 39 | public: 40 | void setAE(aaAaa::aaSpline *sdata); 41 | 42 | void setCurrentSelected(int index); 43 | 44 | private: 45 | void drawGrid(void); 46 | void drawSpline(void); 47 | 48 | aaAaa::Vector2 screen2gl(int x, int y); 49 | int checkSelected(aaAaa::Vector2 point); 50 | 51 | protected: 52 | // void paintEvent(QPaintEvent *event); 53 | void initializeGL(); 54 | void paintGL(); 55 | void resizeGL(int width, int height); 56 | void mousePressEvent(QMouseEvent *event); 57 | void mouseReleaseEvent(QMouseEvent *event); 58 | void mouseMoveEvent(QMouseEvent *event); 59 | void wheelEvent(QWheelEvent *); 60 | 61 | signals: 62 | void selectValuesChanged(float t, float v); 63 | }; 64 | 65 | 66 | 67 | #endif // __SPLINEDISPLAYERWIDGET_H__ 68 | -------------------------------------------------------------------------------- /src/curveeditor/graphiceditor.cpp: -------------------------------------------------------------------------------- 1 | #include "graphiceditor.h" 2 | //#include "smGraphicsScene.h" 3 | #include "GlobalData.h" 4 | //#include "SplineCurveItem.h" 5 | #include "SplineDisplayerWidget.h" 6 | 7 | #include 8 | 9 | graphiceditor::graphiceditor(QWidget *parent) 10 | : QDialog(parent), m_curve_type(aaAaa::aaSpline::SPLINE_CUBIC) 11 | { 12 | ui.setupUi(this); 13 | 14 | GlobalData::instance().addGe(this); 15 | 16 | for(int i=0; iaddItem(aaAaa::aaSpline::spline_name[i].c_str()); 18 | } 19 | 20 | // m_pgv = ui.graphicsView_spline; 21 | // setupScene(); 22 | m_viewer = new SplineDisplayerWidget(0.1, ui.frame_spline); 23 | QVBoxLayout *layout = new QVBoxLayout; 24 | layout->addWidget(m_viewer); 25 | ui.frame_spline->setLayout(layout); 26 | 27 | 28 | 29 | connect(ui.comboBox_item, SIGNAL(currentIndexChanged(int)), this, SLOT(onCurveSelectChanged(int))); 30 | connect(ui.comboBox_type, SIGNAL(currentIndexChanged(int)), this, SLOT(onCurveTypeChanged(int))); 31 | connect(m_viewer, SIGNAL(selectValuesChanged(float, float)), this, SLOT(onSelectPosChanged(float, float))); 32 | } 33 | 34 | graphiceditor::~graphiceditor() 35 | { 36 | 37 | if(m_viewer) 38 | delete m_viewer; 39 | } 40 | 41 | int graphiceditor::getCurrentSplineIndex(){ 42 | return ui.comboBox_item->currentIndex(); 43 | } 44 | 45 | void graphiceditor::setupSplines(){ 46 | ui.comboBox_item->clear(); 47 | m_viewer->setAE(0); 48 | 49 | SplineVec &splines = m_splines; 50 | for(int i=0; iaddItem(splines[i].name.c_str()); 53 | } 54 | 55 | if(!splines.empty()) 56 | m_viewer->setAE(&(splines[0])); 57 | } 58 | 59 | void graphiceditor::clearSplines(){ 60 | m_splines.clear(); 61 | ui.comboBox_item->clear(); 62 | m_viewer->setAE(0); 63 | } 64 | 65 | void graphiceditor::setSplines(const std::vector &splines){ 66 | m_splines = splines; 67 | setupSplines(); 68 | } 69 | 70 | void graphiceditor::addSpline(const aaAaa::aaSpline &knot){ 71 | m_splines.push_back(knot); 72 | setupSplines(); 73 | } 74 | 75 | void graphiceditor::onCurveSelectChanged(int index){ 76 | if(index != -1){ 77 | m_viewer->setAE(&(m_splines[index])); 78 | } 79 | } 80 | 81 | void graphiceditor::onCurveTypeChanged(int index){ 82 | if(index != -1){ 83 | m_curve_type = index; 84 | 85 | SplineVec &splines = m_splines; 86 | for(int i=0; iupdate(); 90 | } 91 | } 92 | 93 | void graphiceditor::onSelectPosChanged(float t, float v){ 94 | ui.lineEdit_input->setText(QString("%1").arg(t)); 95 | ui.lineEdit_output->setText(QString("%1").arg(v)); 96 | } 97 | 98 | void graphiceditor::closeEvent(QCloseEvent *event){ 99 | GlobalData::instance().rmGe(this); 100 | } 101 | 102 | void graphiceditor::addKnot(int index, const aaAaa::aaPoint &pt){ 103 | if(index < 0 || index >= m_splines.size()) 104 | return ; 105 | 106 | aaAaa::aaSpline &cur = m_splines[index]; 107 | cur.addKnots(pt); 108 | setupSplines(); 109 | 110 | ui.comboBox_item->setCurrentIndex(index); 111 | } 112 | 113 | void graphiceditor::addKnot(int index, float t){ 114 | if(index < 0 || index >= m_splines.size()) 115 | return ; 116 | 117 | aaAaa::aaSpline &cur = m_splines[index]; 118 | aaAaa::aaCurvePtr curve = aaAaa::aaCurveFactory::createCurve(cur); 119 | 120 | if(!curve.get()) 121 | return ; 122 | 123 | double v; 124 | curve->getValue(t, v); 125 | 126 | int selpoint = cur.addKnots(aaAaa::aaPoint(t, v)); 127 | setupSplines(); 128 | 129 | ui.comboBox_item->setCurrentIndex(index); 130 | if(selpoint > 0) 131 | m_viewer->setCurrentSelected(selpoint); 132 | } -------------------------------------------------------------------------------- /src/curveeditor/graphiceditor.h: -------------------------------------------------------------------------------- 1 | #ifndef GRAPHICEDITOR_H 2 | #define GRAPHICEDITOR_H 3 | 4 | #include 5 | #include "ui_graphiceditor.h" 6 | 7 | #include "../libspline/aaCurve.h" 8 | #include 9 | 10 | class SplineDisplayerWidget; 11 | 12 | typedef std::vector SplineVec; 13 | 14 | class graphiceditor : public QDialog 15 | { 16 | Q_OBJECT 17 | 18 | public: 19 | graphiceditor(QWidget *parent = 0); 20 | ~graphiceditor(); 21 | 22 | void clearSplines(); 23 | void addSpline(const aaAaa::aaSpline &knot); 24 | void setSplines(const std::vector &splines); 25 | void addKnot(int index, const aaAaa::aaPoint &pt); 26 | void addKnot(int index, float t); 27 | 28 | int getCurrentSplineIndex(); 29 | 30 | const std::vector &getSplines(void) const{ 31 | return m_splines; 32 | } 33 | 34 | private: 35 | Ui::graphiceditorClass ui; 36 | 37 | SplineDisplayerWidget *m_viewer; 38 | 39 | int m_curve_type; 40 | SplineVec m_splines; 41 | 42 | private: 43 | void setupSplines(); 44 | 45 | protected: 46 | void closeEvent(QCloseEvent *event); 47 | 48 | private slots: 49 | void onCurveSelectChanged(int index); 50 | void onCurveTypeChanged(int index); 51 | void onSelectPosChanged(float t, float v); 52 | }; 53 | 54 | #endif // GRAPHICEDITOR_H 55 | -------------------------------------------------------------------------------- /src/curveeditor/graphiceditor.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | graphiceditorClass 4 | 5 | 6 | 7 | 0 8 | 0 9 | 546 10 | 375 11 | 12 | 13 | 14 | GraphicEditor 15 | 16 | 17 | 18 | 19 | 20 | QLayout::SetDefaultConstraint 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | Qt::Horizontal 32 | 33 | 34 | 35 | 40 36 | 20 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | input(X) 45 | 46 | 47 | 48 | 49 | 50 | 51 | 0 52 | 53 | 54 | false 55 | 56 | 57 | true 58 | 59 | 60 | 61 | 62 | 63 | 64 | output(Y) 65 | 66 | 67 | 68 | 69 | 70 | 71 | 0 72 | 73 | 74 | false 75 | 76 | 77 | true 78 | 79 | 80 | 81 | 82 | 83 | 84 | Qt::Horizontal 85 | 86 | 87 | 88 | 40 89 | 20 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 400 101 | 300 102 | 103 | 104 | 105 | QFrame::StyledPanel 106 | 107 | 108 | QFrame::Raised 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | -------------------------------------------------------------------------------- /src/libspline/aaCurve.cpp: -------------------------------------------------------------------------------- 1 | #include "aaCurve.h" 2 | #include "spline.h" 3 | 4 | 5 | namespace aaAaa{ 6 | 7 | std::string aaSpline::spline_name[aaSpline::SPLINE_COUNT] = {"Cubic Spline"}; 8 | 9 | /* aaCurve::aaCurve(const std::string &name, int knum, double *t, double *knot) 10 | : m_name(name), m_knum(knum), m_t(0), m_knot(0){ 11 | 12 | if(m_knum <= 0) 13 | return ; 14 | 15 | m_t = new double[m_knum]; 16 | m_knot = new double[m_knum]; 17 | 18 | for(int i=0; i 3) 61 | m_ddp = spline_cubic_set(m_knum, m_t, m_knot, 2, 0, 2, 0); 62 | } 63 | 64 | aaCubicSpline::~aaCubicSpline(void){ 65 | if(m_ddp) 66 | delete []m_ddp; 67 | } 68 | 69 | bool aaCubicSpline::getValue(double t, double &value){ 70 | if(!m_t) 71 | return false; 72 | 73 | if(m_knum > 3){ 74 | if(!m_ddp) 75 | return false; 76 | 77 | double dp, ddp; 78 | value = spline_cubic_val(m_knum, m_t, t, m_knot, m_ddp, &dp, &ddp); 79 | 80 | return true; 81 | }else if(m_knum > 2){ 82 | double dp; 83 | spline_quadratic_val(m_knum, m_t, m_knot, t, &value, &dp); 84 | 85 | return true; 86 | }else if(m_knum > 1){ 87 | double dp; 88 | spline_linear_val(m_knum, m_t, m_knot, t, &value, &dp); 89 | 90 | return true; 91 | }else{ 92 | return false; 93 | } 94 | } 95 | 96 | 97 | ////////////////////////////////////////////////////////////////////////// 98 | aaQuadraticSpline::aaQuadraticSpline(const aaSpline &spline_data) 99 | : aaCurve(spline_data){ 100 | 101 | } 102 | 103 | aaQuadraticSpline::~aaQuadraticSpline(void){ 104 | 105 | } 106 | 107 | bool aaQuadraticSpline::getValue(double t, double &value){ 108 | if(!m_t) 109 | return false; 110 | 111 | if(m_knum > 2){ 112 | double dp; 113 | spline_quadratic_val(m_knum, m_t, m_knot, t, &value, &dp); 114 | 115 | return true; 116 | }else if(m_knum > 1){ 117 | double dp; 118 | spline_linear_val(m_knum, m_t, m_knot, t, &value, &dp); 119 | 120 | return true; 121 | }else{ 122 | return false; 123 | } 124 | } 125 | 126 | 127 | ////////////////////////////////////////////////////////////////////////// 128 | aaLinearSpline::aaLinearSpline(const aaSpline &spline_data) 129 | : aaCurve(spline_data){ 130 | 131 | } 132 | 133 | aaLinearSpline::~aaLinearSpline(void){ 134 | 135 | } 136 | 137 | bool aaLinearSpline::getValue(double t, double &value){ 138 | if(!m_t || m_knum < 2) 139 | return false; 140 | 141 | double rate = (t - m_t[0]) / (m_t[1] - m_t[0]); 142 | if(rate < 0) 143 | value = m_knot[0]; 144 | if(rate > 1) 145 | value = m_knot[1]; 146 | value = (1 - rate) * m_knot[0] + rate * m_knot[1]; 147 | 148 | return true; 149 | } 150 | 151 | } 152 | -------------------------------------------------------------------------------- /src/libspline/aaCurve.h: -------------------------------------------------------------------------------- 1 | #ifndef __AACURVE_H__ 2 | #define __AACURVE_H__ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | namespace aaAaa{ 10 | 11 | struct aaPoint{ 12 | float t, y; 13 | 14 | aaPoint(void) : t(0), y(0){} 15 | aaPoint(float at, float ay) : t(at), y(ay){} 16 | }; 17 | typedef aaPoint Vector2; 18 | 19 | struct Vector3{ 20 | float x, y, z; 21 | Vector3(void): x(0), y(0), z(0){} 22 | Vector3(float ax, float ay, float az) 23 | : x(ax), y(ay), z(az){ 24 | 25 | } 26 | }; 27 | 28 | // spline data 29 | struct aaSpline{ 30 | enum{ 31 | SPLINE_CUBIC = 0, 32 | // SPLINE_QUADRATIC, 33 | // SPLINE_LINEAR, 34 | SPLINE_COUNT, 35 | }; 36 | static std::string spline_name[SPLINE_COUNT]; 37 | 38 | int type; 39 | 40 | typedef std::vector KnotsList; 41 | std::string name; 42 | // std::map knots; 43 | KnotsList knots; 44 | 45 | bool bLimited; 46 | float limit_left, limit_top, limit_right, limit_bottom; 47 | 48 | aaSpline(void) 49 | : type(SPLINE_CUBIC), bLimited(false), limit_left(0.0f), 50 | limit_top(0.0f), limit_right(0.0f), limit_bottom(0.0f){ 51 | 52 | } 53 | 54 | aaSpline(const std::string &spline_name) 55 | : type(SPLINE_CUBIC), name(spline_name), bLimited(false), limit_left(0.0f), 56 | limit_top(0.0f), limit_right(0.0f), limit_bottom(0.0f){ 57 | 58 | } 59 | 60 | void setKnots(const std::vector > ¬s){ 61 | knots.clear(); 62 | for(int i=0; i knot){ 69 | //knots.insert(std::make_pair(not.first, aaPoint(not.first, not.second))); 70 | KnotsList::iterator it = knots.begin(); 71 | for(; it!=knots.end(); ++it){ 72 | if(knot.first < (*it).t) 73 | break; 74 | else if(knot.first == (*it).t){ 75 | return ; 76 | } 77 | } 78 | 79 | knots.insert(it, aaPoint(knot.first, knot.second)); 80 | } 81 | 82 | int addKnots(aaPoint knot){ 83 | //knots.insert(std::make_pair(not.t, not)); 84 | int count = 0; 85 | KnotsList::iterator it = knots.begin(); 86 | for(; it!=knots.end(); ++it){ 87 | if(knot.t < (*it).t) 88 | break; 89 | else if(knot.t == (*it).t){ 90 | return -1; 91 | } 92 | ++count; 93 | } 94 | 95 | knots.insert(it, knot); 96 | return count; 97 | } 98 | 99 | void setLimit(float left, float top, float right, float bottom){ 100 | bLimited = true; 101 | limit_left = left; 102 | limit_top = top; 103 | limit_right = right; 104 | limit_bottom = bottom; 105 | } 106 | 107 | void removeLimit(void){ 108 | bLimited = false; 109 | } 110 | 111 | void setName(const std::string &name){ 112 | this->name = name; 113 | } 114 | 115 | size_t size(void) const{ return knots.size(); } 116 | }; 117 | 118 | // spline function 119 | 120 | class aaCurve{ 121 | protected: 122 | std::string m_name; 123 | int m_knum; 124 | 125 | double *m_t; 126 | double *m_knot; 127 | 128 | public: 129 | // aaCurve(const std::string &name, int knum, double *t, double *knot); 130 | aaCurve(const aaSpline &spline_data); 131 | virtual ~aaCurve(void); 132 | 133 | std::string name(void) const{ return m_name; } 134 | 135 | virtual bool getValue(double t, double &value) = 0; 136 | 137 | }; 138 | 139 | typedef std::auto_ptr aaCurvePtr; 140 | 141 | class aaCubicSpline : public aaCurve{ 142 | private: 143 | double *m_ddp; 144 | 145 | public: 146 | aaCubicSpline(const aaSpline &spline_data); 147 | virtual ~aaCubicSpline(void); 148 | 149 | virtual bool getValue(double t, double &value); 150 | }; 151 | 152 | class aaBSpline : public aaCurve{ 153 | public: 154 | aaBSpline(const aaSpline &spline_data); 155 | virtual ~aaBSpline(void); 156 | 157 | virtual bool getValue(double t, double &value); 158 | }; 159 | 160 | 161 | class aaQuadraticSpline : public aaCurve{ 162 | 163 | public: 164 | aaQuadraticSpline(const aaSpline &spline_data); 165 | virtual ~aaQuadraticSpline(void); 166 | 167 | virtual bool getValue(double t, double &value); 168 | }; 169 | 170 | class aaLinearSpline : public aaCurve{ 171 | 172 | public: 173 | aaLinearSpline(const aaSpline &spline_data); 174 | virtual ~aaLinearSpline(void); 175 | 176 | virtual bool getValue(double t, double &value); 177 | }; 178 | ////////////////////////////////////////////////////////////////////////// 179 | 180 | class aaCurveFactory{ 181 | private: 182 | aaCurveFactory(void); 183 | aaCurveFactory(const aaCurveFactory&); 184 | public: 185 | static aaCurvePtr createCurve(const aaSpline &spline_data){ 186 | switch(spline_data.type){ 187 | case aaSpline::SPLINE_CUBIC: 188 | return aaCurvePtr(new aaCubicSpline(spline_data)); 189 | /*case aaSpline::SPLINE_QUADRATIC: 190 | return aaCurvePtr(new aaQuadraticSpline(spline_data)); 191 | case aaSpline::SPLINE_LINEAR: 192 | return aaCurvePtr(new aaLinearSpline(spline_data));*/ 193 | default: 194 | return aaCurvePtr(0); 195 | } 196 | } 197 | }; 198 | 199 | } 200 | 201 | #endif // __AASPLINE_H__ 202 | 203 | -------------------------------------------------------------------------------- /src/libspline/spline.h: -------------------------------------------------------------------------------- 1 | #ifndef __SPLINE_H__ 2 | #define __SPLINE_H__ 3 | 4 | double basis_function_b_val ( double tdata[], double tval ); 5 | double basis_function_beta_val ( double beta1, double beta2, double tdata[], 6 | double tval ); 7 | double *basis_matrix_b_uni ( void ); 8 | double *basis_matrix_beta_uni ( double beta1, double beta2 ); 9 | double *basis_matrix_bezier ( void ); 10 | double *basis_matrix_hermite ( void ); 11 | double *basis_matrix_overhauser_nonuni ( double alpha, double beta ); 12 | double *basis_matrix_overhauser_nul ( double alpha ); 13 | double *basis_matrix_overhauser_nur ( double beta ); 14 | double *basis_matrix_overhauser_uni ( void); 15 | double *basis_matrix_overhauser_uni_l ( void ); 16 | double *basis_matrix_overhauser_uni_r ( void ); 17 | double basis_matrix_tmp ( int left, int n, double mbasis[], int ndata, 18 | double tdata[], double ydata[], double tval ); 19 | void bc_val ( int n, double t, double xcon[], double ycon[], double *xval, 20 | double *yval ); 21 | double bez_val ( int n, double x, double a, double b, double y[] ); 22 | double bp_approx ( int n, double a, double b, double ydata[], double xval ); 23 | double *bp01 ( int n, double x ); 24 | double *bpab ( int n, double a, double b, double x ); 25 | int chfev ( double x1, double x2, double f1, double f2, double d1, double d2, 26 | int ne, double xe[], double fe[], int next[] ); 27 | int d3_fs ( double a1[], double a2[], double a3[], int n, double b[], double x[] ); 28 | double *d3_mxv ( int n, double a[], double x[] ); 29 | double *d3_np_fs ( int n, double a[], double b[] ); 30 | void d3_print ( int n, double a[], char *title ); 31 | void d3_print_some ( int n, double a[], int ilo, int jlo, int ihi, int jhi ); 32 | double *d3_uniform ( int n, int *seed ); 33 | void data_to_dif ( int ntab, double xtab[], double ytab[], double diftab[] ); 34 | double dif_val ( int ntab, double xtab[], double diftab[], double xval ); 35 | int i4_max ( int i1, int i2 ); 36 | int i4_min ( int i1, int i2 ); 37 | void least_set ( int point_num, double x[], double f[], double w[], 38 | int nterms, double b[], double c[], double d[] ); 39 | double least_val ( int nterms, double b[], double c[], double d[], 40 | double x ); 41 | void least_val2 ( int nterms, double b[], double c[], double d[], double x, 42 | double *px, double *pxp ); 43 | void least_set_old ( int ntab, double xtab[], double ytab[], int ndeg, 44 | double ptab[], double b[], double c[], double d[], double *eps, int *ierror ); 45 | double least_val_old ( double x, int ndeg, double b[], double c[], double d[] ); 46 | void parabola_val2 ( int ndim, int ndata, double tdata[], double ydata[], 47 | int left, double tval, double yval[] ); 48 | double pchst ( double arg1, double arg2 ); 49 | double r8_max ( double x, double y ); 50 | double r8_min ( double x, double y ); 51 | double r8_uniform_01 ( int *seed ); 52 | void r8vec_bracket ( int n, double x[], double xval, int *left, int *right ); 53 | void r8vec_bracket3 ( int n, double t[], double tval, int *left ); 54 | double *r8vec_even ( int n, double alo, double ahi ); 55 | double *r8vec_indicator ( int n ); 56 | void r8vec_order_type ( int n, double x[], int *order ); 57 | void r8vec_print ( int n, double a[], char *title ); 58 | void r8vec_sort_bubble_a ( int n, double a[] ); 59 | double *r8vec_uniform ( int n, double b, double c, int *seed ); 60 | int r8vec_unique_count ( int n, double a[], double tol ); 61 | void r8vec_zero ( int n, double a[] ); 62 | int s_len_trim ( char* s ); 63 | double spline_b_val ( int ndata, double tdata[], double ydata[], double tval ); 64 | double spline_beta_val ( double beta1, double beta2, int ndata, double tdata[], 65 | double ydata[], double tval ); 66 | double spline_constant_val ( int ndata, double tdata[], double ydata[], double tval ); 67 | double *spline_cubic_set ( int n, double t[], double y[], int ibcbeg, double ybcbeg, 68 | int ibcend, double ybcend ); 69 | double spline_cubic_val ( int n, double t[], double tval, double y[], double ypp[], 70 | double *ypval, double *yppval ); 71 | void spline_cubic_val2 ( int n, double t[], double tval, int *left, double y[], 72 | double ypp[], double *yval, double *ypval, double *yppval ); 73 | double *spline_hermite_set ( int ndata, double tdata[], double ydata[], 74 | double ypdata[] ); 75 | void spline_hermite_val ( int ndata, double tdata[], double c[], double tval, 76 | double *sval, double *spval ); 77 | double spline_linear_int ( int ndata, double tdata[], double ydata[], double a, 78 | double b ); 79 | void spline_linear_intset ( int int_n, double int_x[], double int_v[], 80 | double data_x[], double data_y[] ); 81 | void spline_linear_val ( int ndata, double tdata[], double ydata[], 82 | double tval, double *yval, double *ypval ); 83 | double spline_overhauser_nonuni_val ( int ndata, double tdata[], 84 | double ydata[], double tval ); 85 | double spline_overhauser_uni_val ( int ndata, double tdata[], double ydata[], 86 | double tval ); 87 | void spline_overhauser_val ( int ndim, int ndata, double tdata[], double ydata[], 88 | double tval, double yval[] ); 89 | void spline_pchip_set ( int n, double x[], double f[], double d[] ); 90 | void spline_pchip_val ( int n, double x[], double f[], double d[], int ne, 91 | double xe[], double fe[] ); 92 | void spline_quadratic_val ( int ndata, double tdata[], double ydata[], 93 | double tval, double *yval, double *ypval ); 94 | void timestamp ( void ); 95 | 96 | #endif // __SPLINE_H__ 97 | --------------------------------------------------------------------------------