File: VTK_reader.h

package info (click to toggle)
cgal 6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 144,912 kB
  • sloc: cpp: 810,858; ansic: 208,477; sh: 493; python: 411; makefile: 286; javascript: 174
file content (93 lines) | stat: -rw-r--r-- 2,300 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// Copyright (c) 2018
// GeometryFactory (France) All rights reserved.
//
// This file is part of CGAL (www.cgal.org)
//
// $URL: https://github.com/CGAL/cgal/blob/v6.1/Stream_support/include/CGAL/IO/VTK/VTK_reader.h $
// $Id: include/CGAL/IO/VTK/VTK_reader.h b26b07a1242 $
// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial
//
//
// Author(s)     : Stephane Tayeb

#ifndef CGAL_IO_VTK_READER_H
#define CGAL_IO_VTK_READER_H

#ifdef CGAL_USE_VTK

#include <vtkSmartPointer.h>
#include <vtkCommand.h>

#include <string>

namespace CGAL {
namespace IO {
namespace internal {

class ErrorObserverVtk
  : public vtkCommand
{
public:
  ErrorObserverVtk()
    : Error(false), Warning(false), ErrorMessage(""), WarningMessage("")
  { }

  static ErrorObserverVtk *New() { return new ErrorObserverVtk; }

  bool GetError() const { return this->Error; }
  bool GetWarning() const { return this->Warning; }
  std::string GetErrorMessage() { return ErrorMessage; }
  std::string GetWarningMessage() { return WarningMessage; }

  void Clear()
  {
    this->Error = false;
    this->Warning = false;
    this->ErrorMessage = "";
    this->WarningMessage = "";
  }

  virtual void Execute(vtkObject *vtkNotUsed(caller),
                       unsigned long event,
                       void *calldata)
  {
    switch (event)
    {
      case vtkCommand::ErrorEvent:
        ErrorMessage = static_cast<char *>(calldata);
        this->Error = true;
        break;
      case vtkCommand::WarningEvent:
        WarningMessage = static_cast<char *>(calldata);
        this->Warning = true;
        break;
    }
  }

private:
  bool Error;
  bool Warning;
  std::string ErrorMessage;
  std::string WarningMessage;
};

template <class vtkReader>
vtkSmartPointer<vtkReader> read_vtk_file(const std::string& fname,
                                         vtkSmartPointer<ErrorObserverVtk> errorObserver)
{
  vtkSmartPointer<vtkReader> reader = vtkSmartPointer<vtkReader>::New();
  reader->AddObserver(vtkCommand::ErrorEvent, errorObserver);
  reader->AddObserver(vtkCommand::WarningEvent, errorObserver);
  reader->SetFileName(fname.data());
  reader->Update();

  return reader;
}

} // namespace internal
} // namespace IO
} // namespace CGAL

#endif // CGAL_USE_VTK

#endif // CGAL_IO_VTK_READER_H