Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Matt Larsen
VTK-m
Commits
b48ee6a5
Commit
b48ee6a5
authored
Aug 29, 2016
by
Matt Larsen
Browse files
Large cell extraction
parent
bb920ba0
Changes
2
Hide whitespace changes
Inline
Side-by-side
vtkm/rendering/TetrahedralVR.h
View file @
b48ee6a5
...
...
@@ -3,12 +3,13 @@
#include
<vtkm/cont/ArrayHandleCompositeVector.h>
#include
<vtkm/cont/ArrayHandleIndex.h>
#include
<vtkm/cont/ArrayPortalToIterators.h>
#include
<vtkm/cont/CellSetSingleType.h>
#include
<vtkm/rendering/Camera.h>
#include
<vtkm/rendering/CanvasRayTracer.h>
#include
<vtkm/rendering/ColorTable.h>
#include
<vtkm/rendering/raytracing/RayTracingTypeDefs.h>
#include
<vtkm/rendering/raytracing/Worklets.h>
namespace
vtkm
{
namespace
rendering
{
...
...
@@ -23,6 +24,54 @@ struct SubsetExtent
vtkm
::
Int32
MinZ
;
// Min z (depth) position
};
struct
LargeCells
{
// Stored as x,y,z,scalar (4 Values)
// 4 points per cell, so one cell is
// 4 * 4 = 16 floats per cell. Coordinates
// are already in screen space.
vtkm
::
cont
::
ArrayHandle
<
vtkm
::
Float32
>
CellData
;
vtkm
::
Id
GetNumberOfCells
()
{
return
CellData
.
GetNumberOfValues
()
/
16
;
}
// returns offset to cell in array;
// -1 if the Index is out of bounds
vtkm
::
Id
GetStartingIndex
(
const
vtkm
::
Id
&
cellNum
)
{
if
(
cellNum
>=
this
->
GetNumberOfCells
()
||
cellNum
<
0
)
{
std
::
cout
<<
"LargeCell (Starting Index): bad cell Id "
<<
cellNum
<<
"
\n
"
;
return
-
1
;
}
return
cellNum
*
16
;
}
// returns pointer to cell in array;
// NULL if the Index is out of bounds
vtkm
::
Float32
*
GetCellPointer
(
const
vtkm
::
Id
&
cellNum
)
{
if
(
cellNum
>=
this
->
GetNumberOfCells
()
||
cellNum
<
0
)
{
std
::
cout
<<
"LargeCell (Cell Pointer): bad cell Id "
<<
cellNum
<<
"
\n
"
;
return
NULL
;
}
//We need to extract the type of portal to get to the raw pointer underneath
typedef
vtkm
::
cont
::
ArrayHandle
<
vtkm
::
Float32
>::
PortalControl
PortalType
;
vtkm
::
cont
::
ArrayPortalToIterators
<
PortalType
>
it
(
this
->
CellData
.
GetPortalControl
());
vtkm
::
Float32
*
begining
=
&
(
*
it
.
GetBegin
());
return
(
begining
+
cellNum
*
16
);
}
};
template
<
typename
DeviceAdapter
>
class
TetrahedralVR
{
...
...
@@ -104,6 +153,8 @@ public:
const
ScalarPortalType
&
scalarPortal
,
const
vtkm
::
Id
&
index
)
const
{
// Don't sample the large cells
if
(
classification
==
1
)
return
;
vtkm
::
Id
cellOffset
=
index
*
4
;
// Load cell connectivity
...
...
@@ -240,7 +291,7 @@ public:
}
//operator()
};
//class Sampler
class
ScreenSpaceTransform
:
public
vtkm
::
worklet
::
WorkletMapField
class
ScreenSpaceTransform
:
public
vtkm
::
worklet
::
WorkletMapField
{
protected:
vtkm
::
Matrix
<
vtkm
::
Float32
,
4
,
4
>
ViewProjMat
;
...
...
@@ -303,6 +354,100 @@ public:
}
};
//class Screen space
class
CompactLargeCells
:
public
vtkm
::
worklet
::
WorkletMapField
{
protected:
public:
VTKM_CONT_EXPORT
CompactLargeCells
()
{
}
typedef
void
ControlSignature
(
FieldIn
<>
,
WholeArrayIn
<>
,
WholeArrayIn
<
raytracing
::
ScalarRenderingTypes
>
,
WholeArrayIn
<>
,
WholeArrayOut
<>
);
typedef
void
ExecutionSignature
(
_1
,
_2
,
_3
,
_4
,
_5
,
WorkIndex
);
template
<
typename
CoordPortalType
,
typename
ScalarPortalType
,
typename
ConnPortalType
,
typename
OutputPortalType
>
VTKM_EXEC_EXPORT
void
operator
()(
const
vtkm
::
Id
&
cellId
,
const
CoordPortalType
&
coords
,
const
ScalarPortalType
&
scalarPortal
,
const
ConnPortalType
&
conn
,
const
OutputPortalType
&
output
,
const
vtkm
::
Id
&
index
)
const
{
vtkm
::
Id
cellOffset
=
cellId
*
4
;
printf
(
"Large cell %d
\n
"
,
int
(
cellId
));
// Load cell connectivity
typename
ConnPortalType
::
ValueType
cellConn
[
4
];
for
(
vtkm
::
Int32
i
=
0
;
i
<
4
;
++
i
)
{
BOUNDS_CHECK
(
conn
,
cellOffset
+
i
);
cellConn
[
i
]
=
conn
.
Get
(
cellOffset
+
i
);
}
// Load cell points
vtkm
::
Vec
<
vtkm
::
Float32
,
3
>
points
[
4
];
vtkm
::
Float32
scalars
[
4
];
for
(
vtkm
::
Int32
i
=
0
;
i
<
4
;
++
i
)
{
BOUNDS_CHECK
(
coords
,
cellConn
[
i
]);
points
[
i
]
=
vtkm
::
Vec
<
vtkm
::
Float32
,
3
>
(
coords
.
Get
(
cellConn
[
i
]));
BOUNDS_CHECK
(
scalarPortal
,
cellConn
[
i
]);
scalars
[
i
]
=
vtkm
::
Float32
(
scalarPortal
.
Get
(
cellConn
[
i
]));
}
// write all the data out to a compact location
const
vtkm
::
Id
startIndex
=
index
*
16
;
BOUNDS_CHECK
(
output
,
startIndex
+
0
);
output
.
Set
(
startIndex
+
0
,
points
[
0
][
0
]);
BOUNDS_CHECK
(
output
,
startIndex
+
1
);
output
.
Set
(
startIndex
+
1
,
points
[
0
][
1
]);
BOUNDS_CHECK
(
output
,
startIndex
+
2
);
output
.
Set
(
startIndex
+
2
,
points
[
0
][
2
]);
BOUNDS_CHECK
(
output
,
startIndex
+
3
);
output
.
Set
(
startIndex
+
3
,
scalars
[
0
]);
BOUNDS_CHECK
(
output
,
startIndex
+
4
);
output
.
Set
(
startIndex
+
4
,
points
[
1
][
0
]);
BOUNDS_CHECK
(
output
,
startIndex
+
5
);
output
.
Set
(
startIndex
+
5
,
points
[
1
][
1
]);
BOUNDS_CHECK
(
output
,
startIndex
+
6
);
output
.
Set
(
startIndex
+
6
,
points
[
1
][
2
]);
BOUNDS_CHECK
(
output
,
startIndex
+
7
);
output
.
Set
(
startIndex
+
7
,
scalars
[
1
]);
BOUNDS_CHECK
(
output
,
startIndex
+
8
);
output
.
Set
(
startIndex
+
8
,
points
[
2
][
0
]);
BOUNDS_CHECK
(
output
,
startIndex
+
9
);
output
.
Set
(
startIndex
+
9
,
points
[
2
][
1
]);
BOUNDS_CHECK
(
output
,
startIndex
+
10
);
output
.
Set
(
startIndex
+
10
,
points
[
2
][
2
]);
BOUNDS_CHECK
(
output
,
startIndex
+
11
);
output
.
Set
(
startIndex
+
11
,
scalars
[
2
]);
BOUNDS_CHECK
(
output
,
startIndex
+
12
);
output
.
Set
(
startIndex
+
12
,
points
[
3
][
0
]);
BOUNDS_CHECK
(
output
,
startIndex
+
13
);
output
.
Set
(
startIndex
+
13
,
points
[
3
][
1
]);
BOUNDS_CHECK
(
output
,
startIndex
+
14
);
output
.
Set
(
startIndex
+
14
,
points
[
3
][
2
]);
BOUNDS_CHECK
(
output
,
startIndex
+
15
);
output
.
Set
(
startIndex
+
15
,
scalars
[
3
]);
}
};
//class Screen space
class
Composite
:
public
vtkm
::
worklet
::
WorkletMapField
{
protected:
...
...
@@ -695,7 +840,7 @@ public:
zmax
=
vtkm
::
Ceil
(
vtkm
::
Min
(
vtkm
::
Max
(
0.
f
,
zmax
),
vtkm
::
Float32
(
this
->
Depth
)
));
vtkm
::
Float32
area
=
(
xmax
-
xmin
)
*
(
ymax
-
ymin
)
*
(
zmax
-
zmin
);
//printf("Area %f \n", area);
//
printf("Area %f \n", area);
if
(
area
>
CellAreaThreshold
)
classification
=
1
;
// Large cell
}
...
...
@@ -754,7 +899,7 @@ public:
VTKM_CONT_EXPORT
void
SetDebugLevel
(
const
vtkm
::
Int32
&
level
)
{
{
DebugLevel
=
level
;
};
...
...
@@ -942,6 +1087,51 @@ public:
}
VTKM_CONT_EXPORT
vtkm
::
Id
CountLargeCells
()
{
vtkm
::
cont
::
ArrayHandle
<
vtkm
::
UInt8
>
masks
;
vtkm
::
worklet
::
DispatcherMapField
<
raytracing
::
Mask
<
vtkm
::
UInt8
>
,
DeviceAdapter
>
(
raytracing
::
Mask
<
vtkm
::
UInt8
>
(
1
)).
Invoke
(
this
->
CellClassifications
,
masks
);
vtkm
::
cont
::
ArrayHandleCast
<
vtkm
::
Id
,
vtkm
::
cont
::
ArrayHandle
<
vtkm
::
UInt8
>
>
castedMasks
(
masks
);
const
vtkm
::
Id
initVal
=
0
;
vtkm
::
Id
count
=
vtkm
::
cont
::
DeviceAdapterAlgorithm
<
DeviceAdapter
>::
Reduce
(
castedMasks
,
initVal
);
return
count
;
}
VTKM_CONT_EXPORT
void
GetLargeCells
(
LargeCells
&
cells
)
{
vtkm
::
cont
::
ArrayHandleCounting
<
vtkm
::
Id
>
cellIds
(
0
,
1
,
this
->
CellClassifications
.
GetNumberOfValues
());
vtkm
::
cont
::
ArrayHandle
<
vtkm
::
UInt8
>
masks
;
vtkm
::
worklet
::
DispatcherMapField
<
raytracing
::
Mask
<
vtkm
::
UInt8
>
,
DeviceAdapter
>
(
raytracing
::
Mask
<
vtkm
::
UInt8
>
(
1
)).
Invoke
(
this
->
CellClassifications
,
masks
);
//vtkm::cont::ArrayHandleCast<vtkm::Id,vtkm::cont::ArrayHandle<vtkm::UInt8> > castedMasks(masks);
vtkm
::
cont
::
ArrayHandle
<
vtkm
::
Id
>
largeCellIds
;
vtkm
::
cont
::
DeviceAdapterAlgorithm
<
DeviceAdapter
>::
StreamCompact
(
cellIds
,
masks
,
largeCellIds
);
vtkm
::
Id
largeCellCount
=
largeCellIds
.
GetNumberOfValues
();
cells
.
CellData
.
PrepareForOutput
(
largeCellCount
*
16
,
DeviceAdapter
());
vtkm
::
worklet
::
DispatcherMapField
<
CompactLargeCells
,
DeviceAdapter
>
(
CompactLargeCells
(
)
)
.
Invoke
(
largeCellIds
,
this
->
ScreenSpaceCoords
,
this
->
ScalarField
.
GetData
(),
this
->
CellSet
.
GetConnectivityArray
(
vtkm
::
TopologyElementTagPoint
(),
vtkm
::
TopologyElementTagCell
()
),
cells
.
CellData
);
}
VTKM_CONT_EXPORT
void
Run
(
CanvasRayTracer
*
canvas
)
...
...
@@ -971,7 +1161,10 @@ public:
this
->
CoordinatesToScreenSpace
();
this
->
CellClassification
();
if
(
DebugLevel
>
0
)
std
::
cout
<<
"Large Cells "
<<
this
->
CountLargeCells
()
<<
"
\n
"
;
this
->
SampleCells
();
this
->
CompositeSamples
(
canvas
);
...
...
@@ -983,7 +1176,9 @@ public:
this
->
GetPartialComposites
(
partialCompIds
,
depthIds
,
partialComps
);
LargeCells
largeCells
;
this
->
GetLargeCells
(
largeCells
);
}
...
...
@@ -1012,7 +1207,8 @@ protected:
vtkm
::
worklet
::
DispatcherMapField
<
ClassifyCell
>
(
ClassifyCell
(
this
->
ViewProjectionMat
,
this
->
Width
,
this
->
Height
,
this
->
Depth
)
)
this
->
Depth
,
2
)
)
.
Invoke
(
this
->
CellClassifications
,
this
->
CellSet
.
GetConnectivityArray
(
vtkm
::
TopologyElementTagPoint
(),
vtkm
::
TopologyElementTagCell
()
),
...
...
@@ -1109,7 +1305,7 @@ protected:
pixelIndexes
,
depthIndexes
);
}
};
...
...
vtkm/rendering/raytracing/Worklets.h
View file @
b48ee6a5
...
...
@@ -44,6 +44,59 @@ public:
}
};
//class MemSet
template
<
class
T
>
class
Mask
:
public
vtkm
::
worklet
::
WorkletMapField
{
T
Value
;
public:
VTKM_CONT_EXPORT
Mask
(
T
value
)
:
Value
(
value
)
{}
typedef
void
ControlSignature
(
FieldIn
<>
,
FieldOut
<>
);
typedef
void
ExecutionSignature
(
_1
,
_2
);
template
<
typename
O
>
VTKM_EXEC_EXPORT
void
operator
()(
const
T
&
inValue
,
O
&
outValue
)
const
{
if
(
inValue
==
Value
)
outValue
=
static_cast
<
O
>
(
1
);
else
outValue
=
static_cast
<
O
>
(
0
);
}
};
//class mask
template
<
class
T
,
int
N
>
class
ManyMask
:
public
vtkm
::
worklet
::
WorkletMapField
{
vtkm
::
Vec
<
T
,
N
>
Values
;
public:
VTKM_CONT_EXPORT
ManyMask
(
vtkm
::
Vec
<
T
,
N
>
values
)
:
Values
(
values
)
{}
typedef
void
ControlSignature
(
FieldIn
<>
,
FieldOut
<>
);
typedef
void
ExecutionSignature
(
_1
,
_2
);
template
<
typename
O
>
VTKM_EXEC_EXPORT
void
operator
()(
const
T
&
inValue
,
O
&
outValue
)
const
{
bool
doMask
=
false
;
for
(
vtkm
::
Int32
i
=
0
;
i
<
N
;
++
i
)
{
if
(
inValue
==
Values
[
i
])
doMask
=
true
;
}
if
(
doMask
)
outValue
=
static_cast
<
O
>
(
1
);
else
outValue
=
static_cast
<
O
>
(
0
);
}
};
//class doube mask
struct
MaxValue
{
template
<
typename
T
>
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment