VTK
Allocators.h
Go to the documentation of this file.
1//=============================================================================
2//
3// Copyright (c) Kitware, Inc.
4// All rights reserved.
5// See LICENSE.txt for details.
6//
7// This software is distributed WITHOUT ANY WARRANTY; without even
8// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
9// PURPOSE. See the above copyright notice for more information.
10//
11// Copyright 2012 Sandia Corporation.
12// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
13// the U.S. Government retains certain rights in this software.
14//
15//=============================================================================
16
17#ifndef vtkToDax_Allocators_h
18#define vtkToDax_Allocators_h
19
20#include <dax/VectorTraits.h>
21#include <cstddef>
22
23class vtkPoints;
24class vtkCellArray;
25
26/*
27 * The one rule of allocators is that they can allocate
28 * memory, but they can't set any values in the allocated memory.
29 * We can't write to the memory because that causes affinity
30 * between the memory location and the current thread, which is a very
31 * bad thing as we want that memory location affinity to be assigned to the dax
32 * thread that will be using section, not the master thread
33 */
34
35namespace vtkToDax
36{
37template< typename _T,
38 int NUM_COMPONENTS>
40{
41 typedef _T T;
43
44 typedef std::size_t size_type;
45 typedef ptrdiff_t difference_type;
46 typedef T* pointer;
47 typedef const T* const_pointer;
48 typedef T& reference;
49 typedef const T& const_reference;
50 typedef T value_type;
51
52
54 {
55 pointer p = value_type::New();
56 p->SetNumberOfComponents(NUM_COMPONENTS);
57 p->SetNumberOfTuples(n);
58 return p;
59 }
60
62 {
63 p->Delete();
64 }
65};
66
67template<int NUM_COMPONENTS>
68struct vtkAlloc<vtkPoints, NUM_COMPONENTS>
69{
70 typedef vtkPoints T;
72
73 typedef std::size_t size_type;
74 typedef ptrdiff_t difference_type;
75 typedef T* pointer;
76 typedef const T* const_pointer;
77 typedef T& reference;
78 typedef const T& const_reference;
79 typedef T value_type;
80
81
83 {
84#ifdef DAX_USE_DOUBLE_PRECISION
85 pointer p = value_type::New(VTK_DOUBLE);
86#else
87 pointer p = value_type::New(VTK_FLOAT);
88#endif
90 return p;
91 }
92
94 {
95 p->Delete();
96 }
97};
98
99
100template<int NUM_COMPONENTS>
101struct vtkAlloc<vtkCellArray, NUM_COMPONENTS>
102{
105
106 typedef std::size_t size_type;
107 typedef ptrdiff_t difference_type;
108 typedef T* pointer;
109 typedef const T* const_pointer;
110 typedef T& reference;
111 typedef const T& const_reference;
112 typedef T value_type;
113
114
115 //for cell arrays dax requests an allocation that is num_cells * num_components
117 {
118 pointer p = value_type::New();
119 const size_type numCells = n/NUM_COMPONENTS;
120 p->SetNumberOfCells(numCells);
121 p->GetData()->SetNumberOfTuples(n+numCells);
122 return p;
123 }
124
126 {
127 p->Delete();
128 }
129};
130}
131
132#endif //vtkToDax_Allocators_h
virtual void SetNumberOfTuples(vtkIdType numTuples)=0
Set the number of tuples (a component group) in the array.
object to represent cell connectivity
Definition: vtkCellArray.h:51
vtkIdTypeArray * GetData()
Return the underlying data as a data array.
Definition: vtkCellArray.h:256
virtual void SetNumberOfCells(vtkIdType)
Set the number of cells in the array.
virtual void Delete()
Delete a VTK object.
represent and manipulate 3D points
Definition: vtkPoints.h:40
void SetNumberOfPoints(vtkIdType numPoints)
Specify the number of points for this object to hold.
Definition: vtkPoints.h:252
pointer allocate(size_type n, const_pointer hint=0)
Definition: Allocators.h:116
pointer allocate(size_type n, const_pointer hint=0)
Definition: Allocators.h:82
vtkAlloc< T, NUM_COMPONENTS > self
Definition: Allocators.h:71
const T & const_reference
Definition: Allocators.h:49
std::size_t size_type
Definition: Allocators.h:44
void deallocate(self::pointer p, self::size_type)
Definition: Allocators.h:61
ptrdiff_t difference_type
Definition: Allocators.h:45
vtkAlloc< T, NUM_COMPONENTS > self
Definition: Allocators.h:42
const T * const_pointer
Definition: Allocators.h:47
pointer allocate(size_type n, self::const_pointer hint=0)
Definition: Allocators.h:53
#define VTK_DOUBLE
Definition: vtkType.h:59
#define VTK_FLOAT
Definition: vtkType.h:58