Commit 258997d0 authored by cyrush's avatar cyrush

add serial merge_tree, split_tree, and local_threshold expressions

git-svn-id: http://visit.ilight.com/svn/visit/trunk/src@29524 18c085ea-50e0-402c-830e-de6fd14e8384
parent eb154f2c
......@@ -75,6 +75,9 @@
# Kevin Griffin, Tue Jul 29 10:08:40 PDT 2014
# Added q_criterion.
#
# Timo Bremer, Fri Oct 28 09:09:27 PDT 2016
# Added merge tree and local threshold.
#
#****************************************************************************/
SET(ABSTRACT_SOURCES
......@@ -167,10 +170,12 @@ General/avtIsNaNExpression.C
General/avtKeyAggregatorExpression.C
General/avtLambda2Expression.C
General/avtLaplacianExpression.C
General/avtLocalThresholdExpression.C
General/avtMIRvfExpression.C
General/avtMagnitudeExpression.C
General/avtMatErrorExpression.C
General/avtMatvfExpression.C
General/avtMergeTreeExpression.C
General/avtMeshCoordinateExpression.C
General/avtMinMaxExpression.C
General/avtNMatsExpression.C
......
This diff is collapsed.
/*****************************************************************************
*
* Copyright (c) 2000 - 2016, Lawrence Livermore National Security, LLC
* Produced at the Lawrence Livermore National Laboratory
* LLNL-CODE-442911
* All rights reserved.
*
* This file is part of VisIt. For details, see https://visit.llnl.gov/. The
* full copyright notice is contained in the file COPYRIGHT located at the root
* of the VisIt distribution or at http://www.llnl.gov/visit/copyright.html.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the disclaimer below.
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the disclaimer (as noted below) in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of the LLNS/LLNL nor the names of its contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL SECURITY,
* LLC, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
*****************************************************************************/
// ************************************************************************* //
// avtLocalThresholdExpression.h //
// ************************************************************************* //
#ifndef AVT_LOCALTHRESHOLD_EXPRESSION_H
#define AVT_LOCALTHRESHOLD_EXPRESSION_H
#include <avtMultipleInputExpressionFilter.h>
#include <avtMergeTreeExpression.h>
#include <vtkSmartPointer.h>
class vtkDataArray;
class ArgsExpr;
class ExprPipelineState;
class ConstExpr;
// ****************************************************************************
// Class: avtLocalThresholdExpression
//
// Purpose:
// Uses a merge/split tree to apply a local threshold to a scalar
// function.
//
// Programmer: Peer-Timo Bremer
// Creation: August 8, 2016
//
// ****************************************************************************
class EXPRESSION_API avtLocalThresholdExpression : public avtMultipleInputExpressionFilter
{
public:
enum TransformationType
{
RELEVANCE = 0,
UNDEFINED = 1,
};
static const char* TransformationName[];
avtLocalThresholdExpression();
virtual ~avtLocalThresholdExpression();
virtual int NumVariableArguments()
{return 2;}
virtual const char *GetType(void)
{ return "avtLocalThresholdExpression"; };
virtual const char *GetDescription(void)
{return "Apply a local threshold using a merge tree";};
virtual void ProcessArguments(ArgsExpr*, ExprPipelineState *);
protected:
virtual int GetVariableDimension(void)
{ return 1; };
virtual vtkDataArray *DeriveVariable(vtkDataSet *,
int currentDomainsIndex);
// helpers used to implement the local threshold
class Transformation
{
public:
virtual double eval(vtkMergeTree* tree,
vtkDataArray* function,
vtkDataArray* labels,
vtkIdType index) = 0;
virtual double fillValue() {return 0;}
};
class Relevance : public Transformation
{
public:
virtual double eval(vtkMergeTree* tree,
vtkDataArray* function,
vtkDataArray* labels,
vtkIdType index);
};
TransformationType DetermineTransformationType(const std::string& name);
private:
TransformationType transformation;
};
#endif /* AVT_LOCALTHRESHOLD_EXPRESSION_H */
This diff is collapsed.
/*****************************************************************************
*
* Copyright (c) 2000 - 2016, Lawrence Livermore National Security, LLC
* Produced at the Lawrence Livermore National Laboratory
* LLNL-CODE-442911
* All rights reserved.
*
* This file is part of VisIt. For details, see https://visit.llnl.gov/. The
* full copyright notice is contained in the file COPYRIGHT located at the root
* of the VisIt distribution or at http://www.llnl.gov/visit/copyright.html.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the disclaimer below.
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the disclaimer (as noted below) in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of the LLNS/LLNL nor the names of its contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL SECURITY,
* LLC, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
*****************************************************************************/
// ************************************************************************* //
// avtLocalThresholdExpression.C //
// ************************************************************************* //
#ifndef AVT_MERGETREE_EXPRESSION_H
#define AVT_MERGETREE_EXPRESSION_H
#include <avtSingleInputExpressionFilter.h>
#include <vtkMergeTree.h>
#include <vtkSmartPointer.h>
class vtkDataArray;
class ArgsExpr;
class ExprPipelineState;
class ConstExpr;
// ****************************************************************************
// Class: avtMergeTreeExpression
//
// Purpose:
// Creates the merge/split tree of a scalar function and the corresponding
// per-branch labels
//
// Programmer: Peer-Timo Bremer
// Creation: August 8, 2016
//
// ****************************************************************************
class EXPRESSION_API avtMergeTreeExpression : public avtSingleInputExpressionFilter
{
public:
// The internal Tree
static vtkMergeTree* tree;
// Invalid segmentation id
static const vtkTypeUInt32 LNULL = (vtkTypeUInt32)-1;
avtMergeTreeExpression(bool mt = true);
virtual ~avtMergeTreeExpression();
virtual const char *GetType(void)
{ return "avtMergeTreeExpression"; };
virtual const char *GetDescription(void)
{return "Compute the merge tree";};
virtual void ProcessArguments(ArgsExpr*,
ExprPipelineState *);
protected:
// Internal comparison operator
class Greater
{
public:
vtkDataArray* Function;
// Cyrus todo:: don't inline constructors
Greater(vtkDataArray* f);
bool operator()(vtkIdType u, vtkIdType v)
{return this->Function->GetTuple1(u) > this->Function->GetTuple1(v);}
};
// Description
// Abstract base class for different dataset types
class NeighborhoodIterator
{
public:
NeighborhoodIterator(vtkDataSet* data);
virtual ~NeighborhoodIterator();
virtual void initialize(vtkIdType v) = 0;
virtual void operator++(int i) = 0;
virtual vtkIdType id() = 0;
virtual bool end() = 0;
};
// Iterate through node neighborhood iterator
class NodeIterator : public NeighborhoodIterator
{
public:
NodeIterator(vtkDataSet* data);
virtual ~NodeIterator();
virtual void initialize(vtkIdType v);
virtual void operator++(int i)
{nIt++;}
virtual vtkIdType id()
{return *nIt;}
virtual bool end()
{return (nIt == Neighbors.end());}
private:
vtkDataSet* DataSet;
std::set<vtkIdType> Neighbors;
std::set<vtkIdType>::iterator nIt;
};
// Iterate through cell neighborhood iterator
class CellIterator : public NeighborhoodIterator
{
public:
CellIterator(vtkDataSet* data);
virtual ~CellIterator();
virtual void initialize(vtkIdType v);
virtual void operator++(int i)
{nIt++;}
virtual vtkIdType id()
{return *nIt;}
virtual bool end()
{return (nIt == Neighbors.end());}
private:
vtkDataSet* DataSet;
std::vector<vtkIdType> Neighbors;
std::vector<vtkIdType>::iterator nIt;
};
virtual int GetVariableDimension(void)
{ return 1; };
virtual vtkDataArray *DeriveVariable(vtkDataSet *,
int currentDomainsIndex);
// Flag to indicate whether we compute merge(true) or split(false) trees
bool computeMergeTree;
// The threshold applied before the computation
double threshold;
private:
NeighborhoodIterator* neighborhood(vtkDataSet* data,
vtkIdType v);
};
#endif /* AVT_MERGETREE_EXPRESSION_H */
......@@ -100,6 +100,8 @@
#include <avtVariableSkewExpression.h>
#include <avtVectorComposeExpression.h>
#include <avtVectorDecomposeExpression.h>
#include <avtMergeTreeExpression.h>
#include <avtLocalThresholdExpression.h>
#include <visit-python-config.h>
#ifdef VISIT_PYTHON_FILTERS
......@@ -506,6 +508,9 @@ avtVectorExpr::CreateFilters(ExprPipelineState *state)
// Kevin Griffin, Tue Aug 5 15:01:27 PDT 2014
// Added lambda2 expression.
//
// Timo Bremer, Fri Oct 28 09:09:27 PDT 2016
// Added merge_tree, split_tree and local_threshold.
//
// ****************************************************************************
avtExpressionFilter *
......@@ -565,6 +570,12 @@ avtFunctionExpr::CreateFilters(string functionName)
return new avtProcessorIdExpression();
if (functionName == "threadid")
return new avtThreadIdExpression();
if (functionName == "merge_tree")
return new avtMergeTreeExpression(true);
if (functionName == "split_tree")
return new avtMergeTreeExpression(false);
if (functionName == "local_threshold")
return new avtLocalThresholdExpression();
if (functionName == "python" || functionName == "py")
#ifdef VISIT_PYTHON_FILTERS
return new avtPythonExpression();
......
......@@ -37,7 +37,8 @@ enhancements and bug-fixes that were added to this release.</p>
<a name="Advanced_Features"></a>
<p><b><font size="4">Advanced features added in version 2.12</font></b></p>
<ul>
<li></li>
<li> Added experimental <i>merge_tree, split_tree, and local_threshold</i> serial-only expressions for segmentation using the topology of a scalar field. The <i>merge_tree and split_tree</i> expressions take an input scalar and create a new scalar field with segmentation labels. The <i>local_threshold</i> expression takes a scalar field and a segmentation label and applies a local threshold metric to create a new scalar field.
</li>
</ul>
<a name="GUI_Changes"></a>
......
......@@ -61,6 +61,7 @@ vtkDataSetRemoveGhostCells.C
vtkDepthSortPolyData2.C
vtkLineoutFilter.C
vtkLinesFromOriginalCells.C
vtkMergeTree.C
vtkMultiSplitter.C
vtkOBJWriter.C
vtkOnionPeelFilter.C
......
/*
* vtkMergeTree.cxx
*
* Created on: Jul 28, 2016
* Author: bremer5
*/
#include "vtkMergeTree.h"
#include <vtkObject.h>
#include <vtkObjectFactory.h>
#include <vtkDataObject.h>
#include <vtkIdTypeArray.h>
#include <vtkTypeUInt32Array.h>
// ****************************************************************************
// ****************************************************************************
//
// vtkMergeTree Class
//
// ****************************************************************************
// ****************************************************************************
vtkStandardNewMacro(vtkMergeTree);
// ****************************************************************************
// Method: vtkMergeTree constructor
//
// Programmer: Peer-Timo Bremer
// Creation: August 8, 2016
//
// ****************************************************************************
vtkMergeTree::vtkMergeTree() : vtkMutableDirectedGraph()
{
Threshold = 0;
// Create the id array as Ids
GetVertexData()->AddArray(vtkIdTypeArray::New());
// Create an array for representatives
GetVertexData()->AddArray(vtkTypeUInt32Array::New());
}
// ****************************************************************************
// Method: vtkMergeTree copy constructor
//
// Programmer: Peer-Timo Bremer
// Creation: August 8, 2016
//
// ****************************************************************************
vtkMergeTree::vtkMergeTree(const vtkMergeTree&)
{
// Not implemented.
}
// ****************************************************************************
// Method: vtkMergeTree assignment op
//
// Programmer: Peer-Timo Bremer
// Creation: August 8, 2016
//
// ****************************************************************************
void
vtkMergeTree::operator=(const vtkMergeTree&)
{
// Not implemented.
}
// ****************************************************************************
// Method: vtkMergeTree destructor
//
// Programmer: Peer-Timo Bremer
// Creation: August 8, 2016
//
// ****************************************************************************
vtkMergeTree::~vtkMergeTree()
{
// empty
}
// ****************************************************************************
// Method: vtkMergeTree::Initialize
//
// Programmer: Peer-Timo Bremer
// Creation: August 8, 2016
//
// ****************************************************************************
void
vtkMergeTree::Initialize()
{
// This clears all data
vtkGraph::Initialize();
//return;
// Create the id array as Ids
GetVertexData()->AddArray(vtkIdTypeArray::New());
// Create an array for representatives
GetVertexData()->AddArray(vtkTypeUInt32Array::New());
}
// ****************************************************************************
// Method: vtkMergeTree::AddNode
//
// Programmer: Peer-Timo Bremer
// Creation: August 8, 2016
//
// ****************************************************************************
vtkTypeUInt32
vtkMergeTree::AddNode(vtkIdType id)
{
vtkTypeUInt32 index = AddVertex();
GetVertexData()->GetArray(vtkMergeTree::MESH_ID)->InsertTuple1(index,id);
GetVertexData()->GetArray(vtkMergeTree::REP_ID)->InsertTuple1(index,index);
return index;
}
// ****************************************************************************
// ****************************************************************************
//
// vtkSegmentedMergeTree Class
//
// ****************************************************************************
// ****************************************************************************
vtkStandardNewMacro(vtkSegmentedMergeTree);
// ****************************************************************************
// Method: vtkMergeTree constructor
//
// Programmer: Peer-Timo Bremer
// Creation: August 8, 2016
//
// ****************************************************************************
vtkSegmentedMergeTree::vtkSegmentedMergeTree() : vtkMergeTree()
{
//empty
}
// ****************************************************************************
// Method: vtkSegmentedMergeTree copy constructor
//
// Programmer: Peer-Timo Bremer
// Creation: August 8, 2016
//
// ****************************************************************************
vtkSegmentedMergeTree::vtkSegmentedMergeTree(const vtkSegmentedMergeTree&)
{
// Not implemented.
}
// ****************************************************************************
// Method: vtkSegmentedMergeTree assignment op
//
// Programmer: Peer-Timo Bremer
// Creation: August 8, 2016
//
// ****************************************************************************
void
vtkSegmentedMergeTree::operator=(const vtkSegmentedMergeTree&)
{
// Not implemented.
}
// ****************************************************************************
// Method: vtkMergeTree destructor
//
// Programmer: Peer-Timo Bremer
// Creation: August 8, 2016
//
// ****************************************************************************
vtkSegmentedMergeTree::~vtkSegmentedMergeTree()
{
//empty
}
// ****************************************************************************
// Method: vtkSegmentedMergeTree::AddNode
//
// Programmer: Peer-Timo Bremer
// Creation: August 8, 2016
//
// ****************************************************************************
vtkTypeUInt32
vtkSegmentedMergeTree::AddNode(vtkIdType id)
{
vtkTypeUInt32 index = vtkMergeTree::AddNode(id);
Branches.push_back(std::vector<vtkTypeInt64>());
assert (Branches.size() == index+1);
return index;
}
// ****************************************************************************
// Method: vtkSegmentedMergeTree::AddVertexToBranch
//
// Programmer: Peer-Timo Bremer
// Creation: August 8, 2016
//
// ****************************************************************************
void
vtkSegmentedMergeTree::AddVertexToBranch(vtkTypeUInt32 branch, vtkIdType id)
{
Branches[branch].push_back(id);
}
/*****************************************************************************
*
* Copyright (c) 2000 - 2016, Lawrence Livermore National Security, LLC
* Produced at the Lawrence Livermore National Laboratory
* LLNL-CODE-442911
* All rights reserved.
*
* This file is part of VisIt. For details, see https://visit.llnl.gov/. The
* full copyright notice is contained in the file COPYRIGHT located at the root
* of the VisIt distribution or at http://www.llnl.gov/visit/copyright.html.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the disclaimer below.
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the disclaimer (as noted below) in the
* documentation and/or other materials provided with the distribution.
* - Neither the name of the LLNS/LLNL nor the names of its contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL LAWRENCE LIVERMORE NATIONAL SECURITY,
* LLC, THE U.S. DEPARTMENT OF ENERGY OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
*****************************************************************************/
/*
* vtkMergeTree.h
*
* Created on: Jul 28, 2016
* Author: bremer5
*/
#ifndef VTK_VTKMERGETREE_H_
#define VTK_VTKMERGETREE_H_
#include <visit_vtk_exports.h>
#include <stdint.h>
#include <vector>
#include "vtkCommonDataModelModule.h"
#include "vtkMutableDirectedGraph.h"
#include "vtkTypeInt64Array.h"
#include "vtkSmartPointer.h"
#include "vtkDataSetAttributes.h"
// ****************************************************************************
// Class: vtkMergeTree
//
// Programmer: Peer-Timo Bremer
// Creation: August 8, 2016
//
// ****************************************************************************
class VISIT_VTK_API vtkMergeTree : public vtkMutableDirectedGraph
{
public:
enum MergeTreeAttributes
{
MESH_ID = 0,
REP_ID = 1,
};
vtkTypeMacro(vtkMergeTree,vtkMutableDirectedGraph);
static vtkMergeTree *New();
vtkGetMacro(Threshold,double);
vtkSetMacro(Threshold,double);
vtkGetMacro(Maximum,double);
vtkSetMacro(Maximum,double);
vtkGetMacro(Minimum,double);
vtkSetMacro(Minimum,double);
// Create the right vertex data
virtual void Initialize();
// Construct a new node
virtual vtkTypeUInt32 AddNode(vtkIdType id);
// Return the mesh id corresponding to the given node index
vtkIdType GetId(vtkTypeUInt32 index)
{return GetVertexData()->GetArray(vtkMergeTree::MESH_ID)->GetTuple1(index);}
// Return the node id of the representative for the given node index
vtkTypeUInt32 GetRep(vtkTypeUInt32 index)
{return GetVertexData()->GetArray(vtkMergeTree::REP_ID)->GetTuple1(index);}
// Set the representative for the given node
void SetRep(vtkTypeUInt32 index, vtkTypeUInt32 rep)
{return GetVertexData()->GetArray(vtkMergeTree::REP_ID)->SetTuple1(index,rep);}
protected:
// Default constructor
vtkMergeTree();
// Destructor
virtual ~vtkMergeTree();
// Current threshold
double Threshold;
// The global "maximum" function value
double Maximum;
// The global "minimum" function value
double Minimum;
private:
vtkMergeTree(const vtkMergeTree&); // private, not accessible
void operator=(const vtkMergeTree&); // private, not accessible
};
// ****************************************************************************
// Class: vtkSegmentedMergeTree
//