1 
2 /*=========================================================================
3 
4   Program:   Visualization Toolkit
5   Module:    vtkRAdapter.h
6 
7   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
8   All rights reserved.
9   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
10 
11      This software is distributed WITHOUT ANY WARRANTY; without even
12      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13      PURPOSE.  See the above copyright notice for more information.
14 
15 =========================================================================*/
16 /*-------------------------------------------------------------------------
17   Copyright 2009 Sandia Corporation.
18   Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
19   the U.S. Government retains certain rights in this software.
20 -------------------------------------------------------------------------*/
21 
22 // .NAME vtkRAdapter - This is a utility class to convert VTK array data and
23 //  VTK tables to and from Gnu R S expression (SEXP) data structures.  It is used
24 //  with the R .Call interface and the embedded R interpreter.
25 //
26 // .SECTION Description
27 //
28 //  This class creates deep copies of input data.  Created R SEXP variables created
29 //  by these functions can be freed by the R garbage collector by calling UNPROTECT(1).
30 //  The conversions are performed for double and integer data types.
31 //
32 //  VTK data structures created by this class from R types are stored in array collections
33 //  and freed when the class destructor is called.  Use the Register() method on a returned
34 //  object to increase its reference count by one, in order keep the object around after this
35 //  classes destructor has been called.  The code calling Register() must eventually call Delete()
36 //  on the object to free memory.
37 //
38 // .SECTION See Also
39 //  vtkRinterface vtkRcalculatorFilter
40 //
41 // .SECTION Thanks
42 //  Developed by Thomas Otahal at Sandia National Laboratories.
43 //
44 
45 
46 #ifndef vtkRAdapter_h
47 #define vtkRAdapter_h
48 
49 #include "vtkFiltersStatisticsGnuRModule.h" // For export macro
50 #include "vtkObject.h"
51 #include "Rinternals.h" // Needed for Rinternals.h SEXP data structure
52 
53 class vtkInformation;
54 class vtkInformationVector;
55 class vtkDataArray;
56 class vtkArray;
57 class vtkTable;
58 class vtkTree;
59 class vtkDataArrayCollection;
60 class vtkArrayData;
61 class vtkDataObjectCollection;
62 
63 class VTKFILTERSSTATISTICSGNUR_EXPORT vtkRAdapter : public vtkObject
64 {
65 
66 public:
67 
68   vtkTypeMacro(vtkRAdapter, vtkObject);
69 
70   void PrintSelf(ostream& os, vtkIndent indent);
71 
72   static vtkRAdapter *New();
73 
74 //BTX
75   // Description:
76   // Create a vtkDataArray copy of GNU R input matrix vaiable (deep copy, allocates memory)
77   // Input is a R matrix or vector of doubles or integers
78   vtkDataArray* RToVTKDataArray(SEXP variable);
79 
80   // Description:
81   // Create a vtkArray copy of the GNU R input variable multi-dimensional array (deep copy, allocates memory)
82   // Input is a R multi-dimensional array of doubles or integers
83   vtkArray* RToVTKArray(SEXP variable);
84 
85   // Description:
86   // Create a GNU R matrix copy of the input vtkDataArray da (deep copy, allocates memory)
87   SEXP VTKDataArrayToR(vtkDataArray* da);
88 
89   // Description:
90   // Create a GNU R multi-dimensional array copy of the input vtkArray da (deep copy, allocates memory)
91   SEXP VTKArrayToR(vtkArray* da);
92 
93   // Description:
94   // Create a GNU R matrix copy of the input vtkTable table (deep copy, allocates memory)
95   SEXP VTKTableToR(vtkTable* table);
96 
97   // Description:
98   // Create a vtkTable copy of the GNU R input matrix variable (deep copy, allocates memory)
99   // Input is R list of equal length vectors or a matrix.
100   vtkTable* RToVTKTable(SEXP variable);
101 
102   // Description:
103   // Create a GNU R phylo tree copy of the input vtkTree tree (deep copy, allocates memory)
104   SEXP VTKTreeToR(vtkTree* tree);
105 
106   // Description:
107   // Create a vtkTree copy of the GNU R input phylo tree variable (deep copy, allocates memory)
108   vtkTree* RToVTKTree(SEXP variable);
109 //ETX
110 
111 protected:
112   vtkRAdapter();
113   ~vtkRAdapter();
114 
115 private:
116 
117   vtkRAdapter(const vtkRAdapter&); // Not implemented
118   void operator=(const vtkRAdapter&); // Not implemented
119 
120   vtkDataArrayCollection* vdac;  // Collection of vtkDataArrays that have been converted from R.
121   vtkArrayData* vad;  // Collection of vtkArrays that have been converted from R.
122   vtkDataObjectCollection* vdoc; // Collection of vtkTables that have been converted from R.
123 
124 };
125 
126 
127 #endif
128 
129 
130 
131