[vtkusers] Problem when closing vtk render window
Gishara Indeewarie
gish.777 at gmail.com
Wed Feb 15 07:22:37 EST 2012
Hi all,
I have created a vtk render window and I want to change the data in the
window each time user select an option from a set of radio buttons in a MFC
window.
To do this I called vtkrender window each time an option is selected.
This is working fine, but when I tried to close the vtk window. I get a
debug assertion from vtkgarbagecollector saying that
object->getreferencecount == 1.
Below is the code I am using to render vtk window.
vtkPoints *points = newPts;
vtkPoints *suction_points = newPtsSuction;
vtkSmartPointer<vtkPolyData> polydata =
vtkSmartPointer<vtkPolyData>::New();
polydata->SetPoints(points);
polydata->Modified();
vtkSmartPointer<vtkPolyData> suction_polydata =
vtkSmartPointer<vtkPolyData>::New();
suction_polydata->SetPoints(suction_points);
suction_polydata->Modified();
vtkSmartPointer<vtkDoubleArray> weights =
vtkSmartPointer<vtkDoubleArray>::New();
weights->SetNumberOfValues(ScalarValues_pressure.GetSize());
for(int i=0; i< ScalarValues_pressure.GetSize();i++){
weights->SetValue(i, ScalarValues_pressure[i]);
}
vtkSmartPointer<vtkDoubleArray> suction_weights =
vtkSmartPointer<vtkDoubleArray>::New();
suction_weights->SetNumberOfValues(ScalarValues_suction.GetSize());
for(int i=0; i< ScalarValues_suction.GetSize();i++){
suction_weights->SetValue(i, ScalarValues_suction[i]);
}
vtkSmartPointer<vtkVertexGlyphFilter> glyphFilter =
vtkSmartPointer<vtkVertexGlyphFilter>::New();
glyphFilter->SetInputConnection(polydata->GetProducerPort());
glyphFilter->Update();
vtkSmartPointer<vtkVertexGlyphFilter> suction_glyphFilter =
vtkSmartPointer<vtkVertexGlyphFilter>::New();
suction_glyphFilter->SetInputConnection(suction_polydata->GetProducerPort());
suction_glyphFilter->Update();
//Create a plane
vtkSmartPointer<vtkPlane> plane = vtkSmartPointer<vtkPlane>::New();
plane->SetOrigin(polydata->GetCenter());
plane->SetNormal(1,1,1);
// Construct the surface and create isosurface.
vtkSmartPointer<vtkSurfaceReconstructionFilter> surf =
vtkSmartPointer<vtkSurfaceReconstructionFilter>::New();
surf->SetInput(polydata);
//
vtkSmartPointer<vtkContourFilter> cf =
vtkSmartPointer<vtkContourFilter>::New();
cf->SetInputConnection(surf->GetOutputPort());
cf->Update();
// Construct the suction blade surface and create isosurface.
vtkSmartPointer<vtkSurfaceReconstructionFilter> suction_surf =
vtkSmartPointer<vtkSurfaceReconstructionFilter>::New();
suction_surf->SetInput(suction_polydata);
//
vtkSmartPointer<vtkContourFilter> suction_cf =
vtkSmartPointer<vtkContourFilter>::New();
suction_cf->SetInputConnection(suction_surf->GetOutputPort());
suction_cf->Update();
vtkPolyData* outputPolyData = cf->GetOutput();
outputPolyData->Modified();
vtkPolyData* suction_outputPolyData = suction_cf->GetOutput();
suction_outputPolyData->Modified();
//double bounds[6];
//outputPolyData->GetBounds(bounds);
// Find min and max z
// double minz = bounds[4];
// double maxz = bounds[5];
// Create the color map
vtkSmartPointer<vtkLookupTable> colorLookupTable =
vtkSmartPointer<vtkLookupTable>::New();
colorLookupTable->SetHueRange(0.667,0.0);
colorLookupTable->SetNumberOfColors(16);
colorLookupTable->Build();
colorLookupTable->Modified();
// Create the color map
vtkSmartPointer<vtkLookupTable> colorLookupTable_s =
vtkSmartPointer<vtkLookupTable>::New();
colorLookupTable_s->SetHueRange(0.667,0.0);
colorLookupTable_s->SetNumberOfColors(16);
colorLookupTable_s->Build();
// Generate the colors for each point based on the color map
// double min = minimumValue(PoValues);
int length = ScalarValues_pressure.GetSize();// establish size of array
double max = ScalarValues_pressure[0]; // start with max = first
element
for(int i = 1; i<length; i++)
{
if(ScalarValues_pressure[i] > max)
max = ScalarValues_pressure[i];
}
double min = ScalarValues_pressure[0];
for(int i = 1; i<length; i++)
{
if(ScalarValues_pressure[i] < min)
min = ScalarValues_pressure[i];
}
colorLookupTable->SetTableRange( min,max);
colorLookupTable_s->Modified();
outputPolyData->GetPointData()->SetScalars(weights);
int length_s = ScalarValues_suction.GetSize();// establish size of array
double max_s = ScalarValues_suction[0]; // start with max =
first element
for(int i = 1; i<length_s; i++)
{
if(ScalarValues_suction[i] > max_s)
max_s = ScalarValues_suction[i];
}
double min_s = ScalarValues_suction[0];
for(int i = 1; i<length_s; i++)
{
if(ScalarValues_suction[i] < min_s)
min_s = ScalarValues_suction[i];
}
colorLookupTable_s->SetTableRange( min_s,max_s);
suction_outputPolyData->GetPointData()->SetScalars(suction_weights);
// Create a mapper and actor
vtkSmartPointer<vtkPolyDataMapper> mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(/*reverse->GetOutputPort()*/cf->GetOutputPort());
mapper->Modified();
mapper->ScalarVisibilityOn();
mapper->SetColorModeToMapScalars();
mapper->SetLookupTable(colorLookupTable);
mapper->SetScalarMaterialModeToDefault();
mapper->SetScalarRange(min,max);
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
//actor->GetProperty()->SetColor(1.0, 0.8941, 0.7686); // bisque
actor->SetMapper(mapper);
actor->Modified();
// Create a mapper and actor for suction blade
vtkSmartPointer<vtkPolyDataMapper> suction_mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
suction_mapper->SetInputConnection(/*reverse->GetOutputPort()*/suction_cf->GetOutputPort());
suction_mapper->Modified();
suction_mapper->ScalarVisibilityOn();
suction_mapper->SetColorModeToMapScalars();
suction_mapper->SetLookupTable(colorLookupTable_s);
suction_mapper->SetScalarMaterialModeToDefault();
suction_mapper->SetScalarRange(min_s,max_s);
vtkSmartPointer<vtkActor> suction_actor =
vtkSmartPointer<vtkActor>::New();
// actor->GetProperty()->SetColor(1.0, 0.8941, 0.7686); // bisque
suction_actor->SetMapper(suction_mapper);
suction_actor->Modified();
//Create a renderer, render window, and interactor
Renderer->SetBackground( 1, 1, 1 );
Renderer->Modified();
RenderWindow->AddRenderer(Renderer);
RenderWindow->Modified();
Interactor->SetRenderWindow(RenderWindow);
Interactor->Modified();
Renderer->AddActor(suction_actor);
Renderer->AddActor(actor);
RenderWindow->Render();
Interactor->Start();
points->Delete();
suction_points->Delete();
polydata->Delete();
suction_polydata->Delete();
outputPolyData->Delete();
suction_outputPolyData->Delete();
colorLookupTable->Delete();
colorLookupTable_s->Delete();
Renderer->Delete();
RenderWindow->Delete();
Interactor->Delete();
mapper->Delete();
suction_mapper->Delete();
And below is the code I used everytime user clicks an option.
void VTKRenderer::OnBnClickedP0button()
{
UpdateData(TRUE);
doc->getCFDData(pAirfoil,m_radioVal);
doc->viewCFData();
}
void CCooledTurbineDoc::getCFDData(CAirfoilObject *userAirfoil,int val){
double cfdVal;
newPts->Reset();
newPtsSuction->Reset();
ScalarValues_pressure.RemoveAll();
ScalarValues_suction.RemoveAll();
for (plane = 0; plane <t; plane++)
{
for (int j = 0; j <
userAirfoil->coolingObject->cfdModelSections[plane].PSpoints.GetSize(); j++)
{
CFDPointObject *pt2 =
&userAirfoil->coolingObject->cfdModelSections[plane].PSpoints[j];
switch (val){
case 0:
cfdVal = pt2->P0;
if (cfdVal != 0) {
newPts->InsertNextPoint(pt2->xx,pt2->y,pt2->z);
ScalarValues_pressure.Add(pt2->P0);
}
break;
case 1:
cfdVal = pt2->T0;
if (cfdVal != 0) {
newPts->InsertNextPoint(pt2->xx,pt2->y,pt2->z);
ScalarValues_pressure.Add(pt2->T0);
}
}
}
}
for (plane = 0; plane < t; plane++)
{
for (int j = 0; j <
userAirfoil->coolingObject->cfdModelSections[plane].SSpoints.GetSize(); j++)
{
CFDPointObject *pt3 =
&userAirfoil->coolingObject->cfdModelSections[plane].SSpoints[j];
if (pt3->P0 != 0) {
newPtsSuction->InsertNextPoint(pt3->xx,pt3->y,pt3->z);
ScalarValues_suction.Add(pt3->P0);
}
}
}
}
Please help me.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120215/9e19b195/attachment.htm>
More information about the vtkusers
mailing list