This step reviews how to apply color contour information to a HOOPS/3dGS shell.
HOOPS/3dGS provides support for applying color contour information to shell/mesh primitives and visualizing the data in a variety of ways. We'll start the tutorial by writing a sample routine that takes a selected shell, calculates sample colormap indices based on the shell vertex information, and applies it to the shell.
This exercise will compute/apply sample data by leveraging the following HOOPS/MVO classes and methods intended for prototyping/demo purposes.
We'll first add 2 new members to the HAnalysisModel object and initialize them (note that we'll start with 10 data cycles):
class HAnalysisModel : public HBaseModel { public: ... int m_DataCycles; HShellVertexData *m_pShellVertexData; ... }; HAnalysisModel::HAnalysisModel() { m_DataCycles = 10; m_pShellVertexData = 0; ... }
Add a new method to the 'analysis' project called HAnalysisView::MapData, and add a new GUI menu button which will call MapData.
MapData must first prepare for processing of the items in the selection list. As reviewed in previous tutorials, this is acheived by obtaining a local pointer to the custom HSelectionSet object, checking the size of the selection list, and then iterating through the items. In our example, we'll just process the first item. Note that we must deselect the items before processing.
void HAnalysisView::MapData() { HAnalysisSelectionSet * selection = (HAnalysisSelectionSet*)GetSelection(); if ( selection->GetSize() == 0 ) AfxMessageBox( _T("Must select a shell to use to create the colormap.") ); if( selection->GetSize() > 0 ) { HC_KEY key = selection->GetAt(0); // DeSelect the items first selection->DeSelectAll();
Now we need to actually calculate and apply the sample data. As reviewed above, we have a set number of datacycles,
To prepare for calculating/applying data, we'll first obtain the default # of data cycles, and handle to the shell-vertex-data.
int cycles = ((HAnalysisModel *)GetModel())->m_DataCycles; HShellVertexData *pVertexData = ((HAnalysisModel *)GetModel())->m_pShellVertexData;
Then, we'll free up any existing shell vertex data information hanging off the HBaseModel object, also freeing up it's internal HShellVertexData::m_pFIndexArray.
if (pVertexData) { free(pVertexData->m_pFIndexArray); free(pVertexData); }
Next, we'll allocate the HShellVertexData object and store it in HBaseModel, and compute sample vertex-color data using the shell key and desired data_cycles:
pVertexData = (HShellVertexData *) malloc (sizeof HShellVertexData)); ((HAnalysisModel *)GetModel())->m_pShellVertexData = pVertexData; HUtilityGeometryCreation::ComputeFIndexDemoData(key, pVertexData, cycles);
Next, we call HBaseView::Update to redraw the scene and reflect our changes
Update(); }
After writing and testing the above code, note that we don't see any color contours on the model. This is because we need to set a rendermode to enable viewing of the contour info. We can do this by calling HBaseView::SetColorIndexInterpolation and HBaseView::SetColorInterpolation, discussed further in the next tutorial step.
Let's modify HAnalysisView::MapData() to include the follow prior to the update:
void HAnalysisView::MapData() { // // aforementioned processing is here // SetColorIndexInterpolation(true, false); SetColorInterpolation(true); // redraw the scene to reflect the attributes changes Update(); }
Finally we'll free up any of the shell vertex data that might have been allocated:
HAnalysisModel::~HAnalysisModel() { if (m_pShellVertexData) { free(m_pShellVertexData->m_pFIndexArray); free(m_pShellVertexData); } ... }