TAPs 0.7.7.3
TAPsWXElasticRodParameters.cpp
Go to the documentation of this file.
00001 /******************************************************************************
00002 TAPsWXElasticRodParameters.cpp
00003 ******************************************************************************/
00007 /******************************************************************************
00008 SUKITTI PUNAK   (08/18/2009)
00009 UPDATE          (08/12/2010)
00010 ******************************************************************************/
00011 #include "TAPsWXElasticRodParameters.hpp"
00012 // Using Inclusion Model (i.e. definitions are included in declarations)
00013 //                       (this name.cpp is included in name.hpp)
00014 // Each friend is defined directly inside its declaration.
00015 
00016 BEGIN_NAMESPACE_TAPs__WX
00017 //=============================================================================
00018 // EVENT TABLE
00019 //-----------------------------------------------------------------------------
00020 IMPLEMENT_CLASS ( WXElasticRodParameters, wxDialog )
00021 //-----------------------------------------------------------------------------
00022 BEGIN_EVENT_TABLE( WXElasticRodParameters, wxDialog )
00023     //-----------------------------------------------------
00024     // Physically Based Parameters
00025     EVT_TEXT    ( ID_WXElasticRod_Length,                           WXElasticRodParameters::OnEnteringPhysicallyBasedParameters )
00026     EVT_TEXT    ( ID_WXElasticRod_Mass,                             WXElasticRodParameters::OnEnteringPhysicallyBasedParameters )
00027     EVT_TEXT    ( ID_WXElasticRod_Radius,                           WXElasticRodParameters::OnEnteringPhysicallyBasedParameters )
00028     //EVT_TEXT  ( ID_WXElasticRod_NumOfLinks,                       WXElasticRodParameters::OnEnteringPhysicallyBasedParameters )
00029     EVT_TEXT    ( ID_WXElasticRod_StretchModulus,                   WXElasticRodParameters::OnEnteringPhysicallyBasedParameters )
00030     EVT_TEXT    ( ID_WXElasticRod_BendModulus,                      WXElasticRodParameters::OnEnteringPhysicallyBasedParameters )
00031     EVT_TEXT    ( ID_WXElasticRod_ShearModulus,                     WXElasticRodParameters::OnEnteringPhysicallyBasedParameters )
00032     EVT_TEXT    ( ID_WXElasticRod_MaterialDensity,                  WXElasticRodParameters::OnEnteringPhysicallyBasedParameters )
00033     EVT_TEXT    ( ID_WXElasticRod_KineticTranslational,             WXElasticRodParameters::OnEnteringPhysicallyBasedParameters )
00034     EVT_TEXT    ( ID_WXElasticRod_KineticRotational_0,              WXElasticRodParameters::OnEnteringPhysicallyBasedParameters )
00035     EVT_TEXT    ( ID_WXElasticRod_KineticRotational_1,              WXElasticRodParameters::OnEnteringPhysicallyBasedParameters )
00036     EVT_TEXT    ( ID_WXElasticRod_KineticRotational_2,              WXElasticRodParameters::OnEnteringPhysicallyBasedParameters )
00037     EVT_TEXT    ( ID_WXElasticRod_DissipationTranslational,         WXElasticRodParameters::OnEnteringPhysicallyBasedParameters )
00038     EVT_TEXT    ( ID_WXElasticRod_DissipationRotational_0,          WXElasticRodParameters::OnEnteringPhysicallyBasedParameters )
00039     EVT_TEXT    ( ID_WXElasticRod_DissipationRotational_1,          WXElasticRodParameters::OnEnteringPhysicallyBasedParameters )
00040     EVT_TEXT    ( ID_WXElasticRod_DissipationRotational_2,          WXElasticRodParameters::OnEnteringPhysicallyBasedParameters )
00041     EVT_TEXT    ( ID_WXElasticRod_Constraint_3rdDirAlignCenterline, WXElasticRodParameters::OnEnteringPhysicallyBasedParameters )
00042     EVT_TEXT    ( ID_WXElasticRod_Constraint_ScaleIntrinsicStrainRate,  WXElasticRodParameters::OnEnteringPhysicallyBasedParameters )
00043     EVT_SLIDER  ( ID_WXElasticRod_GravitationalConstant_slider,                 WXElasticRodParameters::OnChangingPhysicallyBasedParameters )
00044     EVT_TEXT    ( ID_WXElasticRod_DampingVelocity,                  WXElasticRodParameters::OnEnteringPhysicallyBasedParameters )
00045 
00046     EVT_TEXT_ENTER  ( ID_WXElasticRod_Length,                           WXElasticRodParameters::OnChangingPhysicallyBasedParameters )
00047     EVT_TEXT_ENTER  ( ID_WXElasticRod_Mass,                             WXElasticRodParameters::OnChangingPhysicallyBasedParameters )
00048     EVT_TEXT_ENTER  ( ID_WXElasticRod_Radius,                           WXElasticRodParameters::OnChangingPhysicallyBasedParameters )
00049     //EVT_TEXT_ENTER    ( ID_WXElasticRod_NumOfLinks,                   WXElasticRodParameters::OnChangingPhysicallyBasedParameters )
00050     EVT_TEXT_ENTER  ( ID_WXElasticRod_StretchModulus,                   WXElasticRodParameters::OnChangingPhysicallyBasedParameters )
00051     EVT_TEXT_ENTER  ( ID_WXElasticRod_BendModulus,                      WXElasticRodParameters::OnChangingPhysicallyBasedParameters )
00052     EVT_TEXT_ENTER  ( ID_WXElasticRod_ShearModulus,                     WXElasticRodParameters::OnChangingPhysicallyBasedParameters )
00053     EVT_TEXT_ENTER  ( ID_WXElasticRod_MaterialDensity,                  WXElasticRodParameters::OnChangingPhysicallyBasedParameters )
00054     EVT_TEXT_ENTER  ( ID_WXElasticRod_KineticTranslational,             WXElasticRodParameters::OnChangingPhysicallyBasedParameters )
00055     EVT_TEXT_ENTER  ( ID_WXElasticRod_KineticRotational_0,              WXElasticRodParameters::OnChangingPhysicallyBasedParameters )
00056     EVT_TEXT_ENTER  ( ID_WXElasticRod_KineticRotational_1,              WXElasticRodParameters::OnChangingPhysicallyBasedParameters )
00057     EVT_TEXT_ENTER  ( ID_WXElasticRod_KineticRotational_2,              WXElasticRodParameters::OnChangingPhysicallyBasedParameters )
00058     EVT_TEXT_ENTER  ( ID_WXElasticRod_DissipationTranslational,         WXElasticRodParameters::OnChangingPhysicallyBasedParameters )
00059     EVT_TEXT_ENTER  ( ID_WXElasticRod_DissipationRotational_0,          WXElasticRodParameters::OnChangingPhysicallyBasedParameters )
00060     EVT_TEXT_ENTER  ( ID_WXElasticRod_DissipationRotational_1,          WXElasticRodParameters::OnChangingPhysicallyBasedParameters )
00061     EVT_TEXT_ENTER  ( ID_WXElasticRod_DissipationRotational_2,          WXElasticRodParameters::OnChangingPhysicallyBasedParameters )
00062     EVT_TEXT_ENTER  ( ID_WXElasticRod_Constraint_3rdDirAlignCenterline, WXElasticRodParameters::OnChangingPhysicallyBasedParameters )
00063     EVT_TEXT_ENTER  ( ID_WXElasticRod_Constraint_ScaleIntrinsicStrainRate,  WXElasticRodParameters::OnChangingPhysicallyBasedParameters )
00064     EVT_TEXT_ENTER  ( ID_WXElasticRod_DampingVelocity,                  WXElasticRodParameters::OnChangingPhysicallyBasedParameters )
00065     //-----------------------------------------------------
00066     // Simulation Parameters
00067     EVT_CHECKBOX    ( ID_WXElasticRod_EnableSelfCDR,    WXElasticRodParameters::OnEnteringSimulationParameters )
00068     EVT_TEXT        ( ID_WXElasticRod_KselfCDR,         WXElasticRodParameters::OnEnteringSimulationParameters )
00069     EVT_TEXT_ENTER  ( ID_WXElasticRod_KselfCDR,         WXElasticRodParameters::OnChangingSimulationParameters )
00070     EVT_TEXT        ( ID_WXElasticRod_KselfCDR_Offset,  WXElasticRodParameters::OnEnteringSimulationParameters )
00071     EVT_TEXT_ENTER  ( ID_WXElasticRod_KselfCDR_Offset,  WXElasticRodParameters::OnChangingSimulationParameters )
00072 #ifdef  TAPs_ADD_KNOT_RECOGNITION
00073     EVT_CHECKBOX    ( ID_WXElasticRod_EnableKR,             WXElasticRodParameters::OnEnteringSimulationParameters )
00074     EVT_CHECKBOX    ( ID_WXElasticRod_EnableKR_LockKnots,   WXElasticRodParameters::OnEnteringSimulationParameters )
00075 #endif//TAPs_ADD_KNOT_RECOGNITION
00076 #ifdef  TAPs_USE_CUDA
00077     //EVT_CHECKBOX  ( ID_WXElasticRod_UseCUDA_PLHM,             WXElasticRodParameters::OnEnteringSimulationParameters )
00078     EVT_CHECKBOX    ( ID_WXElasticRod_EnableCUDA,               WXElasticRodParameters::OnEnteringSimulationParameters )
00079     EVT_CHECKBOX    ( ID_WXElasticRod_EnableCUDA_GenDrawData,   WXElasticRodParameters::OnEnteringSimulationParameters )
00080 #endif//TAPs_USE_CUDA
00081     EVT_TEXT        ( ID_WXElasticRod_Sim_TimeStep,             WXElasticRodParameters::OnEnteringSimulationParameters )
00082     EVT_TEXT_ENTER  ( ID_WXElasticRod_Sim_TimeStep,             WXElasticRodParameters::OnChangingSimulationParameters )
00083     EVT_TEXT        ( ID_WXElasticRod_CDRwBV_Cylinder_K,    WXElasticRodParameters::OnEnteringSimulationParameters )
00084     EVT_TEXT_ENTER  ( ID_WXElasticRod_CDRwBV_Cylinder_K,    WXElasticRodParameters::OnChangingSimulationParameters )
00085     EVT_TEXT        ( ID_WXElasticRod_CDRwBV_Sphere_K,      WXElasticRodParameters::OnEnteringSimulationParameters )
00086     EVT_TEXT_ENTER  ( ID_WXElasticRod_CDRwBV_Sphere_K,      WXElasticRodParameters::OnChangingSimulationParameters )
00087     EVT_TEXT        ( ID_WXElasticRod_CDRwTriangle_K,       WXElasticRodParameters::OnEnteringSimulationParameters )
00088     EVT_TEXT_ENTER  ( ID_WXElasticRod_CDRwTriangle_K,       WXElasticRodParameters::OnChangingSimulationParameters )
00089     EVT_TEXT        ( ID_WXElasticRod_CDRwBV_Cylinder_O,    WXElasticRodParameters::OnEnteringSimulationParameters )
00090     EVT_TEXT_ENTER  ( ID_WXElasticRod_CDRwBV_Cylinder_O,    WXElasticRodParameters::OnChangingSimulationParameters )
00091     EVT_TEXT        ( ID_WXElasticRod_CDRwBV_Sphere_O,      WXElasticRodParameters::OnEnteringSimulationParameters )
00092     EVT_TEXT_ENTER  ( ID_WXElasticRod_CDRwBV_Sphere_O,      WXElasticRodParameters::OnChangingSimulationParameters )
00093     EVT_TEXT        ( ID_WXElasticRod_CDRwTriangle_O,       WXElasticRodParameters::OnEnteringSimulationParameters )
00094     EVT_TEXT_ENTER  ( ID_WXElasticRod_CDRwTriangle_O,       WXElasticRodParameters::OnChangingSimulationParameters )
00095 
00096     // For CDR with implicit objects
00097 #ifdef  TAPs_ADD_IMPLICIT_OBJECTS
00098     EVT_TEXT        ( ID_WXElasticRod_CDRwImpObj_Sphere_K,  WXElasticRodParameters::OnEnteringSimulationParameters )
00099     EVT_TEXT_ENTER  ( ID_WXElasticRod_CDRwImpObj_Sphere_K,  WXElasticRodParameters::OnChangingSimulationParameters )
00100     EVT_TEXT        ( ID_WXElasticRod_CDRwImpObj_Sphere_O,  WXElasticRodParameters::OnEnteringSimulationParameters )
00101     EVT_TEXT_ENTER  ( ID_WXElasticRod_CDRwImpObj_Sphere_O,  WXElasticRodParameters::OnChangingSimulationParameters )
00102     EVT_TEXT        ( ID_WXElasticRod_CDRwImpObj_Torus_K,   WXElasticRodParameters::OnEnteringSimulationParameters )
00103     EVT_TEXT_ENTER  ( ID_WXElasticRod_CDRwImpObj_Torus_K,   WXElasticRodParameters::OnChangingSimulationParameters )
00104     EVT_TEXT        ( ID_WXElasticRod_CDRwImpObj_Torus_O,   WXElasticRodParameters::OnEnteringSimulationParameters )
00105     EVT_TEXT_ENTER  ( ID_WXElasticRod_CDRwImpObj_Torus_O,   WXElasticRodParameters::OnChangingSimulationParameters )
00106 #endif//TAPs_ADD_IMPLICIT_OBJECTS
00107 
00108     //-----------------------------------------------------
00109     // Rendering Parameters
00110     EVT_SLIDER  ( ID_WXElasticRod_Render_NumOfVerticesPerCrossSection_slider,   WXElasticRodParameters::OnChangingRenderingParameters )
00111     //-----------------------------------------------------
00112     // Load/Save Parameters
00113     EVT_COMBOBOX    ( ID_WXElasticRod_Load_Preset,      WXElasticRodParameters::OnLoadParameters )
00114     EVT_COMBOBOX    ( ID_WXElasticRod_Load_Userset,     WXElasticRodParameters::OnLoadParameters )
00115     EVT_BUTTON      ( ID_WXElasticRod_Save_Userset_Btn, WXElasticRodParameters::OnSaveParameters )
00116     //-----------------------------------------------------
00117 END_EVENT_TABLE()
00118 //=============================================================================
00119 
00120 //=============================================================================
00121 bool WXElasticRodParameters::g_isInitialized                = false;
00122 type_info const *   WXElasticRodParameters::g_pDataTypeInfo = NULL;
00123 TextFile            WXElasticRodParameters::g_PresetFile;
00124 TextFile            WXElasticRodParameters::g_UsersetFile;
00125 std::vector< ElasticRodParameters<float> >  WXElasticRodParameters::g_vfPresets;
00126 std::vector< ElasticRodParameters<float> >  WXElasticRodParameters::g_vfUsersets;
00127 std::vector< ElasticRodParameters<double> > WXElasticRodParameters::g_vdPresets;
00128 std::vector< ElasticRodParameters<double> > WXElasticRodParameters::g_vdUsersets;
00129 
00130 wxColour    WXElasticRodParameters::color_textEdit( 255, 0, 0 );
00131 wxColour    WXElasticRodParameters::color_textNormal( 0, 0, 0 );
00132 wxColour    WXElasticRodParameters::color_textWarning( 255, 0, 0 );
00133 
00134 //-----------------------------------------------------------------------------
00135 
00136 // Constructor
00137 WXElasticRodParameters::WXElasticRodParameters () 
00138     : m_isLoaded( false ), m_pERParameters( NULL ), m_pERNodeList( NULL )
00139     #ifdef  TAPs_USE_CUDA
00140       , m_bUseCUDA_PLHM( false )
00141     #endif//TAPs_USE_CUDA
00142 {
00143     // Check initialization
00144     if ( !g_isInitialized ) {
00145         wxXmlResource::Get()->InitAllHandlers();// Shoud be initialized in the main program
00146         std::string xrcFile( Global::GetTAPsResourcePath() + std::string("wxWidgets/Dialogs/TAPsWXElasticRodParameters.xrc") );
00147         if ( wxXmlResource::Get()->Load( xrcFile ) ) {
00148 
00149             g_isInitialized = true;
00150 
00151             // Load the parameter preset file
00152             std::string presetFile( Global::GetTAPsResourcePath() + std::string("Data/ModelElasticRod_PresetParameters.dat") );
00153             if ( g_PresetFile.Read( presetFile ) ) {
00154                 std::cout << "Passed: Reading \"" << presetFile << "\"\n";
00155             }
00156             else {
00157                 std::cout << "Failed: Reading \"" << presetFile << "\"\n";
00158             }
00159             
00160             // Load the parameter userset file
00161             std::string usersetFile( Global::GetTAPsResourcePath() + std::string("Data/ModelElasticRod_UsersetParameters.dat") );
00162             if ( g_UsersetFile.Read( usersetFile ) ) {
00163                 std::cout << "Passed: Reading \"" << usersetFile << "\"\n";
00164             }
00165             else {
00166                 std::cout << "Failed: Reading \"" << usersetFile << "\"\n";
00167             }
00168         }
00169         else {
00170             std::cout << "Loading xrcFile: " << xrcFile << " FAILED!\n";
00171             g_isInitialized = false;
00172         }
00173     }
00174 }
00175 
00176 
00177 // Destructor
00178 WXElasticRodParameters::~WXElasticRodParameters ()
00179 {}
00180 
00181 
00182 // Load the property dialog
00183 template <typename T>
00184 void WXElasticRodParameters::PropertyDialog (
00185     wxWindow * parent,                          
00186     ElasticRodParameters<T> * parameters,       
00187     std::vector< ElasticRodNode<T> > * nodeList 
00188     #ifdef  TAPs_USE_CUDA
00189     , bool bUseCUDA_PLHM    
00190     #endif//TAPs_USE_CUDA
00191 )
00192 {
00193     #ifdef  TAPs_USE_CUDA
00194     m_bUseCUDA_PLHM = bUseCUDA_PLHM;
00195     #endif//TAPs_USE_CUDA
00196 
00197     // Load the dialog if not loaded yet
00198     if ( !m_isLoaded ) {
00199         wxXmlResource::Get()->LoadDialog( this, parent, "ID_WXElasticRodParameters" );
00200         if ( this->GetName().Matches( "ID_WXElasticRodParameters" ) ) {
00201             m_isLoaded = true;
00202             m_pERParameters = parameters;   // set link to the elastic rod parameters
00203             m_pERNodeList = nodeList;       // set link to the elastic rod node list
00204             g_pDataTypeInfo = &typeid(T);   // set link to data type, e.g. float or double
00205             SetIDs();                       // set IDs of all GUI elements
00206             if ( m_bAllIDsWorking ) {
00207                 InitControlLooks();             // initialize the looks of GUI controls
00208                 InitListOfPresetAndUserset();   // initialize the list of preset and user set parameters
00209             }
00210         }
00211     }
00212 
00213     // Show the property dialog
00214     if ( m_isLoaded && m_bAllIDsWorking ) 
00215     {
00216         // Another way to connect the event handler, instead of declaring an event table
00217         //this->Connect( wxID_ANY, wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( WXElasticRodParameters::OnChangingPhysicallyBasedParameters ) );
00218 
00219         ElasticRodParameters<T> * par = static_cast<ElasticRodParameters<T> *>( m_pERParameters );
00220         ShowParametersValuesInGUI( *par );
00221 
00222         // Show the property dialog
00223         //ShowModel();  // show the dialog in model mode -- a model dialog blocks program flow and user input on other windows until it is dismissed.
00224         Show();         // show the dialog in modeless -- a modeless dialog behaves more like a frame in that program flow continues, and input in other winodws is still possible.
00225     }
00226     else {
00227         std::cout << "Elastic Rod's Property Dialog is not available!" << std::endl;
00228         wxMessageDialog( NULL, "Elastic Rod's Property Dialog is not available!", "Not Found", wxOK ).ShowModal();
00229     }
00230 }
00231 
00232 
00233 // Set IDs -- find and link wxWidgets contrils with the local pointers
00234 void WXElasticRodParameters::SetIDs ()
00235 {
00236     m_bAllIDsWorking = true;
00237 
00238     // For physically based parameters
00239     m_pID_WXElasticRod_Length                   = (wxTextCtrl*) FindWindow( "ID_WXElasticRod_Length" );
00240     m_pID_WXElasticRod_Mass                     = (wxTextCtrl*) FindWindow( "ID_WXElasticRod_Mass" );
00241     m_pID_WXElasticRod_Radius                   = (wxTextCtrl*) FindWindow( "ID_WXElasticRod_Radius" );
00242     m_pID_WXElasticRod_NumOfLinks               = (wxTextCtrl*) FindWindow( "ID_WXElasticRod_NumOfLinks" );
00243     m_pID_WXElasticRod_StretchModulus           = (wxTextCtrl*) FindWindow( "ID_WXElasticRod_StretchModulus" );
00244     m_pID_WXElasticRod_BendModulus              = (wxTextCtrl*) FindWindow( "ID_WXElasticRod_BendModulus" );
00245     m_pID_WXElasticRod_ShearModulus             = (wxTextCtrl*) FindWindow( "ID_WXElasticRod_ShearModulus" );
00246     m_pID_WXElasticRod_MaterialDensity          = (wxTextCtrl*) FindWindow( "ID_WXElasticRod_MaterialDensity" );
00247     m_pID_WXElasticRod_KineticTranslational     = (wxTextCtrl*) FindWindow( "ID_WXElasticRod_KineticTranslational" );
00248     m_pID_WXElasticRod_KineticRotational_0      = (wxTextCtrl*) FindWindow( "ID_WXElasticRod_KineticRotational_0" );
00249     m_pID_WXElasticRod_KineticRotational_1      = (wxTextCtrl*) FindWindow( "ID_WXElasticRod_KineticRotational_1" );
00250     m_pID_WXElasticRod_KineticRotational_2      = (wxTextCtrl*) FindWindow( "ID_WXElasticRod_KineticRotational_2" );
00251     m_pID_WXElasticRod_DissipationTranslational = (wxTextCtrl*) FindWindow( "ID_WXElasticRod_DissipationTranslational" );
00252     m_pID_WXElasticRod_DissipationRotational_0  = (wxTextCtrl*) FindWindow( "ID_WXElasticRod_DissipationRotational_0" );
00253     m_pID_WXElasticRod_DissipationRotational_1  = (wxTextCtrl*) FindWindow( "ID_WXElasticRod_DissipationRotational_1" );
00254     m_pID_WXElasticRod_DissipationRotational_2  = (wxTextCtrl*) FindWindow( "ID_WXElasticRod_DissipationRotational_2" );
00255     m_pID_WXElasticRod_Constraint_3rdDirAlignCenterline = (wxTextCtrl*) FindWindow( "ID_WXElasticRod_Constraint_3rdDirAlignCenterline" );
00256     m_pID_WXElasticRod_Constraint_ScaleIntrinsicStrainRate = (wxTextCtrl*) FindWindow( "ID_WXElasticRod_Constraint_ScaleIntrinsicStrainRate" );
00257     m_pID_WXElasticRod_GravitationalConstant_slider                 = (wxSlider*) FindWindow( "ID_WXElasticRod_GravitationalConstant_slider" );
00258     m_pID_WXElasticRod_DampingVelocity          = (wxTextCtrl*) FindWindow( "ID_WXElasticRod_DampingVelocity" );
00259 
00260     if      ( !m_pID_WXElasticRod_Length )  m_bAllIDsWorking = false;
00261     else if ( !m_pID_WXElasticRod_Mass )    m_bAllIDsWorking = false;
00262     else if ( !m_pID_WXElasticRod_Radius )  m_bAllIDsWorking = false;
00263     else if ( !m_pID_WXElasticRod_NumOfLinks )  m_bAllIDsWorking = false;
00264     else if ( !m_pID_WXElasticRod_StretchModulus )  m_bAllIDsWorking = false;
00265     else if ( !m_pID_WXElasticRod_BendModulus ) m_bAllIDsWorking = false;
00266     else if ( !m_pID_WXElasticRod_ShearModulus )    m_bAllIDsWorking = false;
00267     else if ( !m_pID_WXElasticRod_MaterialDensity ) m_bAllIDsWorking = false;
00268     else if ( !m_pID_WXElasticRod_KineticTranslational )    m_bAllIDsWorking = false;
00269     else if ( !m_pID_WXElasticRod_KineticRotational_0 ) m_bAllIDsWorking = false;
00270     else if ( !m_pID_WXElasticRod_KineticRotational_1 ) m_bAllIDsWorking = false;
00271     else if ( !m_pID_WXElasticRod_KineticRotational_2 ) m_bAllIDsWorking = false;
00272     else if ( !m_pID_WXElasticRod_DissipationTranslational )    m_bAllIDsWorking = false;
00273     else if ( !m_pID_WXElasticRod_DissipationRotational_0 ) m_bAllIDsWorking = false;
00274     else if ( !m_pID_WXElasticRod_DissipationRotational_1 ) m_bAllIDsWorking = false;
00275     else if ( !m_pID_WXElasticRod_DissipationRotational_2 ) m_bAllIDsWorking = false;
00276     else if ( !m_pID_WXElasticRod_Constraint_3rdDirAlignCenterline )    m_bAllIDsWorking = false;
00277     else if ( !m_pID_WXElasticRod_Constraint_ScaleIntrinsicStrainRate ) m_bAllIDsWorking = false;
00278     else if ( !m_pID_WXElasticRod_GravitationalConstant_slider )                m_bAllIDsWorking = false;
00279     else if ( !m_pID_WXElasticRod_DampingVelocity ) m_bAllIDsWorking = false;
00280 
00281     if ( m_bAllIDsWorking ) {
00282         m_pID_WXElasticRod_Length->SetId( ID_WXElasticRod_Length );
00283         m_pID_WXElasticRod_Mass->SetId( ID_WXElasticRod_Mass );
00284         m_pID_WXElasticRod_Radius->SetId( ID_WXElasticRod_Radius );
00285         m_pID_WXElasticRod_NumOfLinks->SetId( ID_WXElasticRod_NumOfLinks );
00286         m_pID_WXElasticRod_StretchModulus->SetId( ID_WXElasticRod_StretchModulus );
00287         m_pID_WXElasticRod_BendModulus->SetId( ID_WXElasticRod_BendModulus );
00288         m_pID_WXElasticRod_ShearModulus->SetId( ID_WXElasticRod_ShearModulus );
00289         m_pID_WXElasticRod_MaterialDensity->SetId( ID_WXElasticRod_MaterialDensity );
00290         m_pID_WXElasticRod_KineticTranslational->SetId( ID_WXElasticRod_KineticTranslational );
00291         m_pID_WXElasticRod_KineticRotational_0->SetId( ID_WXElasticRod_KineticRotational_0 );
00292         m_pID_WXElasticRod_KineticRotational_1->SetId( ID_WXElasticRod_KineticRotational_1 );
00293         m_pID_WXElasticRod_KineticRotational_2->SetId( ID_WXElasticRod_KineticRotational_2 );
00294         m_pID_WXElasticRod_DissipationTranslational->SetId( ID_WXElasticRod_DissipationTranslational );
00295         m_pID_WXElasticRod_DissipationRotational_0->SetId( ID_WXElasticRod_DissipationRotational_0 );
00296         m_pID_WXElasticRod_DissipationRotational_1->SetId( ID_WXElasticRod_DissipationRotational_1 );
00297         m_pID_WXElasticRod_DissipationRotational_2->SetId( ID_WXElasticRod_DissipationRotational_2 );
00298         m_pID_WXElasticRod_Constraint_3rdDirAlignCenterline->SetId( ID_WXElasticRod_Constraint_3rdDirAlignCenterline );
00299         m_pID_WXElasticRod_Constraint_ScaleIntrinsicStrainRate->SetId( ID_WXElasticRod_Constraint_ScaleIntrinsicStrainRate );
00300         m_pID_WXElasticRod_GravitationalConstant_slider->SetId( ID_WXElasticRod_GravitationalConstant_slider );
00301         m_pID_WXElasticRod_DampingVelocity->SetId( ID_WXElasticRod_DampingVelocity );
00302     }
00303 
00304     // For simulation
00305     m_pID_WXElasticRod_EnableSelfCDR        = (wxCheckBox*) FindWindow( "ID_WXElasticRod_EnableSelfCDR" );
00306     m_pID_WXElasticRod_KselfCDR             = (wxTextCtrl*) FindWindow( "ID_WXElasticRod_KselfCDR" );
00307     m_pID_WXElasticRod_KselfCDR_Offset      = (wxTextCtrl*) FindWindow( "ID_WXElasticRod_KselfCDR_Offset" );
00308     m_pID_WXElasticRod_Display_Information  = (wxTextCtrl*) FindWindow( "ID_WXElasticRod_Display_Information" );
00309     #ifdef  TAPs_ADD_KNOT_RECOGNITION
00310     m_pID_WXElasticRod_EnableKR             = (wxCheckBox*) FindWindow( "ID_WXElasticRod_EnableKR" );
00311     m_pID_WXElasticRod_EnableKR_LockKnots   = (wxCheckBox*) FindWindow( "ID_WXElasticRod_EnableKR_LockKnots" );
00312     #endif//TAPs_ADD_KNOT_RECOGNITION
00313     #ifdef  TAPs_USE_CUDA
00314     m_pID_WXElasticRod_UseCUDA_PLHM             = (wxCheckBox*) FindWindow( "ID_WXElasticRod_UseCUDA_PLHM" );
00315     m_pID_WXElasticRod_EnableCUDA               = (wxCheckBox*) FindWindow( "ID_WXElasticRod_EnableCUDA" );
00316     m_pID_WXElasticRod_EnableCUDA_GenDrawData   = (wxCheckBox*) FindWindow( "ID_WXElasticRod_EnableCUDA_GenDrawData" );
00317     #endif//TAPs_USE_CUDA
00318     m_pID_WXElasticRod_Sim_TimeStep             = (wxTextCtrl*) FindWindow( "ID_WXElasticRod_Sim_TimeStep" );
00319     m_pID_WXElasticRod_CDRwBV_Cylinder_K    = (wxTextCtrl*) FindWindow( "ID_WXElasticRod_CDRwBV_Cylinder_K" );
00320     m_pID_WXElasticRod_CDRwBV_Sphere_K      = (wxTextCtrl*) FindWindow( "ID_WXElasticRod_CDRwBV_Sphere_K" );
00321     m_pID_WXElasticRod_CDRwTriangle_K       = (wxTextCtrl*) FindWindow( "ID_WXElasticRod_CDRwTriangle_K" );
00322     m_pID_WXElasticRod_CDRwBV_Cylinder_O    = (wxTextCtrl*) FindWindow( "ID_WXElasticRod_CDRwBV_Cylinder_O" );
00323     m_pID_WXElasticRod_CDRwBV_Sphere_O      = (wxTextCtrl*) FindWindow( "ID_WXElasticRod_CDRwBV_Sphere_O" );
00324     m_pID_WXElasticRod_CDRwTriangle_O       = (wxTextCtrl*) FindWindow( "ID_WXElasticRod_CDRwTriangle_O" );
00325 
00326     // For CDR with implicit objects
00327 #ifdef  TAPs_ADD_IMPLICIT_OBJECTS
00328     m_pID_WXElasticRod_CDRwImpObj_Sphere_K  = (wxTextCtrl*) FindWindow( "ID_WXElasticRod_CDRwImpObj_Sphere_K" );
00329     m_pID_WXElasticRod_CDRwImpObj_Sphere_O  = (wxTextCtrl*) FindWindow( "ID_WXElasticRod_CDRwImpObj_Sphere_O" );
00330     m_pID_WXElasticRod_CDRwImpObj_Torus_K   = (wxTextCtrl*) FindWindow( "ID_WXElasticRod_CDRwImpObj_Torus_K" );
00331     m_pID_WXElasticRod_CDRwImpObj_Torus_O   = (wxTextCtrl*) FindWindow( "ID_WXElasticRod_CDRwImpObj_Torus_O" );
00332 #endif//TAPs_ADD_IMPLICIT_OBJECTS
00333 
00334     if      ( !m_pID_WXElasticRod_EnableSelfCDR )       m_bAllIDsWorking = false;
00335     else if ( !m_pID_WXElasticRod_KselfCDR )            m_bAllIDsWorking = false;
00336     else if ( !m_pID_WXElasticRod_KselfCDR_Offset )     m_bAllIDsWorking = false;
00337     else if ( !m_pID_WXElasticRod_Display_Information ) m_bAllIDsWorking = false;
00338     #ifdef  TAPs_ADD_KNOT_RECOGNITION
00339     else if ( !m_pID_WXElasticRod_EnableKR )            m_bAllIDsWorking = false;
00340     else if ( !m_pID_WXElasticRod_EnableKR_LockKnots )  m_bAllIDsWorking = false;
00341     #endif//TAPs_ADD_KNOT_RECOGNITION
00342     #ifdef  TAPs_USE_CUDA
00343     else if ( !m_pID_WXElasticRod_UseCUDA_PLHM )            m_bAllIDsWorking = false;
00344     else if ( !m_pID_WXElasticRod_EnableCUDA )              m_bAllIDsWorking = false;
00345     else if ( !m_pID_WXElasticRod_EnableCUDA_GenDrawData )  m_bAllIDsWorking = false;
00346     #endif//TAPs_USE_CUDA
00347     else if ( !m_pID_WXElasticRod_Sim_TimeStep )            m_bAllIDsWorking = false;
00348     else if ( !m_pID_WXElasticRod_CDRwBV_Cylinder_K )   m_bAllIDsWorking = false;
00349     else if ( !m_pID_WXElasticRod_CDRwBV_Sphere_K )     m_bAllIDsWorking = false;
00350     else if ( !m_pID_WXElasticRod_CDRwTriangle_K )      m_bAllIDsWorking = false;
00351     else if ( !m_pID_WXElasticRod_CDRwBV_Cylinder_O )   m_bAllIDsWorking = false;
00352     else if ( !m_pID_WXElasticRod_CDRwBV_Sphere_O )     m_bAllIDsWorking = false;
00353     else if ( !m_pID_WXElasticRod_CDRwTriangle_O )      m_bAllIDsWorking = false;
00354 
00355     // For CDR with implicit objects
00356 #ifdef  TAPs_ADD_IMPLICIT_OBJECTS
00357     else if ( !m_pID_WXElasticRod_CDRwImpObj_Sphere_K ) m_bAllIDsWorking = false;
00358     else if ( !m_pID_WXElasticRod_CDRwImpObj_Sphere_O ) m_bAllIDsWorking = false;
00359     else if ( !m_pID_WXElasticRod_CDRwImpObj_Torus_K )  m_bAllIDsWorking = false;
00360     else if ( !m_pID_WXElasticRod_CDRwImpObj_Torus_O )  m_bAllIDsWorking = false;
00361 #endif//TAPs_ADD_IMPLICIT_OBJECTS
00362 
00363     if ( m_bAllIDsWorking ) {
00364         m_pID_WXElasticRod_EnableSelfCDR->SetId( ID_WXElasticRod_EnableSelfCDR );
00365         m_pID_WXElasticRod_KselfCDR->SetId( ID_WXElasticRod_KselfCDR );
00366         m_pID_WXElasticRod_KselfCDR_Offset->SetId( ID_WXElasticRod_KselfCDR_Offset );
00367         m_pID_WXElasticRod_Display_Information->SetId( ID_WXElasticRod_Display_Information );
00368         #ifdef  TAPs_ADD_KNOT_RECOGNITION
00369         m_pID_WXElasticRod_EnableKR->SetId( ID_WXElasticRod_EnableKR );
00370         m_pID_WXElasticRod_EnableKR_LockKnots->SetId( ID_WXElasticRod_EnableKR_LockKnots );
00371         #endif//TAPs_ADD_KNOT_RECOGNITION
00372         #ifdef  TAPs_USE_CUDA
00373         m_pID_WXElasticRod_UseCUDA_PLHM->SetId( ID_WXElasticRod_UseCUDA_PLHM );
00374         m_pID_WXElasticRod_EnableCUDA->SetId( ID_WXElasticRod_EnableCUDA );
00375         m_pID_WXElasticRod_EnableCUDA_GenDrawData->SetId( ID_WXElasticRod_EnableCUDA_GenDrawData );
00376         #endif//TAPs_USE_CUDA
00377         m_pID_WXElasticRod_Sim_TimeStep->SetId( ID_WXElasticRod_Sim_TimeStep );
00378         m_pID_WXElasticRod_CDRwBV_Cylinder_K->SetId( ID_WXElasticRod_CDRwBV_Cylinder_K );
00379         m_pID_WXElasticRod_CDRwBV_Sphere_K->SetId( ID_WXElasticRod_CDRwBV_Sphere_K );
00380         m_pID_WXElasticRod_CDRwTriangle_K->SetId( ID_WXElasticRod_CDRwTriangle_K );
00381         m_pID_WXElasticRod_CDRwBV_Cylinder_O->SetId( ID_WXElasticRod_CDRwBV_Cylinder_O );
00382         m_pID_WXElasticRod_CDRwBV_Sphere_O->SetId( ID_WXElasticRod_CDRwBV_Sphere_O );
00383         m_pID_WXElasticRod_CDRwTriangle_O->SetId( ID_WXElasticRod_CDRwTriangle_O );
00384 
00385         // For CDR with implicit objects
00386     #ifdef  TAPs_ADD_IMPLICIT_OBJECTS
00387         m_pID_WXElasticRod_CDRwImpObj_Sphere_K->SetId( ID_WXElasticRod_CDRwImpObj_Sphere_K );
00388         m_pID_WXElasticRod_CDRwImpObj_Sphere_O->SetId( ID_WXElasticRod_CDRwImpObj_Sphere_O );
00389         m_pID_WXElasticRod_CDRwImpObj_Torus_K->SetId( ID_WXElasticRod_CDRwImpObj_Torus_K );
00390         m_pID_WXElasticRod_CDRwImpObj_Torus_O->SetId( ID_WXElasticRod_CDRwImpObj_Torus_O );
00391     #endif//TAPs_ADD_IMPLICIT_OBJECTS
00392 
00393     }
00394 
00395     // For rendering
00396     m_pID_WXElasticRod_Render_NumOfVerticesPerCrossSection_slider   = (wxSlider*) FindWindow( "ID_WXElasticRod_Render_NumOfVerticesPerCrossSection_slider" );
00397     if  ( !m_pID_WXElasticRod_Render_NumOfVerticesPerCrossSection_slider )  m_bAllIDsWorking = false;
00398     if  ( m_bAllIDsWorking ) {
00399         m_pID_WXElasticRod_Render_NumOfVerticesPerCrossSection_slider->SetId( ID_WXElasticRod_Render_NumOfVerticesPerCrossSection_slider );
00400     }
00401 
00402     // For load/save preset and user set
00403     m_pID_WXElasticRod_Load_Preset                  = (wxComboBox*) FindWindow( "ID_WXElasticRod_Load_Preset" );
00404     m_pID_WXElasticRod_Load_Userset                 = (wxComboBox*) FindWindow( "ID_WXElasticRod_Load_Userset" );
00405     m_pID_WXElasticRod_Save_Userset_Btn             = (wxButton*)   FindWindow( "ID_WXElasticRod_Save_Userset_Btn" );
00406     m_pID_WXElasticRod_Save_Userset_Name            = (wxTextCtrl*) FindWindow( "ID_WXElasticRod_Save_Userset_Name" );
00407     m_pID_WXElasticRod_Current_Load_Parameter_Set   = (wxTextCtrl*) FindWindow( "ID_WXElasticRod_Current_Load_Parameter_Set" );
00408 
00409     if      ( !m_pID_WXElasticRod_Load_Preset ) m_bAllIDsWorking = false;
00410     else if ( !m_pID_WXElasticRod_Load_Userset )    m_bAllIDsWorking = false;
00411     else if ( !m_pID_WXElasticRod_Save_Userset_Btn )    m_bAllIDsWorking = false;
00412     else if ( !m_pID_WXElasticRod_Save_Userset_Name )   m_bAllIDsWorking = false;
00413     else if ( !m_pID_WXElasticRod_Current_Load_Parameter_Set )  m_bAllIDsWorking = false;
00414 
00415     if ( m_bAllIDsWorking ) {
00416         m_pID_WXElasticRod_Load_Preset->SetId( ID_WXElasticRod_Load_Preset );
00417         m_pID_WXElasticRod_Load_Userset->SetId( ID_WXElasticRod_Load_Userset );
00418         m_pID_WXElasticRod_Save_Userset_Btn->SetId( ID_WXElasticRod_Save_Userset_Btn );
00419         m_pID_WXElasticRod_Save_Userset_Name->SetId( ID_WXElasticRod_Save_Userset_Name );
00420         m_pID_WXElasticRod_Current_Load_Parameter_Set->SetId( ID_WXElasticRod_Current_Load_Parameter_Set );
00421     }
00422 }
00423 
00424 
00425 // Initailize the looks of controls
00426 void WXElasticRodParameters::InitControlLooks ()
00427 {
00428     ElasticRodParameters<double> * parDouble = static_cast<ElasticRodParameters<double> *>( m_pERParameters );
00429     ElasticRodParameters<float> * parFloat   = static_cast<ElasticRodParameters<float> *>( m_pERParameters );
00430 
00431     // Self Collision Detection
00432     {
00433         bool isSelfCDR;
00434         if ( std::string( "double" ).compare( g_pDataTypeInfo->name() ) == 0 ) {
00435             isSelfCDR = parDouble->EnableSelfCDR;
00436         }
00437         else if ( std::string( "float" ).compare( g_pDataTypeInfo->name() ) == 0 ) {
00438             isSelfCDR = parFloat->EnableSelfCDR;
00439         }
00440         else {
00441             std::cout << g_pDataTypeInfo->name() << " type is not supported!\n";
00442         }
00443         m_pID_WXElasticRod_EnableSelfCDR->SetValue( isSelfCDR );
00444         m_pID_WXElasticRod_KselfCDR->Show( true );
00445         m_pID_WXElasticRod_KselfCDR->Enable( isSelfCDR );
00446         m_pID_WXElasticRod_KselfCDR_Offset->Enable( isSelfCDR );
00447     }
00448 
00449     // Knot Recognition
00450     #ifdef  TAPs_ADD_KNOT_RECOGNITION
00451     {
00452         bool isKR;
00453         bool isKR_LockKnots;
00454         if ( std::string( "double" ).compare( g_pDataTypeInfo->name() ) == 0 ) {
00455             isKR = parDouble->EnableKR;
00456             isKR_LockKnots = parDouble->EnableKR_LockKnots;
00457         }
00458         else if ( std::string( "float" ).compare( g_pDataTypeInfo->name() ) == 0 ) {
00459             isKR = parFloat->EnableKR;
00460             isKR_LockKnots = parFloat->EnableKR_LockKnots;
00461         }
00462         else {
00463             std::cout << g_pDataTypeInfo->name() << " type is not supported!\n";
00464         }
00465         m_pID_WXElasticRod_EnableKR->SetValue( isKR );
00466         m_pID_WXElasticRod_EnableKR_LockKnots->Enable( isKR );
00467         m_pID_WXElasticRod_EnableKR_LockKnots->SetValue( isKR_LockKnots );
00468     }
00469     #else //TAPs_ADD_KNOT_RECOGNITION
00470     {
00471         // Remove the GUI controls for knot recognition
00472         wxSizer * sizer_ER_sim = (wxSizer*) FindWindow( "sizer_ER_SimulationParameters" );
00473         wxSizer * sizer_ER_KR  = (wxSizer*) FindWindow( "sizer_ER_KR" );
00474         bool isFound = true;
00475         if ( !sizer_ER_sim ) {
00476             std::cout << "!NOT FOUND! the wxSizer named sizer_ER_SimulationParameters\n";
00477             isFound = false;
00478         }
00479         if ( !sizer_ER_KR ) {
00480             std::cout << "!NOT FOUND! the wxSizer named sizer_ER_KR\n";
00481             isFound = false;
00482         }
00483         if ( isFound ) {
00484             sizer_ER_sim->Detach( sizer_ER_KR );
00485         }
00486         else {
00487             wxStaticText * label_EnableKR = (wxStaticText*) FindWindow( "label_EnableKR" );
00488             wxCheckBox * chkBox_EnableKR = (wxCheckBox*) FindWindow( "ID_WXElasticRod_EnableKR" );
00489             wxStaticText * label_EnableKR_LockKnots = (wxStaticText*) FindWindow( "label_EnableKR_LockKnots" );
00490             wxCheckBox * chkBox_EnableKR_LockKnots = (wxCheckBox*) FindWindow( "ID_WXElasticRod_EnableKR_LockKnots" );
00491             if ( label_EnableKR ) {
00492                 label_EnableKR->Disable();
00493                 label_EnableKR->SetSize( 0, 0 );
00494             }
00495             if ( chkBox_EnableKR ) {
00496                 chkBox_EnableKR->Disable();
00497                 chkBox_EnableKR->SetSize( 0, 0 );
00498             }
00499             if ( label_EnableKR_LockKnots ) {
00500                 label_EnableKR_LockKnots->Disable();
00501                 label_EnableKR_LockKnots->SetSize( 0, 0 );
00502             }
00503             if ( chkBox_EnableKR_LockKnots ) {
00504                 chkBox_EnableKR_LockKnots->Disable();
00505                 chkBox_EnableKR_LockKnots->SetSize( 0, 0 );
00506             }
00507         }
00508     }
00509     #endif//TAPs_ADD_KNOT_RECOGNITION
00510 
00511     // Use CUDA
00512     #ifdef  TAPs_USE_CUDA
00513     {
00514         // DEBUG
00515         //wxSizer * sizer_ER_CUDA  = (wxSizer*) FindWindow( "sizer_ER_CUDA" );
00516         //if ( sizer_ER_CUDA )  std::cout << "FOUND sizer_ER_CUDA \n";
00517         //else                  std::cout << "NOT FOUND sizer_ER_CUDA \n";
00518 
00519         bool isCUDA;
00520         bool isCUDA_GenDrawData;
00521         if ( std::string( "double" ).compare( g_pDataTypeInfo->name() ) == 0 ) {
00522             isCUDA = parDouble->EnableCUDA;
00523             isCUDA_GenDrawData = parDouble->EnableCUDA_GenDrawData ;
00524         }
00525         else if ( std::string( "float" ).compare( g_pDataTypeInfo->name() ) == 0 ) {
00526             isCUDA = parFloat->EnableCUDA;
00527             isCUDA_GenDrawData = parFloat->EnableCUDA_GenDrawData ;
00528         }
00529         else {
00530             std::cout << g_pDataTypeInfo->name() << " type is not supported!\n";
00531         }
00532         m_pID_WXElasticRod_UseCUDA_PLHM->SetValue( m_bUseCUDA_PLHM );
00533         m_pID_WXElasticRod_UseCUDA_PLHM->Enable( false );
00534         m_pID_WXElasticRod_EnableCUDA->SetValue( isCUDA );
00535         m_pID_WXElasticRod_EnableCUDA_GenDrawData->SetValue( isCUDA_GenDrawData );
00536         m_pID_WXElasticRod_EnableCUDA_GenDrawData->Enable( isCUDA );
00537     }
00538     #else //TAPs_USE_CUDA
00539     {
00540         // Remove the GUI controls for knot recognition
00541         wxSizer * sizer_ER_sim = (wxSizer*) FindWindow( "sizer_ER_SimulationParameters" );
00542         wxSizer * sizer_ER_CUDA  = (wxSizer*) FindWindow( "sizer_ER_CUDA" );
00543         bool isFound = true;
00544         if ( !sizer_ER_sim ) {
00545             std::cout << "!NOT FOUND! the wxSizer named sizer_ER_SimulationParameters\n";
00546             isFound = false;
00547         }
00548         if ( !sizer_ER_CUDA ) {
00549             std::cout << "!NOT FOUND! the wxSizer named sizer_ER_CUDA\n";
00550             isFound = false;
00551         }
00552         if ( isFound ) {
00553             sizer_ER_sim->Detach( sizer_ER_CUDA );
00554         }
00555         else {
00556             wxStaticText * label_EnableCUDA = (wxStaticText*) FindWindow( "label_EnableCUDA" );
00557             wxCheckBox * chkBox_EnableCUDA = (wxCheckBox*) FindWindow( "ID_WXElasticRod_EnableCUDA" );
00558             wxStaticText * label_UseCUDA_PLHM = (wxStaticText*) FindWindow( "label_UseCUDA_PLHM" );
00559             wxCheckBox * chkBox_UseCUDA_PLHM = (wxCheckBox*) FindWindow( "ID_WXElasticRod_UseCUDA_PLHM" );
00560             wxStaticText * label_EnableCUDA_GenDrawData = (wxStaticText*) FindWindow( "label_EnableCUDA_GenDrawData" );
00561             wxCheckBox * chkBox_EnableCUDA_GenDrawData = (wxCheckBox*) FindWindow( "ID_WXElasticRod_EnableCUDA_GenDrawData" );
00562             if ( label_EnableCUDA ) {
00563                 label_EnableCUDA->Disable();
00564                 label_EnableCUDA->SetSize( 0, 0 );
00565             }
00566             if ( chkBox_EnableCUDA ) {
00567                 chkBox_EnableCUDA->Disable();
00568                 chkBox_EnableCUDA->SetSize( 0, 0 );
00569             }
00570             if ( label_UseCUDA_PLHM ) {
00571                 label_UseCUDA_PLHM->Disable();
00572                 label_UseCUDA_PLHM->SetSize( 0, 0 );
00573             }
00574             if ( chkBox_UseCUDA_PLHM ) {
00575                 chkBox_UseCUDA_PLHM->Disable();
00576                 chkBox_UseCUDA_PLHM->SetSize( 0, 0 );
00577             }
00578             if ( label_EnableCUDA_GenDrawData ) {
00579                 label_EnableCUDA_GenDrawData->Disable();
00580                 label_EnableCUDA_GenDrawData->SetSize( 0, 0 );
00581             }
00582             if ( chkBox_EnableCUDA_GenDrawData ) {
00583                 chkBox_EnableCUDA_GenDrawData->Disable();
00584                 chkBox_EnableCUDA_GenDrawData->SetSize( 0, 0 );
00585             }
00586         }
00587     }
00588     #endif//TAPs_USE_CUDA
00589 }
00590 
00591 
00592 // Initailize the list of preset and userset, so that the user can select a parameter set from the GUI
00593 void WXElasticRodParameters::InitListOfPresetAndUserset ()
00594 {
00595     if ( std::string( "double" ).compare( g_pDataTypeInfo->name() ) == 0 ) {
00596         LoadListOfParameterSetsFromFile<double>( g_vdPresets );
00597         LoadListOfParameterSetsFromFile<double>( g_vdUsersets );
00598     }
00599     else if ( std::string( "float" ).compare( g_pDataTypeInfo->name() ) == 0 ) {
00600         LoadListOfParameterSetsFromFile<float>( g_vfPresets );
00601         LoadListOfParameterSetsFromFile<float>( g_vfUsersets );
00602     }
00603     else {
00604         std::cout << g_pDataTypeInfo->name() << " type is not supported!\n";
00605     }
00606 }
00607 
00608 
00609 // Read parameters from file and save them as parameter sets in memory
00610 template <typename T>
00611 void WXElasticRodParameters::LoadListOfParameterSetsFromFile (  std::vector< ElasticRodParameters<T> > & parSets )
00612 {
00613     TextFile * pTF;
00614     wxComboBox * pCB;
00615     if ( (void*)(&parSets) == (void*)(&g_vfPresets) || (void*)(&parSets) == (void*)(&g_vdPresets) ) {
00616         pTF = &g_PresetFile;
00617         pCB = m_pID_WXElasticRod_Load_Preset;
00618     }
00619     else {
00620         pTF = &g_UsersetFile;
00621         pCB = m_pID_WXElasticRod_Load_Userset;
00622     }
00623     if ( pCB == NULL )  return;
00624 
00625     // Load the parameter sets
00626     std::string parameter;
00627     //pTF->Read();
00628     const std::string delims( " ,\t" );
00629     std::string::size_type begIdx, endIdx;
00630     std::string strName, strValue;
00631 
00632     int idx = 0;    // index for accesing the parameter set
00633     for ( int i = 0; i < pTF->GetNumOfLines(); ++i ) {
00634         parameter = pTF->GetLine( i );
00635         // Search beginning of the first word
00636         begIdx = parameter.find_first_not_of( delims );
00637         // While beginning of a word found
00638         while ( begIdx != std::string::npos ) {
00639             // Search end of the actual word
00640             endIdx = parameter.find_first_of( delims, begIdx );
00641             if ( endIdx == std::string::npos ) {
00642                 // End of word is end of line
00643                 endIdx = parameter.length();
00644             }
00645             //-------------------------------------------------------
00646             // Process Parameter(s) -- Treat # as comment
00647             if ( !(parameter[begIdx] == '#') ) {
00648                 strName = parameter.substr( begIdx, endIdx );
00649                 //std::cout << idx << " strName: " << strName << "\n";
00650                 //----------------------------------------------
00651                 if      ( "Name" == strName ) {
00652                     // Get the name of the parameter set
00653                     begIdx = parameter.find_first_of( "\"", endIdx );
00654                     ++begIdx;
00655                     endIdx = parameter.find_first_of( "\"", begIdx );
00656                     ElasticRodParameters<T> parSet = *(static_cast<ElasticRodParameters<T> *>( m_pERParameters ));
00657                     parSet.Name = parameter.substr( begIdx, endIdx-begIdx );
00658 
00659                     // Insert this parameter set into the list in alphabetical order (low-to-high)
00660                     if ( parSets.size() > 0 ) {
00661                         int insertPos = 0;
00662                         std::vector< ElasticRodParameters<T> >::iterator it = parSets.begin();
00663                         bool isNotInserted = true;
00664                         idx = 0;
00665                         while ( it != parSets.end() ) {
00666                             if ( 0 < it->Name.compare( parSet.Name ) ) {
00667                                 parSets.insert( it, parSet );
00668                                 isNotInserted = false;
00669                                 idx;
00670                                 break;
00671                             }
00672                             ++it; ++idx;
00673                         }
00674                         if ( isNotInserted ) {
00675                             // the current last element
00676                             parSets.push_back( parSet );
00677                             idx = parSets.size() - 1;
00678                         }
00679                     }
00680                     else {
00681                         // the first element
00682                         parSets.push_back( parSet );
00683                         idx = 0;
00684                     }
00685                 }
00686                 //else if   ( "NumOfLinks" == strName ) {
00687                 //  begIdx = parameter.find_first_not_of( delims, endIdx );
00688                 //  endIdx = parameter.find_first_of( delims, begIdx );
00689                 //  parSets[idx].NumOfNodes = atoi( parameter.substr( begIdx, endIdx ).c_str() ) + 1;
00690                 //}
00691                 else if ( "Radius" == strName ) {
00692                     begIdx = parameter.find_first_not_of( delims, endIdx );
00693                     endIdx = parameter.find_first_of( delims, begIdx );
00694                     parSets[idx].Radius = atof( parameter.substr( begIdx, endIdx ).c_str() );
00695                 }
00696                 //else if   ( "Mass" == strName ) {
00697                 //  begIdx = parameter.find_first_not_of( delims, endIdx );
00698                 //  endIdx = parameter.find_first_of( delims, begIdx );
00699                 //  parSets[idx].TotalMass = atof( parameter.substr( begIdx, endIdx ).c_str() );
00700                 //}
00701                 //else if   ( "Length" == strName ) {
00702                 //  begIdx = parameter.find_first_not_of( delims, endIdx );
00703                 //  endIdx = parameter.find_first_of( delims, begIdx );
00704                 //  parSets[idx].TotalLength = atof( parameter.substr( begIdx, endIdx ).c_str() );
00705                 //}
00706                 else if ( "K_Kinetic_Translational" == strName ) {
00707                     begIdx = parameter.find_first_not_of( delims, endIdx );
00708                     endIdx = parameter.find_first_of( delims, begIdx );
00709                     parSets[idx].Kt = atof( parameter.substr( begIdx, endIdx ).c_str() );
00710                 }
00711                 else if ( "K_Kinetic_Rotational" == strName ) {
00712                     for ( int d = 0; d < 3; ++d ) {
00713                         begIdx = parameter.find_first_not_of( delims, endIdx );
00714                         endIdx = parameter.find_first_of( delims, begIdx );
00715                         parSets[idx].Kr[d] = atof( parameter.substr( begIdx, endIdx ).c_str() );
00716                     }
00717                 }
00718                 else if ( "K_Dissipation_Translational" == strName ) {
00719                     begIdx = parameter.find_first_not_of( delims, endIdx );
00720                     endIdx = parameter.find_first_of( delims, begIdx );
00721                     parSets[idx].Dt = atof( parameter.substr( begIdx, endIdx ).c_str() );
00722                 }
00723                 else if ( "K_Dissipation_Rotational" == strName ) {
00724                     for ( int d = 0; d < 3; ++d ) {
00725                         begIdx = parameter.find_first_not_of( delims, endIdx );
00726                         endIdx = parameter.find_first_of( delims, begIdx );
00727                         parSets[idx].Dr[d] = atof( parameter.substr( begIdx, endIdx ).c_str() );
00728                     }
00729                 }
00730                 else if ( "K_Constraint_3rdDirAlignTangent" == strName ) {
00731                     begIdx = parameter.find_first_not_of( delims, endIdx );
00732                     endIdx = parameter.find_first_of( delims, begIdx );
00733                     parSets[idx].Kconstraint_3rdDirAlignTangent = atof( parameter.substr( begIdx, endIdx ).c_str() );
00734                 }
00735                 else if ( "K_Damping_Velocity" == strName ) {
00736                     begIdx = parameter.find_first_not_of( delims, endIdx );
00737                     endIdx = parameter.find_first_of( delims, begIdx );
00738                     parSets[idx].Kvdamping = 1.0 - atof( parameter.substr( begIdx, endIdx ).c_str() );
00739                 }
00740                 else if ( "K_Stretching_Modulus" == strName ) {
00741                     begIdx = parameter.find_first_not_of( delims, endIdx );
00742                     endIdx = parameter.find_first_of( delims, begIdx );
00743                     parSets[idx].Kstretch_modulus = atof( parameter.substr( begIdx, endIdx ).c_str() );
00744                 }
00745                 else if ( "K_Bending_Modulus" == strName ) {
00746                     begIdx = parameter.find_first_not_of( delims, endIdx );
00747                     endIdx = parameter.find_first_of( delims, begIdx );
00748                     parSets[idx].Kbend_modulus = atof( parameter.substr( begIdx, endIdx ).c_str() );
00749                 }
00750                 else if ( "K_Shear_Modulus" == strName ) {
00751                     begIdx = parameter.find_first_not_of( delims, endIdx );
00752                     endIdx = parameter.find_first_of( delims, begIdx );
00753                     parSets[idx].Kshear_modulus = atof( parameter.substr( begIdx, endIdx ).c_str() );
00754                 }
00755                 else if ( "K_Material_Density" == strName ) {
00756                     begIdx = parameter.find_first_not_of( delims, endIdx );
00757                     endIdx = parameter.find_first_of( delims, begIdx );
00758                     parSets[idx].MaterialDensity = atof( parameter.substr( begIdx, endIdx ).c_str() );
00759                 }
00760                 //else if   ( "SimTimeStep" == strName ) {
00761                 //  begIdx = parameter.find_first_not_of( delims, endIdx );
00762                 //  endIdx = parameter.find_first_of( delims, begIdx );
00763                 //  parSets[idx]. = atof( parameter.substr( begIdx, endIdx ).c_str() );
00764                 //}
00765                 //else if   ( "First_Point_Position" == strName ) {
00766                 //  for ( int d = 0; d < 3; ++d ) {
00767                 //      begIdx = parameter.find_first_not_of( delims, endIdx );
00768                 //      endIdx = parameter.find_first_of( delims, begIdx );
00769                 //      parSets[idx].[d] = atof( parameter.substr( begIdx, endIdx ).c_str() );
00770                 //  }
00771                 //}
00772                 else if ( "K_Self_CDR" == strName ) {
00773                     begIdx = parameter.find_first_not_of( delims, endIdx );
00774                     endIdx = parameter.find_first_of( delims, begIdx );
00775                     parSets[idx].KselfCDR = atof( parameter.substr( begIdx, endIdx ).c_str() );
00776                 }
00777             }
00778             begIdx = std::string::npos;
00779         }
00780     }
00781 
00782     // Set the list in the ComboBox
00783     for ( unsigned int i = 0; i < parSets.size(); ++i ) {
00784         pCB->Append( parSets[i].Name );
00785 
00786         // Calculate the parameter values
00787         // The NumOfNodes value is copied from the current parameter set
00788         // Here recalculate the LinkLength, MassOfPoint, and some of other parameters 
00789         // that are depending on the values of other parameters.
00790         parSets[i].CalDependentParameters();
00791 
00792         //std::cout << "Set# " << i << "\n" << parSets[i] << "\n";
00793     }
00794 }
00795 
00796 
00797 // Process events for editing a value for physically based parameters
00798 void WXElasticRodParameters::OnEnteringPhysicallyBasedParameters ( wxCommandEvent & event )
00799 {
00800     switch ( event.GetId() ) {
00801         case ID_WXElasticRod_Length:
00802             m_pID_WXElasticRod_Length->SetForegroundColour( color_textEdit );
00803             break;
00804         case ID_WXElasticRod_Mass:
00805             m_pID_WXElasticRod_Mass->SetForegroundColour( color_textEdit );
00806             break;
00807         case ID_WXElasticRod_Radius:
00808             m_pID_WXElasticRod_Radius->SetForegroundColour( color_textEdit );
00809             break;
00810         //case ID_WXElasticRod_NumOfLinks:
00811         //  m_pID_WXElasticRod_NumOfLinks->SetForegroundColour( color_textEdit );
00812         //  break;
00813         case ID_WXElasticRod_StretchModulus:
00814             m_pID_WXElasticRod_StretchModulus->SetForegroundColour( color_textEdit );
00815             break;
00816         case ID_WXElasticRod_BendModulus:
00817             m_pID_WXElasticRod_BendModulus->SetForegroundColour( color_textEdit );
00818             break;
00819         case ID_WXElasticRod_ShearModulus:
00820             m_pID_WXElasticRod_ShearModulus->SetForegroundColour( color_textEdit );
00821             break;
00822         case ID_WXElasticRod_MaterialDensity:
00823             m_pID_WXElasticRod_MaterialDensity->SetForegroundColour( color_textEdit );
00824             break;
00825         case ID_WXElasticRod_KineticTranslational:
00826             m_pID_WXElasticRod_KineticTranslational->SetForegroundColour( color_textEdit );
00827             break;
00828         case ID_WXElasticRod_KineticRotational_0:
00829             m_pID_WXElasticRod_KineticRotational_0->SetForegroundColour( color_textEdit );
00830             break;
00831         case ID_WXElasticRod_KineticRotational_1:
00832             m_pID_WXElasticRod_KineticRotational_1->SetForegroundColour( color_textEdit );
00833             break;
00834         case ID_WXElasticRod_KineticRotational_2:
00835             m_pID_WXElasticRod_KineticRotational_2->SetForegroundColour( color_textEdit );
00836             break;
00837         case ID_WXElasticRod_DissipationTranslational:
00838             m_pID_WXElasticRod_DissipationTranslational->SetForegroundColour( color_textEdit );
00839             break;
00840         case ID_WXElasticRod_DissipationRotational_0:
00841             m_pID_WXElasticRod_DissipationRotational_0->SetForegroundColour( color_textEdit );
00842             break;
00843         case ID_WXElasticRod_DissipationRotational_1:
00844             m_pID_WXElasticRod_DissipationRotational_1->SetForegroundColour( color_textEdit );
00845             break;
00846         case ID_WXElasticRod_DissipationRotational_2:
00847             m_pID_WXElasticRod_DissipationRotational_2->SetForegroundColour( color_textEdit );
00848             break;
00849         case ID_WXElasticRod_Constraint_3rdDirAlignCenterline:
00850             m_pID_WXElasticRod_Constraint_3rdDirAlignCenterline->SetForegroundColour( color_textEdit );
00851             break;
00852         case ID_WXElasticRod_Constraint_ScaleIntrinsicStrainRate:
00853             m_pID_WXElasticRod_Constraint_ScaleIntrinsicStrainRate->SetForegroundColour( color_textEdit );
00854             break;
00855         case ID_WXElasticRod_DampingVelocity:
00856             m_pID_WXElasticRod_DampingVelocity->SetForegroundColour( color_textEdit );
00857             break;
00858     }
00859 }
00860 
00861 
00862 // Process events for changing physically based parameters
00863 void WXElasticRodParameters::OnChangingPhysicallyBasedParameters ( wxCommandEvent & event )
00864 {
00865     if ( std::string( "double" ).compare( g_pDataTypeInfo->name() ) == 0 ) {
00866         WritePhysicallyBasedParameters<double>( event );
00867     }
00868     else if ( std::string( "float" ).compare( g_pDataTypeInfo->name() ) == 0 ) {
00869         WritePhysicallyBasedParameters<float>( event );
00870     }
00871     else {
00872         std::cout << g_pDataTypeInfo->name() << " type is not supported!\n";
00873     }
00874     //Update();
00875 }
00876 
00877 
00878 // Process events for editing a value for simulation parameters
00879 void WXElasticRodParameters::OnEnteringSimulationParameters ( wxCommandEvent & event )
00880 {
00881     ElasticRodParameters<double> * parDouble = static_cast<ElasticRodParameters<double> *>( m_pERParameters );
00882     ElasticRodParameters<float> * parFloat   = static_cast<ElasticRodParameters<float> *>( m_pERParameters );
00883 
00884     // Self Collision Detection
00885     {
00886         bool isSelfCDR = m_pID_WXElasticRod_EnableSelfCDR->IsChecked();
00887         switch ( event.GetId() ) {
00888             case ID_WXElasticRod_EnableSelfCDR:
00889                 if ( std::string( "double" ).compare( g_pDataTypeInfo->name() ) == 0 ) {
00890                     parDouble->EnableSelfCDR = isSelfCDR;
00891                 }
00892                 else if ( std::string( "float" ).compare( g_pDataTypeInfo->name() ) == 0 ) {
00893                     parFloat->EnableSelfCDR = isSelfCDR;
00894                 }
00895                 else {
00896                     std::cout << g_pDataTypeInfo->name() << " type is not supported!\n";
00897                 }
00898                 m_pID_WXElasticRod_KselfCDR->Enable( isSelfCDR );
00899                 m_pID_WXElasticRod_KselfCDR_Offset->Enable( isSelfCDR );
00900                 break;
00901         #ifdef  TAPs_SIM_WITH_POSITION_BASED_DYNAMICS
00902         #else //TAPs_SIM_WITH_POSITION_BASED_DYNAMICS
00903             case ID_WXElasticRod_KselfCDR:
00904                 m_pID_WXElasticRod_KselfCDR->SetForegroundColour( color_textEdit );
00905                 m_pID_WXElasticRod_KselfCDR_Offset->SetForegroundColour( color_textEdit );
00906                 break;
00907         #endif//TAPs_SIM_WITH_POSITION_BASED_DYNAMICS
00908             case ID_WXElasticRod_Sim_TimeStep:
00909                 m_pID_WXElasticRod_Sim_TimeStep->SetForegroundColour( color_textEdit );
00910                 break;
00911             case ID_WXElasticRod_CDRwBV_Cylinder_K:
00912                 m_pID_WXElasticRod_CDRwBV_Cylinder_K->SetForegroundColour( color_textEdit );
00913                 break;
00914             case ID_WXElasticRod_CDRwBV_Sphere_K:
00915                 m_pID_WXElasticRod_CDRwBV_Sphere_K->SetForegroundColour( color_textEdit );
00916                 break;
00917             case ID_WXElasticRod_CDRwTriangle_K:
00918                 m_pID_WXElasticRod_CDRwTriangle_K->SetForegroundColour( color_textEdit );
00919                 break;
00920             case ID_WXElasticRod_CDRwBV_Cylinder_O:
00921                 m_pID_WXElasticRod_CDRwBV_Cylinder_O->SetForegroundColour( color_textEdit );
00922                 break;
00923             case ID_WXElasticRod_CDRwBV_Sphere_O:
00924                 m_pID_WXElasticRod_CDRwBV_Sphere_O->SetForegroundColour( color_textEdit );
00925                 break;
00926             case ID_WXElasticRod_CDRwTriangle_O:
00927                 m_pID_WXElasticRod_CDRwTriangle_O->SetForegroundColour( color_textEdit );
00928                 break;
00929 
00930             // For CDR with implicit objects
00931         #ifdef  TAPs_ADD_IMPLICIT_OBJECTS
00932             case ID_WXElasticRod_CDRwImpObj_Sphere_K:
00933                 m_pID_WXElasticRod_CDRwImpObj_Sphere_K->SetForegroundColour( color_textEdit );
00934                 break;
00935             case ID_WXElasticRod_CDRwImpObj_Sphere_O:
00936                 m_pID_WXElasticRod_CDRwImpObj_Sphere_O->SetForegroundColour( color_textEdit );
00937                 break;
00938             case ID_WXElasticRod_CDRwImpObj_Torus_K:
00939                 m_pID_WXElasticRod_CDRwImpObj_Torus_K->SetForegroundColour( color_textEdit );
00940                 break;
00941             case ID_WXElasticRod_CDRwImpObj_Torus_O:
00942                 m_pID_WXElasticRod_CDRwImpObj_Torus_O->SetForegroundColour( color_textEdit );
00943                 break;
00944         #endif//TAPs_ADD_IMPLICIT_OBJECTS
00945         }
00946     }
00947 
00948     // Knot Recognition
00949     #ifdef  TAPs_ADD_KNOT_RECOGNITION
00950     {
00951         bool isKR = m_pID_WXElasticRod_EnableKR->IsChecked();
00952         bool isKR_LockKnots = m_pID_WXElasticRod_EnableKR_LockKnots->IsChecked();
00953         switch ( event.GetId() ) {
00954             case ID_WXElasticRod_EnableKR:
00955                 if ( std::string( "double" ).compare( g_pDataTypeInfo->name() ) == 0 ) {
00956                     parDouble->EnableKR = isKR;
00957                 }
00958                 else if ( std::string( "float" ).compare( g_pDataTypeInfo->name() ) == 0 ) {
00959                     parFloat->EnableKR = isKR;
00960                 }
00961                 else {
00962                     std::cout << g_pDataTypeInfo->name() << " type is not supported!\n";
00963                 }
00964                 m_pID_WXElasticRod_EnableKR_LockKnots->Enable( isKR );
00965                 break;
00966             case ID_WXElasticRod_EnableKR_LockKnots:
00967                 if ( std::string( "double" ).compare( g_pDataTypeInfo->name() ) == 0 ) {
00968                     parDouble->EnableKR_LockKnots = isKR_LockKnots;
00969                 }
00970                 else if ( std::string( "float" ).compare( g_pDataTypeInfo->name() ) == 0 ) {
00971                     parFloat->EnableKR_LockKnots = isKR_LockKnots;
00972                 }
00973                 else {
00974                     std::cout << g_pDataTypeInfo->name() << " type is not supported!\n";
00975                 }
00976                 break;
00977         }
00978     }
00979     #endif//TAPs_ADD_KNOT_RECOGNITION
00980 
00981     #ifdef  TAPs_USE_CUDA
00982     {
00983         bool isCUDA = m_pID_WXElasticRod_EnableCUDA->IsChecked();
00984         bool isCUDA_GenDrawData = m_pID_WXElasticRod_EnableCUDA_GenDrawData->IsChecked();
00985         std::cout << "isCUDA: " << isCUDA << "\n";
00986         std::cout << "isCUDA_GenDrawData: " << isCUDA_GenDrawData << "\n";
00987         switch ( event.GetId() ) {
00988             case ID_WXElasticRod_EnableCUDA:
00989                 if ( std::string( "double" ).compare( g_pDataTypeInfo->name() ) == 0 ) {
00990                     parDouble->EnableCUDA = isCUDA;
00991                 }
00992                 else if ( std::string( "float" ).compare( g_pDataTypeInfo->name() ) == 0 ) {
00993                     parFloat->EnableCUDA = isCUDA;
00994                 }
00995                 else {
00996                     std::cout << g_pDataTypeInfo->name() << " type is not supported!\n";
00997                 }
00998                 m_pID_WXElasticRod_EnableCUDA_GenDrawData->Enable( isCUDA );
00999                 break;
01000             case ID_WXElasticRod_EnableCUDA_GenDrawData:
01001                 if ( std::string( "double" ).compare( g_pDataTypeInfo->name() ) == 0 ) {
01002                     parDouble->EnableCUDA_GenDrawData = isCUDA_GenDrawData;
01003                 }
01004                 else if ( std::string( "float" ).compare( g_pDataTypeInfo->name() ) == 0 ) {
01005                     parFloat->EnableCUDA_GenDrawData = isCUDA_GenDrawData;
01006                 }
01007                 else {
01008                     std::cout << g_pDataTypeInfo->name() << " type is not supported!\n";
01009                 }
01010                 break;
01011         }
01012     }
01013     #endif//TAPs_USE_CUDA
01014 }
01015 
01016 
01017 // Process events for changing simulation parameters
01018 void WXElasticRodParameters::OnChangingSimulationParameters ( wxCommandEvent & event )
01019 {
01020     if ( std::string( "double" ).compare( g_pDataTypeInfo->name() ) == 0 ) {
01021         WriteSimulationParameters<double>( event );
01022     }
01023     else if ( std::string( "float" ).compare( g_pDataTypeInfo->name() ) == 0 ) {
01024         WriteSimulationParameters<float>( event );
01025     }
01026     else {
01027         std::cout << g_pDataTypeInfo->name() << " type is not supported!\n";
01028     }
01029     //Update();
01030 }
01031 
01032 
01033 // Process events for changing rendering parameters
01034 void WXElasticRodParameters::OnChangingRenderingParameters ( wxCommandEvent & event )
01035 {
01036     if ( std::string( "double" ).compare( g_pDataTypeInfo->name() ) == 0 ) {
01037         WriteRenderingParameters<double>( event );
01038     }
01039     else if ( std::string( "float" ).compare( g_pDataTypeInfo->name() ) == 0 ) {
01040         WriteRenderingParameters<float>( event );
01041     }
01042     else {
01043         std::cout << g_pDataTypeInfo->name() << " type is not supported!\n";
01044     }
01045     //Update();
01046 }
01047 
01048 
01049 // Write physically based values from the property dialog to the elastic rod parameters
01050 template <typename T>
01051 void WXElasticRodParameters::WritePhysicallyBasedParameters ( wxCommandEvent & event )
01052 {
01053     std::string strVal;
01054     ElasticRodParameters<T> * par = static_cast<ElasticRodParameters<T> *>( m_pERParameters );
01055     switch ( event.GetId() ) {
01056         case ID_WXElasticRod_Length:
01057             m_pID_WXElasticRod_Length->SetForegroundColour( color_textNormal );
01058             strVal = m_pID_WXElasticRod_Length->GetValue();
01059             //m_pID_WXElasticRod_Length->ChangeValue( strVal + " " );
01060             par->TotalLength = atof( strVal.c_str() );
01061             if ( std::string( "double" ).compare( g_pDataTypeInfo->name() ) == 0 ) {
01062                 // Recalculate the LinkLength, MassOfPoint, and some of other parameters 
01063                 // that are depending on the values of other parameters.
01064                 par->CalDependentParameters();
01065                 // Adjust all of the rest lengths of centerlines and orientations
01066                 SetAllRestLengths<T>();
01067             }
01068             else if ( std::string( "float" ).compare( g_pDataTypeInfo->name() ) == 0 ) {
01069                 // Recalculate the LinkLength, MassOfPoint, and some of other parameters 
01070                 // that are depending on the values of other parameters.
01071                 par->CalDependentParameters();
01072                 // Adjust all of the rest lengths of centerlines and orientations
01073                 SetAllRestLengths<T>();
01074             }
01075             else {
01076                 std::cout << g_pDataTypeInfo->name() << " type is not supported!\n";
01077             }
01078             break;
01079         case ID_WXElasticRod_Mass:
01080             m_pID_WXElasticRod_Mass->SetForegroundColour( color_textNormal );
01081             strVal = m_pID_WXElasticRod_Mass->GetValue();
01082             //m_pID_WXElasticRod_Mass->ChangeValue( strVal + " " );
01083             par->TotalMass = atof( strVal.c_str() );
01084             SetAllMassPoints<T>();
01085             break;
01086         case ID_WXElasticRod_Radius:
01087             m_pID_WXElasticRod_Radius->SetForegroundColour( color_textNormal );
01088             strVal = m_pID_WXElasticRod_Radius->GetValue();
01089             //m_pID_WXElasticRod_Radius->ChangeValue( strVal + " " );
01090             par->Radius = atof( strVal.c_str() );
01091             break;
01092         //case ID_WXElasticRod_NumOfLinks:
01093         //  m_pID_WXElasticRod_NumOfLinks->SetForegroundColour( color_textNormal );
01094         //  strVal = m_pID_WXElasticRod_NumOfLinks->GetValue();
01095         //  //m_pID_WXElasticRod_NumOfLinks->ChangeValue( strVal + " " );
01096         //  par->NumOfNodes = atoi( strVal.c_str() ) + 1;
01097         //  break;
01098         case ID_WXElasticRod_StretchModulus:
01099             m_pID_WXElasticRod_StretchModulus->SetForegroundColour( color_textNormal );
01100             strVal = m_pID_WXElasticRod_StretchModulus->GetValue();
01101             //m_pID_WXElasticRod_StretchModulus->ChangeValue( strVal + " " );
01102             par->Kstretch_modulus = atof( strVal.c_str() );
01103             break;
01104         case ID_WXElasticRod_BendModulus:
01105             m_pID_WXElasticRod_BendModulus->SetForegroundColour( color_textNormal );
01106             strVal = m_pID_WXElasticRod_BendModulus->GetValue();
01107             //m_pID_WXElasticRod_BendModulus->ChangeValue( strVal + " " );
01108             par->Kbend_modulus = atof( strVal.c_str() );
01109             break;
01110         case ID_WXElasticRod_ShearModulus:
01111             m_pID_WXElasticRod_ShearModulus->SetForegroundColour( color_textNormal );
01112             strVal = m_pID_WXElasticRod_ShearModulus->GetValue();
01113             //m_pID_WXElasticRod_ShearModulus->ChangeValue( strVal + " " );
01114             par->Kshear_modulus = atof( strVal.c_str() );
01115             break;
01116         case ID_WXElasticRod_MaterialDensity:
01117             m_pID_WXElasticRod_MaterialDensity->SetForegroundColour( color_textNormal );
01118             strVal = m_pID_WXElasticRod_MaterialDensity->GetValue();
01119             //m_pID_WXElasticRod_MaterialDensity->ChangeValue( strVal + " " );
01120             par->MaterialDensity = atof( strVal.c_str() );
01121             break;
01122         case ID_WXElasticRod_KineticTranslational:
01123             m_pID_WXElasticRod_KineticTranslational->SetForegroundColour( color_textNormal );
01124             strVal = m_pID_WXElasticRod_KineticTranslational->GetValue();
01125             //m_pID_WXElasticRod_KineticTranslational->ChangeValue( strVal + " " );
01126             par->Kt = atof( strVal.c_str() );
01127             break;
01128         case ID_WXElasticRod_KineticRotational_0:
01129             m_pID_WXElasticRod_KineticRotational_0->SetForegroundColour( color_textNormal );
01130             strVal = m_pID_WXElasticRod_KineticRotational_0->GetValue();
01131             //m_pID_WXElasticRod_KineticRotational_0->ChangeValue( strVal + " " );
01132             par->Kr[0] = atof( strVal.c_str() );
01133             break;
01134         case ID_WXElasticRod_KineticRotational_1:
01135             m_pID_WXElasticRod_KineticRotational_1->SetForegroundColour( color_textNormal );
01136             strVal = m_pID_WXElasticRod_KineticRotational_1->GetValue();
01137             //m_pID_WXElasticRod_KineticRotational_1->ChangeValue( strVal + " " );
01138             par->Kr[1] = atof( strVal.c_str() );
01139             break;
01140         case ID_WXElasticRod_KineticRotational_2:
01141             m_pID_WXElasticRod_KineticRotational_2->SetForegroundColour( color_textNormal );
01142             strVal = m_pID_WXElasticRod_KineticRotational_2->GetValue();
01143             //m_pID_WXElasticRod_KineticRotational_2->ChangeValue( strVal + " " );
01144             par->Kr[2] = atof( strVal.c_str() );
01145             break;
01146         case ID_WXElasticRod_DissipationTranslational:
01147             m_pID_WXElasticRod_DissipationTranslational->SetForegroundColour( color_textNormal );
01148             strVal = m_pID_WXElasticRod_DissipationTranslational->GetValue();
01149             //m_pID_WXElasticRod_DissipationTranslational->ChangeValue( strVal + " " );
01150             par->Dt = atof( strVal.c_str() );
01151             break;
01152         case ID_WXElasticRod_DissipationRotational_0:
01153             m_pID_WXElasticRod_DissipationRotational_0->SetForegroundColour( color_textNormal );
01154             strVal = m_pID_WXElasticRod_DissipationRotational_0->GetValue();
01155             //m_pID_WXElasticRod_DissipationRotational_0->ChangeValue( strVal + " " );
01156             par->Dr[0] = atof( strVal.c_str() );
01157             break;
01158         case ID_WXElasticRod_DissipationRotational_1:
01159             m_pID_WXElasticRod_DissipationRotational_1->SetForegroundColour( color_textNormal );
01160             strVal = m_pID_WXElasticRod_DissipationRotational_1->GetValue();
01161             //m_pID_WXElasticRod_DissipationRotational_1->ChangeValue( strVal + " " );
01162             par->Dr[1] = atof( strVal.c_str() );
01163             break;
01164         case ID_WXElasticRod_DissipationRotational_2:
01165             m_pID_WXElasticRod_DissipationRotational_2->SetForegroundColour( color_textNormal );
01166             strVal = m_pID_WXElasticRod_DissipationRotational_2->GetValue();
01167             //m_pID_WXElasticRod_DissipationRotational_2->ChangeValue( strVal + " " );
01168             par->Dr[2] = atof( strVal.c_str() );
01169             break;
01170         case ID_WXElasticRod_Constraint_3rdDirAlignCenterline:
01171             m_pID_WXElasticRod_Constraint_3rdDirAlignCenterline->SetForegroundColour( color_textNormal );
01172             strVal = m_pID_WXElasticRod_Constraint_3rdDirAlignCenterline->GetValue();
01173             //m_pID_WXElasticRod_Constraint_3rdDirAlignCenterline->ChangeValue( strVal + " " );
01174             par->Kconstraint_3rdDirAlignTangent = atof( strVal.c_str() );
01175             break;
01176         case ID_WXElasticRod_Constraint_ScaleIntrinsicStrainRate:
01177             m_pID_WXElasticRod_Constraint_ScaleIntrinsicStrainRate->SetForegroundColour( color_textNormal );
01178             strVal = m_pID_WXElasticRod_Constraint_ScaleIntrinsicStrainRate->GetValue();
01179             //m_pID_WXElasticRod_Constraint_ScaleIntrinsicStrainRate->ChangeValue( strVal + " " );
01180             par->Kconstraint_ScaleIntrinsicStrainRate = atof( strVal.c_str() );
01181             break;
01182         case ID_WXElasticRod_GravitationalConstant_slider:
01183             {
01184                 int val = m_pID_WXElasticRod_GravitationalConstant_slider->GetValue();
01185                 par->Kgravity = val / T(100);
01186             }
01187             break;
01188         case ID_WXElasticRod_DampingVelocity:
01189             m_pID_WXElasticRod_DampingVelocity->SetForegroundColour( color_textNormal );
01190             strVal = m_pID_WXElasticRod_DampingVelocity->GetValue();
01191             //m_pID_WXElasticRod_DampingVelocity->ChangeValue( strVal + " " );
01192             par->Kvdamping = 1.0 - atof( strVal.c_str() )/100.0;
01193             break;
01194     }
01195     DisplayERInfo( *par );
01196     par->CalDependentParameters();
01197     ShowSuggestedMassAndMaterialDensity( *par );
01198 }
01199 
01200 
01201 // Write simulation values from the property dialog to the elastic rod parameters
01202 template <typename T>
01203 void WXElasticRodParameters::WriteSimulationParameters ( wxCommandEvent & event )
01204 {
01205     std::string strVal;
01206     ElasticRodParameters<T> * par = static_cast<ElasticRodParameters<T> *>( m_pERParameters );
01207     switch ( event.GetId() ) {
01208         case ID_WXElasticRod_KselfCDR:
01209             m_pID_WXElasticRod_KselfCDR->SetForegroundColour( color_textNormal );
01210             strVal = m_pID_WXElasticRod_KselfCDR->GetValue();
01211             //m_pID_WXElasticRod_KselfCDR->ChangeValue( strVal + " " );
01212             par->KselfCDR = atof( strVal.c_str() );
01213             break;
01214         case ID_WXElasticRod_KselfCDR_Offset:
01215             m_pID_WXElasticRod_KselfCDR_Offset->SetForegroundColour( color_textNormal );
01216             strVal = m_pID_WXElasticRod_KselfCDR_Offset->GetValue();
01217             //m_pID_WXElasticRod_KselfCDR_Offset->ChangeValue( strVal + " " );
01218             par->Offset_CD_Self = atof( strVal.c_str() );
01219             break;
01220         case ID_WXElasticRod_Sim_TimeStep:
01221             m_pID_WXElasticRod_Sim_TimeStep->SetForegroundColour( color_textNormal );
01222             strVal = m_pID_WXElasticRod_Sim_TimeStep->GetValue();
01223             //m_pID_WXElasticRod_Sim_TimeStep->ChangeValue( strVal + " " );
01224             par->TimeStep = atof( strVal.c_str() );
01225             break;
01226         case ID_WXElasticRod_CDRwBV_Cylinder_K:
01227             m_pID_WXElasticRod_CDRwBV_Cylinder_K->SetForegroundColour( color_textNormal );
01228             strVal = m_pID_WXElasticRod_CDRwBV_Cylinder_K->GetValue();
01229             //m_pID_WXElasticRod_CDRwBV_Cylinder_K->ChangeValue( strVal + " " );
01230             par->K_CDRwBV_Cylinder = atof( strVal.c_str() );
01231             break;
01232         case ID_WXElasticRod_CDRwBV_Sphere_K:
01233             m_pID_WXElasticRod_CDRwBV_Sphere_K->SetForegroundColour( color_textNormal );
01234             strVal = m_pID_WXElasticRod_CDRwBV_Sphere_K->GetValue();
01235             //m_pID_WXElasticRod_CDRwBV_Sphere_K->ChangeValue( strVal + " " );
01236             par->K_CDRwBV_Sphere = atof( strVal.c_str() );
01237             break;
01238         case ID_WXElasticRod_CDRwTriangle_K:
01239             m_pID_WXElasticRod_CDRwTriangle_K->SetForegroundColour( color_textNormal );
01240             strVal = m_pID_WXElasticRod_CDRwTriangle_K->GetValue();
01241             //m_pID_WXElasticRod_CDRwTriangle_K->ChangeValue( strVal + " " );
01242             par->K_CDRwTriangle = atof( strVal.c_str() );
01243             break;
01244         case ID_WXElasticRod_CDRwBV_Cylinder_O:
01245             m_pID_WXElasticRod_CDRwBV_Cylinder_O->SetForegroundColour( color_textNormal );
01246             strVal = m_pID_WXElasticRod_CDRwBV_Cylinder_O->GetValue();
01247             //m_pID_WXElasticRod_CDRwBV_Cylinder_O->ChangeValue( strVal + " " );
01248             par->Offset_CD_BV_Cylinder = atof( strVal.c_str() );
01249             break;
01250         case ID_WXElasticRod_CDRwBV_Sphere_O:
01251             m_pID_WXElasticRod_CDRwBV_Sphere_O->SetForegroundColour( color_textNormal );
01252             strVal = m_pID_WXElasticRod_CDRwBV_Sphere_O->GetValue();
01253             //m_pID_WXElasticRod_CDRwBV_Sphere_O->ChangeValue( strVal + " " );
01254             par->Offset_CD_BV_Sphere = atof( strVal.c_str() );
01255             break;
01256         case ID_WXElasticRod_CDRwTriangle_O:
01257             m_pID_WXElasticRod_CDRwTriangle_O->SetForegroundColour( color_textNormal );
01258             strVal = m_pID_WXElasticRod_CDRwTriangle_O->GetValue();
01259             //m_pID_WXElasticRod_CDRwTriangle_O->ChangeValue( strVal + " " );
01260             par->Offset_CD_Triangle = atof( strVal.c_str() );
01261             break;
01262 
01263         // For CDR with implicit objects
01264     #ifdef  TAPs_ADD_IMPLICIT_OBJECTS
01265         case ID_WXElasticRod_CDRwImpObj_Sphere_K:
01266             m_pID_WXElasticRod_CDRwImpObj_Sphere_K->SetForegroundColour( color_textNormal );
01267             strVal = m_pID_WXElasticRod_CDRwImpObj_Sphere_K->GetValue();
01268             //m_pID_WXElasticRod_CDRwImpObj_Sphere_K->ChangeValue( strVal + " " );
01269             par->K_CDRwImpObj_Sphere = atof( strVal.c_str() );
01270             std::cout << "par->K_CDRwImpObj_Sphere: " << par->K_CDRwImpObj_Sphere << "\n";
01271             break;
01272         case ID_WXElasticRod_CDRwImpObj_Sphere_O:
01273             m_pID_WXElasticRod_CDRwImpObj_Sphere_O->SetForegroundColour( color_textNormal );
01274             strVal = m_pID_WXElasticRod_CDRwImpObj_Sphere_O->GetValue();
01275             //m_pID_WXElasticRod_CDRwImpObj_Sphere_O->ChangeValue( strVal + " " );
01276             par->Offset_CD_ImpObj_Sphere = atof( strVal.c_str() );
01277             break;
01278         case ID_WXElasticRod_CDRwImpObj_Torus_K:
01279             m_pID_WXElasticRod_CDRwImpObj_Torus_K->SetForegroundColour( color_textNormal );
01280             strVal = m_pID_WXElasticRod_CDRwImpObj_Torus_K->GetValue();
01281             //m_pID_WXElasticRod_CDRwImpObj_Torus_K->ChangeValue( strVal + " " );
01282             par->K_CDRwImpObj_Torus = atof( strVal.c_str() );
01283             break;
01284         case ID_WXElasticRod_CDRwImpObj_Torus_O:
01285             m_pID_WXElasticRod_CDRwImpObj_Torus_O->SetForegroundColour( color_textNormal );
01286             strVal = m_pID_WXElasticRod_CDRwImpObj_Torus_O->GetValue();
01287             //m_pID_WXElasticRod_CDRwImpObj_Torus_O->ChangeValue( strVal + " " );
01288             par->Offset_CD_ImpObj_Torus = atof( strVal.c_str() );
01289             break;
01290     #endif//TAPs_ADD_IMPLICIT_OBJECTS
01291 
01292     }
01293     DisplayERInfo( *par );
01294 }
01295 
01296 
01297 // Write rendering values from the property dialog to the elastic rod parameters
01298 template <typename T>
01299 void WXElasticRodParameters::WriteRenderingParameters ( wxCommandEvent & event )
01300 {
01301     std::string strVal;
01302     ElasticRodParameters<T> * par = static_cast<ElasticRodParameters<T> *>( m_pERParameters );
01303     switch ( event.GetId() ) {
01304         case ID_WXElasticRod_Render_NumOfVerticesPerCrossSection_slider:
01305             //pOwner->SetRenderingForNumberOfVerticesPerCrossSection( m_pID_WXElasticRod_Render_NumOfVerticesPerCrossSection_slider->GetValue() );
01306             break;
01307     }
01308     DisplayERInfo( *par );
01309 }
01310 
01311 
01312 // Show the parameter values of the elastic rod in GUI
01313 template <typename T>
01314 void WXElasticRodParameters::ShowParametersValuesInGUI ( ElasticRodParameters<T> & par )
01315 {
01316     // Set name
01317     m_pID_WXElasticRod_Current_Load_Parameter_Set->ChangeValue( par.Name );
01318 
01319     // The length is always from the current parameter, i.e. it is not allowed to change.
01320     ElasticRodParameters<T> * ERpar = static_cast<ElasticRodParameters<T> *>( m_pERParameters );
01321     par.TotalLength = ERpar->TotalLength;
01322 
01323     // Set values for physically based parameters
01324     {std::ostringstream ss; ss << par.TotalLength;          m_pID_WXElasticRod_Length->ChangeValue( ss.str() );}
01325     m_pID_WXElasticRod_Length->SetForegroundColour( color_textNormal );
01326     {std::ostringstream ss; ss << par.TotalMass;            m_pID_WXElasticRod_Mass->ChangeValue( ss.str() );}
01327     m_pID_WXElasticRod_Mass->SetForegroundColour( color_textNormal );
01328     {std::ostringstream ss; ss << par.Radius;               m_pID_WXElasticRod_Radius->ChangeValue( ss.str() );}
01329     m_pID_WXElasticRod_Radius->SetForegroundColour( color_textNormal );
01330     {std::ostringstream ss; ss << par.NumOfNodes-1;         m_pID_WXElasticRod_NumOfLinks->ChangeValue( ss.str() );}
01331     m_pID_WXElasticRod_NumOfLinks->SetForegroundColour( color_textNormal );
01332     {std::ostringstream ss; ss << par.Kstretch_modulus;     m_pID_WXElasticRod_StretchModulus->ChangeValue( ss.str() );}
01333     m_pID_WXElasticRod_StretchModulus->SetForegroundColour( color_textNormal );
01334     {std::ostringstream ss; ss << par.Kbend_modulus;        m_pID_WXElasticRod_BendModulus->ChangeValue( ss.str() );}
01335     m_pID_WXElasticRod_BendModulus->SetForegroundColour( color_textNormal );
01336     {std::ostringstream ss; ss << par.Kshear_modulus;       m_pID_WXElasticRod_ShearModulus->ChangeValue( ss.str() );}
01337     m_pID_WXElasticRod_ShearModulus->SetForegroundColour( color_textNormal );
01338     {std::ostringstream ss; ss << par.MaterialDensity;      m_pID_WXElasticRod_MaterialDensity->ChangeValue( ss.str() );}
01339     m_pID_WXElasticRod_MaterialDensity->SetForegroundColour( color_textNormal );
01340     {std::ostringstream ss; ss << par.Kt;                   m_pID_WXElasticRod_KineticTranslational->ChangeValue( ss.str() );}
01341     m_pID_WXElasticRod_KineticTranslational->SetForegroundColour( color_textNormal );
01342     {std::ostringstream ss; ss << par.Kr[0];                m_pID_WXElasticRod_KineticRotational_0->ChangeValue( ss.str() );}
01343     m_pID_WXElasticRod_KineticRotational_0->SetForegroundColour( color_textNormal );
01344     {std::ostringstream ss; ss << par.Kr[1];                m_pID_WXElasticRod_KineticRotational_1->ChangeValue( ss.str() );}
01345     m_pID_WXElasticRod_KineticRotational_1->SetForegroundColour( color_textNormal );
01346     {std::ostringstream ss; ss << par.Kr[2];                m_pID_WXElasticRod_KineticRotational_2->ChangeValue( ss.str() );}
01347     m_pID_WXElasticRod_KineticRotational_2->SetForegroundColour( color_textNormal );
01348     {std::ostringstream ss; ss << par.Dt;                   m_pID_WXElasticRod_DissipationTranslational->ChangeValue( ss.str() );}
01349     m_pID_WXElasticRod_DissipationTranslational->SetForegroundColour( color_textNormal );
01350     {std::ostringstream ss; ss << par.Dr[0];                m_pID_WXElasticRod_DissipationRotational_0->ChangeValue( ss.str() );}
01351     m_pID_WXElasticRod_DissipationRotational_0->SetForegroundColour( color_textNormal );
01352     {std::ostringstream ss; ss << par.Dr[1];                m_pID_WXElasticRod_DissipationRotational_1->ChangeValue( ss.str() );}
01353     m_pID_WXElasticRod_DissipationRotational_1->SetForegroundColour( color_textNormal );
01354     {std::ostringstream ss; ss << par.Dr[2];                m_pID_WXElasticRod_DissipationRotational_2->ChangeValue( ss.str() );}
01355     m_pID_WXElasticRod_DissipationRotational_2->SetForegroundColour( color_textNormal );
01356     {std::ostringstream ss; ss << par.Kconstraint_3rdDirAlignTangent;   m_pID_WXElasticRod_Constraint_3rdDirAlignCenterline->ChangeValue( ss.str() );}
01357     m_pID_WXElasticRod_Constraint_3rdDirAlignCenterline->SetForegroundColour( color_textNormal );
01358     {std::ostringstream ss; ss << (1.0-par.Kvdamping)*100;  m_pID_WXElasticRod_DampingVelocity->ChangeValue( ss.str() );}
01359     m_pID_WXElasticRod_DampingVelocity->SetForegroundColour( color_textNormal );
01360 
01361     // ScaleIntrinsicStrainRate
01362     {std::ostringstream ss; ss << par.Kconstraint_ScaleIntrinsicStrainRate; m_pID_WXElasticRod_Constraint_ScaleIntrinsicStrainRate->ChangeValue( ss.str() );}
01363     m_pID_WXElasticRod_Constraint_ScaleIntrinsicStrainRate->SetForegroundColour( color_textNormal );
01364 
01365     // Slider for gravitational constant
01366     m_pID_WXElasticRod_GravitationalConstant_slider->SetValue( floor( par.Kgravity * 100 ) );
01367 
01368     // Set values for simulation parameters
01369     {std::ostringstream ss; ss << par.KselfCDR; m_pID_WXElasticRod_KselfCDR->ChangeValue( ss.str() );}
01370     m_pID_WXElasticRod_KselfCDR->SetForegroundColour( color_textNormal );
01371     {std::ostringstream ss; ss << par.Offset_CD_Self;   m_pID_WXElasticRod_KselfCDR_Offset->ChangeValue( ss.str() );}
01372     m_pID_WXElasticRod_KselfCDR_Offset->SetForegroundColour( color_textNormal );
01373     {std::ostringstream ss; ss << par.TimeStep;                 m_pID_WXElasticRod_Sim_TimeStep->ChangeValue( ss.str() );}
01374     m_pID_WXElasticRod_Sim_TimeStep->SetForegroundColour( color_textNormal );
01375     {std::ostringstream ss; ss << par.K_CDRwBV_Cylinder;    m_pID_WXElasticRod_CDRwBV_Cylinder_K->ChangeValue( ss.str() );}
01376     m_pID_WXElasticRod_CDRwBV_Cylinder_K->SetForegroundColour( color_textNormal );
01377     {std::ostringstream ss; ss << par.K_CDRwBV_Sphere;      m_pID_WXElasticRod_CDRwBV_Sphere_K->ChangeValue( ss.str() );}
01378     m_pID_WXElasticRod_CDRwBV_Sphere_K->SetForegroundColour( color_textNormal );
01379     {std::ostringstream ss; ss << par.K_CDRwTriangle;       m_pID_WXElasticRod_CDRwTriangle_K->ChangeValue( ss.str() );}
01380     m_pID_WXElasticRod_CDRwTriangle_K->SetForegroundColour( color_textNormal );
01381     {std::ostringstream ss; ss << par.Offset_CD_BV_Cylinder;    m_pID_WXElasticRod_CDRwBV_Cylinder_O->ChangeValue( ss.str() );}
01382     m_pID_WXElasticRod_CDRwBV_Cylinder_O->SetForegroundColour( color_textNormal );
01383     {std::ostringstream ss; ss << par.Offset_CD_BV_Sphere;      m_pID_WXElasticRod_CDRwBV_Sphere_O->ChangeValue( ss.str() );}
01384     m_pID_WXElasticRod_CDRwBV_Sphere_O->SetForegroundColour( color_textNormal );
01385     {std::ostringstream ss; ss << par.Offset_CD_Triangle;       m_pID_WXElasticRod_CDRwTriangle_O->ChangeValue( ss.str() );}
01386     m_pID_WXElasticRod_CDRwTriangle_O->SetForegroundColour( color_textNormal );
01387 
01388     // For CDR with implicit objects
01389 #ifdef  TAPs_ADD_IMPLICIT_OBJECTS
01390     {std::ostringstream ss; ss << par.K_CDRwImpObj_Sphere;  m_pID_WXElasticRod_CDRwImpObj_Sphere_K->ChangeValue( ss.str() );}
01391     m_pID_WXElasticRod_CDRwImpObj_Sphere_K->SetForegroundColour( color_textNormal );
01392     {std::ostringstream ss; ss << par.Offset_CD_ImpObj_Sphere;  m_pID_WXElasticRod_CDRwImpObj_Sphere_O->ChangeValue( ss.str() );}
01393     m_pID_WXElasticRod_CDRwImpObj_Sphere_O->SetForegroundColour( color_textNormal );
01394     {std::ostringstream ss; ss << par.K_CDRwImpObj_Torus;   m_pID_WXElasticRod_CDRwImpObj_Torus_K->ChangeValue( ss.str() );}
01395     m_pID_WXElasticRod_CDRwImpObj_Torus_K->SetForegroundColour( color_textNormal );
01396     {std::ostringstream ss; ss << par.Offset_CD_ImpObj_Torus;   m_pID_WXElasticRod_CDRwImpObj_Torus_O->ChangeValue( ss.str() );}
01397     m_pID_WXElasticRod_CDRwImpObj_Torus_O->SetForegroundColour( color_textNormal );
01398 #endif//TAPs_ADD_IMPLICIT_OBJECTS
01399 
01400     // For rendering
01401     //m_pID_WXElasticRod_Render_NumOfVerticesPerCrossSection_slider->SetValue( pOwner->GetRenderingForNumberOfVerticesPerCrossSection() );
01402 
01403     // Display the information of the elastic rod
01404     DisplayERInfo( par );
01405     ShowSuggestedMassAndMaterialDensity( par );
01406 }
01407 
01408 
01409 // Process events for loading parameters
01410 void WXElasticRodParameters::OnLoadParameters ( wxCommandEvent & event )
01411 {
01412     wxComboBox * pCB_preset  = m_pID_WXElasticRod_Load_Preset;
01413     wxComboBox * pCB_userset = m_pID_WXElasticRod_Load_Userset;
01414     int presetID  = pCB_preset->GetSelection();
01415     int usersetID = pCB_userset->GetSelection();
01416     if ( std::string( "double" ).compare( g_pDataTypeInfo->name() ) == 0 ) {
01417         switch ( event.GetId() ) {
01418             case ID_WXElasticRod_Load_Preset:
01419                 ApplyParameters<double>( g_vdPresets[presetID] );
01420                 break;
01421             case ID_WXElasticRod_Load_Userset:
01422                 ApplyParameters<double>( g_vdUsersets[usersetID] );
01423                 break;
01424         }
01425     }
01426     else if ( std::string( "float" ).compare( g_pDataTypeInfo->name() ) == 0 ) {
01427         switch ( event.GetId() ) {
01428             case ID_WXElasticRod_Load_Preset:
01429                 ApplyParameters<float>( g_vfPresets[presetID] );
01430                 break;
01431             case ID_WXElasticRod_Load_Userset:
01432                 ApplyParameters<float>( g_vfUsersets[usersetID] );
01433                 break;
01434         }
01435     }
01436     else {
01437         std::cout << g_pDataTypeInfo->name() << " type is not supported!\n";
01438     }
01439 }
01440 
01441 
01442 // Apply parameters from the select parameter set to the elastic rod (and GUI)
01443 template <typename T>
01444 void WXElasticRodParameters::ApplyParameters ( ElasticRodParameters<T> & par )
01445 {
01446     // Set parameter values in GUI from the passing parameters
01447     ShowParametersValuesInGUI( par );
01448 
01449     // Set parameter values in the Elastic Rod from the passing parameters
01450     ElasticRodParameters<T> * ERpar = static_cast<ElasticRodParameters<T> *>( m_pERParameters );
01451 
01452     //std::cout << "ERpar Before: " << *ERpar << std::endl;
01453 
01454     // Name
01455     ERpar->Name = par.Name;
01456 
01457     SetParametersFromGUI( *ERpar );
01458 
01459     //std::cout << "ERpar After: " << *ERpar << std::endl;
01460 }
01461 
01462 
01463 // Process events for saving parameters
01464 void WXElasticRodParameters::OnSaveParameters ( wxCommandEvent & event )
01465 {
01466     if ( std::string( "double" ).compare( g_pDataTypeInfo->name() ) == 0 ) {
01467         switch ( event.GetId() ) {
01468             case ID_WXElasticRod_Save_Userset_Btn:
01469                 SaveParameters<double>( g_vdUsersets );
01470                 break;
01471         }
01472     }
01473     else if ( std::string( "float" ).compare( g_pDataTypeInfo->name() ) == 0 ) {
01474         switch ( event.GetId() ) {
01475             case ID_WXElasticRod_Save_Userset_Btn:
01476                 SaveParameters<float>( g_vfUsersets );
01477                 break;
01478         }
01479     }
01480     else {
01481         std::cout << g_pDataTypeInfo->name() << " type is not supported!\n";
01482     }
01483 }
01484 
01485 
01486 // Save the current parameters as a user set
01487 template <typename T>
01488 void WXElasticRodParameters::SaveParameters ( std::vector< ElasticRodParameters<T> > & userSets )
01489 {
01490     // Insert this parameter set into the list in alphabetical order (low-to-high)
01491     if ( userSets.size() > 0 ) {
01492         ElasticRodParameters<T> userSet = *(static_cast<ElasticRodParameters<T> *>( m_pERParameters ));
01493         wxComboBox * pCB  = m_pID_WXElasticRod_Load_Userset;
01494         wxTextCtrl * pTC  = m_pID_WXElasticRod_Save_Userset_Name;
01495         wxTextCtrl * pTC2 = m_pID_WXElasticRod_Current_Load_Parameter_Set;
01496 
01497         userSet.Name = pTC->GetValue();
01498         SetParametersFromGUI( userSet );
01499         int insertPos = 0;
01500         std::vector< ElasticRodParameters<T> >::iterator it = userSets.begin();
01501         bool isNotInserted = true;
01502         while ( it != userSets.end() ) {
01503             if ( 0 < it->Name.compare( userSet.Name ) ) {
01504                 userSets.insert( it, userSet );
01505                 isNotInserted = false;
01506                 break;
01507             }
01508             ++it;
01509         }
01510         if ( isNotInserted ) {
01511             // the current last element
01512             userSets.push_back( userSet );
01513         }
01514 
01515         // Update the GUI
01516         pTC2->ChangeValue( pTC->GetValue() );
01517         pCB->Clear();
01518         it = userSets.begin();
01519         while ( it != userSets.end() ) {
01520             pCB->Append( it->Name );
01521             ++it;
01522         }
01523     }
01524     else {  // the first element
01525         userSets.push_back( ElasticRodParameters<T>() );
01526         SetParametersFromGUI( userSets.back() );
01527         wxComboBox * pCB  = m_pID_WXElasticRod_Load_Userset;
01528         wxTextCtrl * pTC  = m_pID_WXElasticRod_Save_Userset_Name;
01529         wxTextCtrl * pTC2 = m_pID_WXElasticRod_Current_Load_Parameter_Set;
01530         userSets.back().Name = pTC->GetValue();
01531         pTC2->ChangeValue( pTC->GetValue() );
01532         pCB->Append( userSets.back().Name );
01533     }
01534 
01535 
01536     // Write to the file
01537     std::ofstream out;
01538     out.open( g_UsersetFile.GetFileName().c_str(), std::ios::out );
01539     if ( !out.is_open() ) {
01540         std::cout << "Couldn't open file \"" << g_UsersetFile << "\" for writing!" << std::endl;
01541         return;
01542     }
01543     std::vector< ElasticRodParameters<T> >::iterator it = userSets.begin();
01544     while ( it != userSets.end() ) {
01545         std::string str( it->StrInfo() );
01546         out.write( str.c_str(), static_cast<int>( str.size() ) );
01547         out << std::endl;
01548         ++it;
01549     }
01550     out.close();
01551 }
01552 
01553 
01554 // Set the parameter values from GUI to the passing parameter set
01555 template <typename T>
01556 void WXElasticRodParameters::SetParametersFromGUI ( ElasticRodParameters<T> & par )
01557 {
01558     std::string strVal;
01559 
01560     // Name
01561     strVal = m_pID_WXElasticRod_Mass->GetValue();
01562     par.Name = strVal;
01563 
01564     // Physically based parameters
01565     strVal = m_pID_WXElasticRod_Length->GetValue();
01566     par.TotalLength = atof( strVal.c_str() );
01567     strVal = m_pID_WXElasticRod_Mass->GetValue();
01568     par.TotalMass = atof( strVal.c_str() );
01569     strVal = m_pID_WXElasticRod_Radius->GetValue();
01570     par.Radius = atof( strVal.c_str() );
01571     strVal = m_pID_WXElasticRod_NumOfLinks->GetValue();
01572     par.NumOfNodes = atoi( strVal.c_str() ) + 1;
01573     strVal = m_pID_WXElasticRod_StretchModulus->GetValue();
01574     par.Kstretch_modulus = atof( strVal.c_str() );
01575     strVal = m_pID_WXElasticRod_BendModulus->GetValue();
01576     par.Kbend_modulus = atof( strVal.c_str() );
01577     strVal = m_pID_WXElasticRod_ShearModulus->GetValue();
01578     par.Kshear_modulus = atof( strVal.c_str() );
01579     strVal = m_pID_WXElasticRod_MaterialDensity->GetValue();
01580     par.MaterialDensity = atof( strVal.c_str() );
01581     strVal = m_pID_WXElasticRod_KineticTranslational->GetValue();
01582     par.Kt = atof( strVal.c_str() );
01583     strVal = m_pID_WXElasticRod_KineticRotational_0->GetValue();
01584     par.Kr[0] = atof( strVal.c_str() );
01585     strVal = m_pID_WXElasticRod_KineticRotational_1->GetValue();
01586     par.Kr[1] = atof( strVal.c_str() );
01587     strVal = m_pID_WXElasticRod_KineticRotational_2->GetValue();
01588     par.Kr[2] = atof( strVal.c_str() );
01589     strVal = m_pID_WXElasticRod_DissipationTranslational->GetValue();
01590     par.Dt = atof( strVal.c_str() );
01591     strVal = m_pID_WXElasticRod_DissipationRotational_0->GetValue();
01592     par.Dr[0] = atof( strVal.c_str() );
01593     strVal = m_pID_WXElasticRod_DissipationRotational_1->GetValue();
01594     par.Dr[1] = atof( strVal.c_str() );
01595     strVal = m_pID_WXElasticRod_DissipationRotational_2->GetValue();
01596     par.Dr[2] = atof( strVal.c_str() );
01597     strVal = m_pID_WXElasticRod_Constraint_3rdDirAlignCenterline->GetValue();
01598     par.Kconstraint_3rdDirAlignTangent = atof( strVal.c_str() );
01599     strVal = m_pID_WXElasticRod_DampingVelocity->GetValue();
01600     par.Kvdamping = 1.0 - atof( strVal.c_str() )/100.0;
01601 
01602     // for intrinsic strain rate
01603     strVal = m_pID_WXElasticRod_Constraint_ScaleIntrinsicStrainRate->GetValue();
01604     par.Kconstraint_ScaleIntrinsicStrainRate = atof( strVal.c_str() );
01605 
01606     // Slider for gravitational constant
01607     par.Kgravity = m_pID_WXElasticRod_GravitationalConstant_slider->GetValue() / T(100);
01608 
01609     // Simulation parameters
01610     strVal = m_pID_WXElasticRod_KselfCDR->GetValue();
01611     par.KselfCDR = atof( strVal.c_str() );
01612     strVal = m_pID_WXElasticRod_KselfCDR_Offset->GetValue();
01613     par.Offset_CD_Self = atof( strVal.c_str() );
01614     strVal = m_pID_WXElasticRod_Sim_TimeStep->GetValue();
01615     par.TimeStep = atof( strVal.c_str() );
01616     strVal = m_pID_WXElasticRod_CDRwBV_Cylinder_K->GetValue();
01617     par.K_CDRwBV_Cylinder = atof( strVal.c_str() );
01618     strVal = m_pID_WXElasticRod_CDRwBV_Sphere_K->GetValue();
01619     par.K_CDRwBV_Sphere = atof( strVal.c_str() );
01620     strVal = m_pID_WXElasticRod_CDRwTriangle_K->GetValue();
01621     par.K_CDRwTriangle = atof( strVal.c_str() );
01622     strVal = m_pID_WXElasticRod_CDRwBV_Cylinder_O->GetValue();
01623     par.Offset_CD_BV_Cylinder = atof( strVal.c_str() );
01624     strVal = m_pID_WXElasticRod_CDRwBV_Sphere_O->GetValue();
01625     par.Offset_CD_BV_Sphere = atof( strVal.c_str() );
01626     strVal = m_pID_WXElasticRod_CDRwTriangle_O->GetValue();
01627     par.Offset_CD_Triangle = atof( strVal.c_str() );
01628 
01629     // For CDR with implicit objects
01630 #ifdef  TAPs_ADD_IMPLICIT_OBJECTS
01631     strVal = m_pID_WXElasticRod_CDRwImpObj_Sphere_K->GetValue();
01632     par.K_CDRwImpObj_Sphere = atof( strVal.c_str() );
01633     strVal = m_pID_WXElasticRod_CDRwImpObj_Sphere_O->GetValue();
01634     par.Offset_CD_ImpObj_Sphere = atof( strVal.c_str() );
01635     strVal = m_pID_WXElasticRod_CDRwImpObj_Torus_K->GetValue();
01636     par.K_CDRwImpObj_Torus = atof( strVal.c_str() );
01637     strVal = m_pID_WXElasticRod_CDRwImpObj_Torus_O->GetValue();
01638     par.Offset_CD_ImpObj_Torus = atof( strVal.c_str() );
01639 #endif//TAPs_ADD_IMPLICIT_OBJECTS
01640 
01641     // Rendering parameters
01642 
01643     // Recalculate the LinkLength, MassOfPoint, and some of other parameters 
01644     // that are depending on the values of other parameters.
01645     par.CalDependentParameters();
01646     // Adjust all of the rest lengths of centerlines and orientations
01647     SetAllRestLengths<T>();
01648     // Adjust all of the mass points
01649     SetAllMassPoints<T>();
01650 }
01651 
01652 
01653 // Set all the rest lengths of centerlines and orientations
01654 template <typename T>
01655 void WXElasticRodParameters::SetAllRestLengths ()
01656 {
01657     ElasticRodParameters<T> * par = static_cast<ElasticRodParameters<T> *>( m_pERParameters );
01658     std::vector< ElasticRodNode<T> > * nodes = static_cast<std::vector< ElasticRodNode<T> > *>( m_pERNodeList );
01659     std::vector< ElasticRodNode<T> >::iterator node = nodes->begin();
01660     while ( node != nodes->end() ) {
01661         T Clength = par->LinkLength;
01662         T ratio = Clength / node->CenterlineRestLength;
01663         T Olength = node->OrientationRestLength * ratio;
01664         node->CenterlineRestLength  = Clength;
01665         node->OrientationRestLength = Olength;
01666         ++node;
01667     }
01668 }
01669 
01670 
01671 // Set all the mass points
01672 template <typename T>
01673 void WXElasticRodParameters::SetAllMassPoints ()
01674 {
01675     ElasticRodParameters<T> * par = static_cast<ElasticRodParameters<T> *>( m_pERParameters );
01676     std::vector< ElasticRodNode<T> > * nodes = static_cast<std::vector< ElasticRodNode<T> > *>( m_pERNodeList );
01677     std::vector< ElasticRodNode<T> >::iterator node = nodes->begin();
01678     while ( node != nodes->end() ) {
01679         node->SetMass( par->MassOfPoint );
01680         ++node;
01681     }
01682 }
01683 
01684 
01685 // Display the information about the elastic rod
01686 template <typename T>
01687 void WXElasticRodParameters::DisplayERInfo ( ElasticRodParameters<T> & par )
01688 {
01689     std::ostringstream info;
01690     if ( par.LinkLength < par.Radius ) {
01691         m_pID_WXElasticRod_Display_Information->SetForegroundColour( color_textWarning );
01692         info << "Warning: The link length is less than the radius.\n";
01693         info << "The link length should be increased and/or the radius should be reduced.\n\n";
01694     }
01695     else {
01696         m_pID_WXElasticRod_Display_Information->SetForegroundColour( color_textNormal );
01697     }
01698     info << "The elastic rod is " << par.TotalLength << " unit long.\n";
01699     info << "Its radius is " << par.Radius << " unit with the mass of " << par.TotalMass << " unit.\n";
01700     info << "It is divided into " << par.NumOfNodes-1 << " links.\n";
01701     info << "The length of each link is " << par.LinkLength << " unit.\n";
01702     info << "The mass of each point is " << par.MassOfPoint << " unit.\n";
01703     m_pID_WXElasticRod_Display_Information->ChangeValue( info.str() );
01704 }
01705 
01706 
01707 // Show suggested Mass and Material Density
01708 template <typename T>
01709 void WXElasticRodParameters::ShowSuggestedMassAndMaterialDensity ( ElasticRodParameters<T> & par )
01710 {
01711     wxStaticText * pMass    = (wxStaticText*) FindWindow( "ID_WXER_SuggestedMass" );
01712     wxStaticText * pMatDen  = (wxStaticText*) FindWindow( "ID_WXER_SuggestedMaterialDensity" );
01713     if ( !pMass || !pMatDen )   return;
01714     T volume = par.TotalLength * Math<T>::PI * par.Radius * par.Radius;
01715     std::stringstream ss;
01716     ss << volume * par.MaterialDensity;
01717     pMass->SetLabel( ss.str() );
01718     ss.str("");
01719     ss << par.TotalMass / volume;
01720     pMatDen->SetLabel( ss.str() );
01721 }
01722 //-----------------------------------------------------------------------------
01723 //=============================================================================
01724 END_NAMESPACE_TAPs__WX
01725 //34567890123456789012345678901234567890123456789012345678901234567890123456789
01726 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines