# 3DSImporter

VTKExamples/Cxx/IO/3DSImporter

### Code

3DSImporter.cxx

    #include <vtk3DSImporter.h>
    #include <vtkActor.h>
    #include <vtkActorCollection.h>
    #include <vtkCamera.h>
    #include <vtkNamedColors.h>
    #include <vtkProperty.h>
    #include <vtkRenderWindow.h>
    #include <vtkRenderWindowInteractor.h>
    #include <vtkRenderer.h>
    #include <vtkSmartPointer.h>

    int main (int argc, char *argv[])
    {
      if (argc < 2)
      {
        std::cout << "Usage: " << argv[0]
                  << " file.3ds"
                  << std::endl;
        return EXIT_FAILURE;
      }

      vtkSmartPointer<vtk3DSImporter> importer =
        vtkSmartPointer<vtk3DSImporter>::New();
      importer->SetFileName(argv[1]);
      importer->ComputeNormalsOn();

      vtkSmartPointer<vtkNamedColors> colors =
        vtkSmartPointer<vtkNamedColors>::New();

      vtkSmartPointer<vtkRenderer> renderer =
        vtkSmartPointer<vtkRenderer>::New();
      vtkSmartPointer<vtkRenderWindow> renWin =
        vtkSmartPointer<vtkRenderWindow>::New();
      vtkSmartPointer<vtkRenderWindowInteractor> iren =
        vtkSmartPointer<vtkRenderWindowInteractor>::New();

      renWin->AddRenderer(renderer);
      renderer->SetBackground2 (colors->GetColor3d("Gold").GetData());
      renderer->SetBackground (colors->GetColor3d("Wheat").GetData());
      renderer->GradientBackgroundOn();

      iren->SetRenderWindow(renWin);
      importer->SetRenderWindow(renWin);
      importer->Update();

      vtkSmartPointer<vtkActorCollection> actors =
        vtkSmartPointer<vtkActorCollection>::New();
      actors = renderer->GetActors();
      std::cout << "There are " << actors->GetNumberOfItems() << " actors" << std::endl;

      renWin->Render();
      vtkSmartPointer<vtkCamera> camera =
        vtkSmartPointer<vtkCamera>::New();
      camera->SetPosition (0, -1, 0);
      camera->SetFocalPoint (0, 0, 0);
      camera->SetViewUp (0, 0, 1);
      camera->Azimuth(150);
      camera->Elevation(30);

      renderer->SetActiveCamera(camera);
      renderer->ResetCamera();
      renderer->ResetCameraClippingRange();

      iren->Start();

      return EXIT_SUCCESS;
    }

### CMakeLists.txt

    cmake_minimum_required(VERSION 2.8)

    PROJECT(3DSImporter)

    find_package(VTK REQUIRED)
    include(${VTK_USE_FILE})

    add_executable(3DSImporter MACOSX_BUNDLE 3DSImporter.cxx )

    target_link_libraries(3DSImporter ${VTK_LIBRARIES})

### Download and Build 3DSImporter

Click here to download 3DSImporter and its CMakeLists.txt file. Once the tarball 3DSImporter.tar has been downloaded and extracted,

    cd 3DSImporter/build

If VTK is installed:

    cmake ..

If VTK is not installed but compiled on your system, you will need to specify the path to your VTK build:

    cmake -DVTK_DIR:PATH=/home/me/vtk_build ..

Build the project:

    make

and run it:

    ./3DSImporter

WINDOWS USERS

Be sure to add the VTK bin directory to your path. This will resolve the VTK dll's at run time.