Commit a4f8fcc6 authored by ghweber's avatar ghweber
Browse files

Added colorlookup expression to map a scalar value to a color vector using a specified LUT.

git-svn-id: http://visit.ilight.com/svn/visit/trunk/src@2940 18c085ea-50e0-402c-830e-de6fd14e8384
parent b772ce9f
/*****************************************************************************
*
* Copyright (c) 2000 - 2008, Lawrence Livermore National Security, LLC
* Produced at the Lawrence Livermore National Laboratory
* LLNL-CODE-400142
* 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.
*
*****************************************************************************/
// ************************************************************************* //
// avtPerformColorTableLookupFilter.C //
// ************************************************************************* //
#include <avtPerformColorTableLookupFilter.h>
#include <vtkDataArray.h>
#include <vtkDataSet.h>
#include <vtkSkewLookupTable.h>
#include <avtLookupTable.h>
#include <avtExprNode.h>
#include <ExpressionException.h>
// ****************************************************************************
// Method: avtPerformColorTableLookupFilter constructor
//
// Purpose:
// Defines the constructor. Note: this should not be inlined in the
// header because it causes problems for certain compilers.
//
// Programmer: Gunther H. Weber
// Creation: Tue Jan 8 17:02:56 PST 2008
//
// ****************************************************************************
avtPerformColorTableLookupFilter::avtPerformColorTableLookupFilter()
{
}
// ****************************************************************************
// Method: avtPerformColorTableLookupFilter destructor
//
// Purpose:
// Defines the destructor. Note: this should not be inlined in the header
// because it causes problems for certain compilers.
//
// Programmer: Gunther H. Weber
// Creation: Tue Jan 8 17:02:56 PST 2008
//
// ****************************************************************************
avtPerformColorTableLookupFilter::~avtPerformColorTableLookupFilter()
{
}
// ****************************************************************************
// Method: avtPerformColorTableLookupFilter::PreExecute
//
// Purpose:
// Initializes a flag saying whether or not we've issued a warning.
//
// Programmer: Hank Childs
// Creation: February 13, 2006
//
// ****************************************************************************
void
avtPerformColorTableLookupFilter::PreExecute(void)
{
avtUnaryMathFilter::PreExecute();
// Get value range of default variable
GetDataExtents(mExtents, 0);
}
// ****************************************************************************
// Method: avtPerformColorTableLookupFilter::ProcessArguments
//
// Purpose:
// Parses optional algorithm argument.
//
// Arguments:
// args Expression arguments
// state Expression pipeline state
//
// Programmer: Gunther H. Weber
// Creation: Tue Jan 8 17:06:16 PST 2008
//
// ****************************************************************************
void
avtPerformColorTableLookupFilter::ProcessArguments(ArgsExpr *args,
ExprPipelineState *state)
{
// Get the argument list and # of arguments
std::vector<ArgExpr*> *arguments = args->GetArgs();
int nargs = arguments->size();
// Check number of args
if (nargs < 2)
{
EXCEPTION2(ExpressionException, outputVariableName,
"PerformColorTableLookup() Incorrect syntax.\n"
"Usage: PerformColorTableLookup(varname,colortablename, "
"mapping,skewfactor);\n with mapping being \"id\"/0, "
"\"log\"/1 or \"skew\"/2. The argument \"skewfactor\" "
"is only required for the mapping \"skew\".");
}
// First argument is the var name, let it do its own magic
ArgExpr *first_arg = (*arguments)[0];
avtExprNode *first_tree = dynamic_cast<avtExprNode*>(first_arg->GetExpr());
first_tree->CreateFilters(state);
// Parse the color table argument
ArgExpr *second_arg= (*arguments)[1];
ExprParseTreeNode *second_tree= second_arg->GetExpr();
string second_type = second_tree->GetTypeName();
if ((second_type == "StringConst"))
mLUTName = dynamic_cast<StringConstExpr*>(second_tree)->GetValue();
else // invalid arg type
EXCEPTION2(ExpressionException, outputVariableName,
"avtPerformColorTableLookupFilter: Expected string (color"
"table name) as second argument.");
// Check for a mapping
if (nargs > 2)
{
// Parse the color table argument
ArgExpr *third_arg = (*arguments)[2];
ExprParseTreeNode *third_tree= third_arg->GetExpr();
string third_type = third_tree->GetTypeName();
if ((third_type == "StringConst"))
{
string mapping = dynamic_cast<StringConstExpr*>(third_tree)->GetValue();
if (mapping == "id")
mLUTMapping = Identity;
else if (mapping == "log")
mLUTMapping = Log;
else if (mapping == "skew")
mLUTMapping = Skew;
else
EXCEPTION2(ExpressionException, outputVariableName,
"avtPerformColorTableLookupFilter: Invalid third argument.\n"
"Valid options are: \"id\"/0, \"log\"/1 or \"skew\"/2.");
}
else if (third_type == "IntegerConst")
{
int mapping = dynamic_cast<IntegerConstExpr*>(third_tree)->GetValue();
if(mapping < 0 || mapping > 2)
{
EXCEPTION2(ExpressionException, outputVariableName,
"avtPerformColorTableLookupFilter: Invalid third argument.\n"
"Valid options are: \"id\"/0, \"log\"/1 or \"skew\"/2.");
}
else
{
mLUTMapping = LookupMapping(mapping);
}
}
if (mLUTMapping == Skew)
{
if (nargs < 4)
{
EXCEPTION2(ExpressionException, outputVariableName,
"avtPerformColorTableLookupFilter: Missing fourth argument.\n"
"Must specify skew factor for mapping \"skew\".");
}
else
{
ArgExpr *fourth_arg = (*arguments)[3];
ExprParseTreeNode *fourth_tree= fourth_arg->GetExpr();
string fourth_type = fourth_tree->GetTypeName();
if (fourth_type == "FloatConst")
{
mSkew = dynamic_cast<FloatConstExpr*>(fourth_tree)->GetValue();
}
else if (fourth_type == "IntegerConst")
{
mSkew = double(dynamic_cast<IntegerConstExpr*>(fourth_tree)->GetValue());
}
else
{
EXCEPTION2(ExpressionException, outputVariableName,
"avtPerformColorTableLookupFilter: Skew factor must "
"be a float constant.");
}
}
}
}
else
{
mLUTMapping = Identity;
mSkew = 1.0;
}
}
// ****************************************************************************
// Method: avtPerformColorTableLookupFilter::DoOperation
//
// Purpose:
// Performs the color table lookup for each tuple of a data array.
//
// Arguments:
// in The input data array.
// out The output data array.
// ncomponents The number of components ('1' for scalar, '2' or '3' for
// vectors, etc.)
// ntuples The number of tuples (ie 'npoints' or 'ncells')
//
// Programmer: Gunther H. Weber
// Creation: Tue Jan 8 17:04:08 PST 2008
//
// Modifications:
//
// ****************************************************************************
void
avtPerformColorTableLookupFilter::DoOperation(vtkDataArray *in, vtkDataArray *out,
int ncomponents, int ntuples)
{
// Ensure we are dealing with scalar data
if (ncomponents != 1)
EXCEPTION2(ExpressionException, outputVariableName,
"PerformColorTableLookup() Expected scalar mesh variable.\n");
// Get color table
avtLookupTable avtLUT;
avtLUT.SetColorTable(mLUTName.c_str(), true);
vtkLookupTable *vtkLUT;
switch (mLUTMapping)
{
case Identity:
vtkLUT = avtLUT.GetLookupTable();
break;
case Log:
vtkLUT = avtLUT.GetLogLookupTable();
break;
case Skew:
avtLUT.SetSkewFactor(mSkew);
std::cout << "avtLUT.SetSkewFactor("<<mSkew<<")"<<std::endl;
vtkLUT = avtLUT.GetSkewLookupTable();
std::cout << (dynamic_cast<vtkSkewLookupTable*>(vtkLUT)->GetSkewFactor()) << std::endl;
break;
}
// Set value range
vtkLUT->SetRange(mExtents[0], mExtents[1]);
if (mLUTMapping == Skew) std::cout << dynamic_cast<vtkSkewLookupTable*>(vtkLUT)->GetSkewFactor() << std::endl;
double col[3];
// Perform lookup for each scalar in the data set
for (int i = 0 ; i < ntuples ; i++)
{
unsigned char *col;
// FIXME: Hack. Something strange is happening here. MapValue is virtual and should automatically call
// the method of the correct subclass of vtkLookupTable. However, this does not seem to work for
// vtkSkewLookupTable. For vtkLogLookupTable it works fine, though. As a workaround, we manually check
// whether we are dealing with "Skew" lookup and cast vtkLookupTable manually to vtkSkewLookupTable if
// necessary.
if (mLUTMapping = Skew)
col = dynamic_cast<vtkSkewLookupTable*>(vtkLUT)->MapValue(in->GetTuple1(i));
else
col = vtkLUT->MapValue(in->GetTuple1(i));
out->SetTuple3(i, double(col[0]), double(col[1]), double(col[2]));
}
}
/*****************************************************************************
*
* Copyright (c) 2000 - 2008, Lawrence Livermore National Security, LLC
* Produced at the Lawrence Livermore National Laboratory
* LLNL-CODE-400142
* 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.
*
*****************************************************************************/
// ************************************************************************* //
// avtPerformColorTableLookupFilter.h //
// ************************************************************************* //
#ifndef AVT_PERFORMCOLORTABLELOOKUP_FILTER_H
#define AVT_PERFORMCOLORTABLELOOKUP_FILTER_H
#include <avtUnaryMathFilter.h>
#include <string>
class vtkDataArray;
// ****************************************************************************
// Class: avtPerformColorTableLookupFilter
//
// Purpose:
// A filter that converts a scalar variable to a color by performing a
// color table lookup.
//
// Programmer: Gunther H. Weber
// Creation: Tue Jan 8 16:27:49 PST 2008
//
// Modifications:
//
// ****************************************************************************
class EXPRESSION_API avtPerformColorTableLookupFilter : public avtUnaryMathFilter
{
public:
avtPerformColorTableLookupFilter();
virtual ~avtPerformColorTableLookupFilter();
virtual const char *GetType(void)
{ return "avtPerformColorTableLookupFilter"; };
virtual const char *GetDescription(void)
{ return "Perform color table lookup"; };
virtual void PreExecute(void);
virtual void ProcessArguments(ArgsExpr*, ExprPipelineState *);
protected:
virtual int GetVariableDimension()
{ return 3; }
virtual int GetNumberOfComponentsInOutput(int numInInput)
{ return 3; }
virtual void DoOperation(vtkDataArray *in, vtkDataArray *out,
int ncomponents, int ntuples);
private:
enum LookupMapping { Identity = 0, Log = 1, Skew = 2 } ;
std::string mLUTName;
double mExtents[2];
LookupMapping mLUTMapping;
double mSkew;
};
#endif
......@@ -184,6 +184,9 @@
# Jeremy Meredith, Thu Aug 30 16:04:41 EDT 2007
# Added avtHSVColorComposeFilter.C.
#
# Gunther H. Weber, Wed Jan 9 10:21:48 PST 2008
# Added avtPerformColorTableLookupFilter.C
#
##############################################################################
@SET_MAKE@
......@@ -271,6 +274,7 @@ General_src= \
General/avtNMatsFilter.C \
General/avtNeighborEvaluatorFilter.C \
General/avtNormalizeFilter.C \
General/avtPerformColorTableLookupFilter.C \
General/avtProcessorIdFilter.C \
General/avtRelativeDifferenceFilter.C \
General/avtResradFilter.C \
......@@ -282,7 +286,7 @@ General_src= \
General/avtVariableSkewFilter.C \
General/avtVectorComposeFilter.C \
General/avtVectorDecomposeFilter.C \
General/avtViscousStressFilter.C\
General/avtViscousStressFilter.C \
General/avtZoneTypeFilter.C
......
......@@ -153,6 +153,7 @@
#include <avtConnComponentsExpression.h>
#include <avtTensorContractionFilter.h>
#include <avtViscousStressFilter.h>
#include <avtPerformColorTableLookupFilter.h>
#include <stdio.h>
#include <ExpressionException.h>
......@@ -462,6 +463,9 @@ avtVectorExpr::CreateFilters(ExprPipelineState *state)
// Jeremy Meredith, Thu Aug 30 16:02:01 EDT 2007
// Added hsvcolor.
//
// Gunther H. Weber, Wed Jan 9 10:22:55 PST 2008
// Added colorlookup.
//
// ****************************************************************************
avtExpressionFilter *
......@@ -859,6 +863,8 @@ avtFunctionExpr::CreateFilters(string functionName)
return new avtColorComposeFilter(4);
if (functionName == "hsvcolor")
return new avtHSVColorComposeFilter;
if (functionName == "colorlookup")
return new avtPerformColorTableLookupFilter;
return NULL;
}
......
......@@ -127,6 +127,9 @@
// Jeremy Meredith, Thu Aug 30 16:02:58 EDT 2007
// Added hsvcolor.
//
// Gunther H. Weber, Thu Jan 10 12:00:23 PST 2008
// Added colorlookup.
//
// ****************************************************************************
struct ExprNameList
......@@ -221,6 +224,7 @@ const char *expr_trig[] = {
const char *expr_vector[] = {
"color",
"color4",
"colorlookup",
"cross",
"dot",
"hsvcolor",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment