Skip to content
Snippets Groups Projects
Commit fffee384 authored by Andrew Maclean's avatar Andrew Maclean
Browse files

Running CppCheck on the Utilities files

parent b8f47ce0
No related branches found
No related tags found
No related merge requests found
......@@ -13,28 +13,27 @@
int main(int, char*[])
{
double sp;
auto colors =
vtkSmartPointer<vtkNamedColors>::New();
vtkSmartPointer<vtkNamedColors> colors =
vtkSmartPointer<vtkNamedColors>::New();
vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderWindow> renWin =
vtkSmartPointer<vtkRenderWindow>::New();
auto renderer =
vtkSmartPointer<vtkRenderer>::New();
auto renWin =
vtkSmartPointer<vtkRenderWindow>::New();
renWin->AddRenderer(renderer);
vtkSmartPointer<vtkRenderWindowInteractor> iren =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
auto iren =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
iren->SetRenderWindow(renWin);
vtkSmartPointer<vtkStructuredPoints> vol =
vtkSmartPointer<vtkStructuredPoints>::New();
auto vol =
vtkSmartPointer<vtkStructuredPoints>::New();
vol->SetDimensions(26, 26, 26);
vol->SetOrigin(-0.5, -0.5, -0.5);
sp = 1.0 / 25.0;
auto sp = 1.0 / 25.0;
vol->SetSpacing(sp, sp, sp);
vtkSmartPointer<vtkDoubleArray> scalars =
vtkSmartPointer<vtkDoubleArray>::New();
auto scalars =
vtkSmartPointer<vtkDoubleArray>::New();
scalars->SetNumberOfComponents(1);
scalars->SetNumberOfTuples(26 * 26 * 26);
for (auto k = 0; k < 26; k++)
......@@ -56,16 +55,17 @@ int main(int, char*[])
}
vol->GetPointData()->SetScalars(scalars);
vtkSmartPointer<vtkContourFilter> contour =
vtkSmartPointer<vtkContourFilter>::New();
auto contour =
vtkSmartPointer<vtkContourFilter>::New();
contour->SetInputData(vol);
contour->SetValue(0, 0.0);
vtkSmartPointer<vtkPolyDataMapper> volMapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
auto volMapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
volMapper->SetInputConnection(contour->GetOutputPort());
volMapper->ScalarVisibilityOff();
vtkSmartPointer<vtkActor> volActor = vtkSmartPointer<vtkActor>::New();
auto volActor =
vtkSmartPointer<vtkActor>::New();
volActor->SetMapper(volMapper);
volActor->GetProperty()->EdgeVisibilityOn();
volActor->GetProperty()->SetColor(colors->GetColor3d("Salmon").GetData());
......
#include <vtkSmartPointer.h>
#include <vtkSphereSource.h>
#include <vtkPolyData.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkCommand.h>
#include <vtkRenderer.h>
#include <vtkNamedColors.h>
#include <vtkPolyData.h>
#include <vtkPolyDataMapper.h>
#include <vtkProperty.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
#include <vtkSmartPointer.h>
#include <vtkSphereSource.h>
class vtkTimerCallback2 : public vtkCommand
{
public:
static vtkTimerCallback2 *New()
public:
vtkTimerCallback2() = default;
static vtkTimerCallback2* New()
{
vtkTimerCallback2* cb = new vtkTimerCallback2;
cb->TimerCount = 0;
return cb;
}
virtual void Execute(vtkObject* caller, unsigned long eventId,
void* vtkNotUsed(callData))
{
if (vtkCommand::TimerEvent == eventId)
{
vtkTimerCallback2 *cb = new vtkTimerCallback2;
cb->TimerCount = 0;
return cb;
++this->TimerCount;
}
std::cout << this->TimerCount << std::endl;
actor->SetPosition(this->TimerCount, this->TimerCount, 0);
if (this->TimerCount < this->maxCount)
{
virtual void Execute(vtkObject *caller, unsigned long eventId,
void * vtkNotUsed(callData))
vtkRenderWindowInteractor* iren =
dynamic_cast<vtkRenderWindowInteractor*>(caller);
iren->GetRenderWindow()->Render();
}
else
{
if (vtkCommand::TimerEvent == eventId)
vtkRenderWindowInteractor* iren =
dynamic_cast<vtkRenderWindowInteractor*>(caller);
if (this->timerId > -1)
{
++this->TimerCount;
iren->DestroyTimer(this->timerId);
}
std::cout << this->TimerCount << std::endl;
actor->SetPosition(this->TimerCount, this->TimerCount,0);
vtkRenderWindowInteractor *iren = dynamic_cast<vtkRenderWindowInteractor*>(caller);
iren->GetRenderWindow()->Render();
}
}
private:
int TimerCount = 0;
private:
int TimerCount;
public:
vtkActor* actor;
public:
vtkActor* actor = nullptr;
int timerId = 0;
int maxCount = -1;
};
int main(int, char* [])
int main(int, char*[])
{
auto colors =
vtkSmartPointer<vtkNamedColors>::New();
// Create a sphere
vtkSmartPointer<vtkSphereSource> sphereSource =
auto sphereSource =
vtkSmartPointer<vtkSphereSource>::New();
sphereSource->SetCenter(0.0, 0.0, 0.0);
sphereSource->SetRadius(5.0);
sphereSource->Update();
// Create a mapper and actor
vtkSmartPointer<vtkPolyDataMapper> mapper =
auto mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(sphereSource->GetOutputPort());
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
auto actor =
vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
actor->GetProperty()->SetColor(colors->GetColor3d("Salmon").GetData());
// Create a renderer, render window, and interactor
vtkSmartPointer<vtkRenderer> renderer =
auto renderer =
vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderWindow> renderWindow =
auto renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->AddRenderer(renderer);
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
auto renderWindowInteractor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderWindowInteractor->SetRenderWindow(renderWindow);
// Add the actor to the scene
renderer->AddActor(actor);
renderer->SetBackground(1,1,1); // Background color white
renderer->SetBackground(colors->GetColor3d("AliceBlue").GetData());
// Render and interact
renderWindow->Render();
......@@ -74,14 +100,15 @@ int main(int, char* [])
renderWindowInteractor->Initialize();
// Sign up to receive TimerEvent
vtkSmartPointer<vtkTimerCallback2> cb =
vtkSmartPointer<vtkTimerCallback2>::New();
auto cb = vtkSmartPointer<vtkTimerCallback2>::New();
cb->actor = actor;
renderWindowInteractor->AddObserver(vtkCommand::TimerEvent, cb);
int timerId = renderWindowInteractor->CreateRepeatingTimer(100);
std::cout << "timerId: " << timerId << std::endl;
// Destroy the timer when maxCount is reached.
cb->maxCount = 7;
cb->timerId = timerId;
// Start the interaction and timer
renderWindowInteractor->Start();
......
#include <vtkSmartPointer.h>
#include <vtkCellIterator.h>
#include <vtkGenericDataSet.h>
#include <vtkCellTypes.h>
#include <vtkGenericCell.h>
#include <vtkXMLGenericDataObjectReader.h>
#include <vtkGenericDataSet.h>
#include <vtkPointSet.h>
#include <vtkCellTypes.h>
#include <vtkSmartPointer.h>
#include <vtkXMLGenericDataObjectReader.h>
#include <map>
int main (int argc, char *argv[])
int main(int argc, char* argv[])
{
std::map<std::string, int> cellMap;
for (int arg = 1; arg < argc; ++arg)
{
vtkSmartPointer<vtkXMLGenericDataObjectReader> reader =
auto reader =
vtkSmartPointer<vtkXMLGenericDataObjectReader>::New();
reader->SetFileName(argv[arg]);
reader->Update();
// vtkPointSet *pointSet = vtkPointSet::SafeDownCast(reader->GetOutput());;
vtkPointSet *pointSet = dynamic_cast<vtkPointSet *>(reader->GetOutput());;
vtkSmartPointer<vtkCellIterator> it =
pointSet->NewCellIterator();
// vtkPointSet *pointSet =
// vtkPointSet::SafeDownCast(reader->GetOutput());;
vtkPointSet* pointSet = dynamic_cast<vtkPointSet*>(reader->GetOutput());
;
auto it = pointSet->NewCellIterator();
for (it->InitTraversal(); !it->IsDoneWithTraversal(); it->GoToNextCell())
{
vtkSmartPointer<vtkGenericCell> cell =
vtkSmartPointer<vtkGenericCell>::New();
auto cell = vtkSmartPointer<vtkGenericCell>::New();
it->GetCell(cell);
std::string cellName = vtkCellTypes::GetClassNameFromTypeId(cell->GetCellType());
std::string cellName =
vtkCellTypes::GetClassNameFromTypeId(cell->GetCellType());
if (cellMap.count(cellName) == 0)
{
std::cout << "Type: " << cellName
<< " has " << cell->GetNumberOfFaces() << " faces" << std::endl;
std::cout << "Type: " << cellName << " has " << cell->GetNumberOfFaces()
<< " faces" << std::endl;
}
cellMap[cellName]++;
}
it->Delete();
it->Delete();
}
std::map <std::string, int>::iterator itm = cellMap.begin();
for (itm = cellMap.begin(); itm != cellMap.end(); ++itm)
for (auto itm = cellMap.begin(); itm != cellMap.end(); ++itm)
{
std::cout << itm->first << " occurs " << itm->second << " times" << std::endl;
std::cout << itm->first << " occurs " << itm->second << " times"
<< std::endl;
}
return EXIT_SUCCESS;
......
#include <vtkSmartPointer.h>
#include <vtkCommand.h>
#include <vtkRenderer.h>
#include <vtkRendererCollection.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
#include <vtkRendererCollection.h>
#include <vtkSmartPointer.h>
class vtkTimerCallback : public vtkCommand
{
public:
static vtkTimerCallback *New()
public:
vtkTimerCallback() = default;
static vtkTimerCallback* New()
{
vtkTimerCallback* cb = new vtkTimerCallback;
cb->TimerCount = 0;
return cb;
}
virtual void Execute(vtkObject* caller, unsigned long eventId,
void* vtkNotUsed(callData))
{
if (vtkCommand::TimerEvent == eventId)
{
vtkTimerCallback *cb = new vtkTimerCallback;
cb->TimerCount = 0;
return cb;
++this->TimerCount;
}
virtual void Execute(vtkObject *vtkNotUsed(caller), unsigned long eventId,
void *vtkNotUsed(callData))
std::cout << this->TimerCount << std::endl;
if (this->TimerCount >= this->maxCount)
{
if (vtkCommand::TimerEvent == eventId)
vtkRenderWindowInteractor* iren =
dynamic_cast<vtkRenderWindowInteractor*>(caller);
if (this->timerId > -1)
{
++this->TimerCount;
iren->DestroyTimer(this->timerId);
}
cout << this->TimerCount << endl;
}
}
private:
int TimerCount;
private:
int TimerCount = 0;
public:
int maxCount = 0;
int timerId = -1;
};
int main(int, char *[])
int main(int, char*[])
{
// Setup renderer, render window, and interactor
vtkSmartPointer<vtkRenderer> renderer =
auto renderer =
vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderWindow> renderWindow =
auto renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->AddRenderer(renderer);
vtkSmartPointer<vtkRenderWindowInteractor> interactor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
auto interactor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
interactor->SetRenderWindow(renderWindow);
// Initialize must be called prior to creating timer events.
......@@ -47,13 +61,17 @@ int main(int, char *[])
interactor->Initialize();
// Sign up to receive TimerEvent
vtkSmartPointer<vtkTimerCallback> cb =
auto cb =
vtkSmartPointer<vtkTimerCallback>::New();
interactor->AddObserver(vtkCommand::TimerEvent, cb);
int timerId = interactor->CreateRepeatingTimer(100);
std::cout << "timerId: " << timerId << std::endl;
// Destroy the timer when maxCount is reached.
cb->maxCount = 10;
cb->timerId = timerId;
// Note: nothing is displayed in the render window.
// Start the interaction and timer
interactor->Start();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment