#include "qvtkwidgetrendu3d.h"

#include <QtDebug>
#include <QFile>
#include <QDir>
#include <QTimer>
#include <vtkProperty.h>

#include <iostream>
using namespace std;

QVTKWidgetRendu3d::QVTKWidgetRendu3d() : QVTKWidget()
{
    resize(512,512);

    // Setup points
    points = vtkSmartPointer<vtkPoints>::New();

     // Setup the colors array
    colors = vtkSmartPointer<vtkUnsignedCharArray>::New();
    colors->SetNumberOfComponents(3);    
    colors->SetName("Colors");

    // create a vertex
    vertex = vtkSmartPointer<vtkVertex>::New();

    // list of all the vertices
    vertices= vtkSmartPointer<vtkCellArray>::New();

    nb_points = 3;
    points->Resize(nb_points);
    vertices->Initialize();
    colors->Initialize();

    points->SetPoint(0, 0.1, 0.0, 0.0);
    vertex->GetPointIds()->SetId(0,0);
    vertices->InsertNextCell(vertex);
    colors->InsertNextTuple3(255,0,0);

    points->SetPoint(1, 0, 0.1, 0.0);
    vertex->GetPointIds()->SetId(0,1);
    vertices->InsertNextCell(vertex);
    colors->InsertNextTuple3(0,255,0);

    points->SetPoint(2, 0, 0.0, 0.1);
    vertex->GetPointIds()->SetId(0,2);
    vertices->InsertNextCell(vertex);
    colors->InsertNextTuple3(0,0,255);

    // Create a polydata object and add everything to it
    polydata = vtkSmartPointer<vtkPolyData>::New();
    polydata->SetPoints(points);
    polydata->SetVerts(vertices);
    polydata->GetPointData()->SetScalars(colors);

    mapper = vtkSmartPointer<vtkPolyDataMapper>::New();

    mapper->SetInputData(polydata);

    actor = vtkSmartPointer<vtkActor>::New();
    actor->SetMapper(mapper);
    actor->GetProperty()->SetPointSize(5);

    // Setup window
    renderWindow = vtkSmartPointer<vtkRenderWindow>::New();

    // Setup renderer
    renderer = vtkSmartPointer<vtkRenderer>::New();
    renderWindow->AddRenderer(renderer);

    renderer->AddActor(actor);
    renderer->ResetCamera();

    this->SetRenderWindow(renderWindow);

    this->show();
}


