Commit 886157db authored by js9's avatar js9

merge from 2.7RC: revert poly/edge normals, add new edge normal expr.


git-svn-id: http://visit.ilight.com/svn/visit/trunk/src@22962 18c085ea-50e0-402c-830e-de6fd14e8384
parent e4ebf7b0
......@@ -144,6 +144,7 @@ General/avtDegreeExpression.C
General/avtDistanceToBestFitLineExpression.C
General/avtDivergenceExpression.C
General/avtDominantMaterialExpression.C
General/avtEdgeNormalExpression.C
General/avtExpressionComponentMacro.C
General/avtFindExternalExpression.C
General/avtGeodesicVectorQuantizeExpression.C
......
/*****************************************************************************
*
* Copyright (c) 2000 - 2013, 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.
*
*****************************************************************************/
// ************************************************************************* //
// avtEdgeNormalExpression.C //
// ************************************************************************* //
#include <avtEdgeNormalExpression.h>
#include <vtkCellData.h>
#include <vtkDataSet.h>
#include <vtkPointData.h>
#include <vtkPolyData.h>
#include <vtkRectilinearGrid.h>
#include <vtkVisItPolyDataNormals2D.h>
#include <ExpressionException.h>
// ****************************************************************************
// Method: avtEdgeNormalExpression constructor
//
// Purpose:
// Defines the constructor. Note: this should not be inlined in the
// header because it causes problems for certain compilers.
//
// Note: Derived from avtSurfaceNormalExpression version of function
//
// Programmer: Jeremy Meredith
// Creation: March 10, 2014
//
// ****************************************************************************
avtEdgeNormalExpression::avtEdgeNormalExpression()
{
isPoint = true;
}
// ****************************************************************************
// Method: avtEdgeNormalExpression destructor
//
// Purpose:
// Defines the destructor. Note: this should not be inlined in the header
// because it causes problems for certain compilers.
//
// Note: Derived from avtSurfaceNormalExpression version of function
//
// Programmer: Jeremy Meredith
// Creation: March 10, 2014
//
// ****************************************************************************
avtEdgeNormalExpression::~avtEdgeNormalExpression()
{
;
}
// ****************************************************************************
// Method: avtEdgeNormalExpression::DeriveVariable
//
// Purpose:
// Assigns the zone ID to each variable.
//
// Arguments:
// inDS The input dataset.
//
// Returns: The derived variable. The calling class must free this
// memory.
//
// Note: Derived from avtSurfaceNormalExpression version of function
//
// Programmer: Jeremy Meredith
// Creation: March 10, 2014
//
// Modifications:
//
// ****************************************************************************
vtkDataArray *
avtEdgeNormalExpression::DeriveVariable(vtkDataSet *in_ds, int currentDomainsIndex)
{
if (in_ds->GetDataObjectType() == VTK_RECTILINEAR_GRID)
{
return RectilinearDeriveVariable((vtkRectilinearGrid *) in_ds);
}
if (in_ds->GetDataObjectType() != VTK_POLY_DATA)
{
EXCEPTION2(ExpressionException, outputVariableName,
"The Edge normal expression "
"can only be calculated on edges.");
}
vtkPolyData *pd = (vtkPolyData *) in_ds;
vtkVisItPolyDataNormals2D *n = vtkVisItPolyDataNormals2D::New();
if (isPoint)
n->SetNormalTypeToPoint();
else
n->SetNormalTypeToCell();
n->SetInputData(pd);
n->Update();
vtkPolyData *out = n->GetOutput();
vtkDataArray *arr = NULL;
if (isPoint)
arr = out->GetPointData()->GetNormals();
else
arr = out->GetCellData()->GetNormals();
if (arr == NULL)
{
n->Delete();
EXCEPTION2(ExpressionException, outputVariableName,
"An internal error occurred where "
"the edge normals could not be calculated. Please "
"contact a VisIt developer.");
}
arr->Register(NULL);
n->Delete();
return arr;
}
// ****************************************************************************
// Method: avtEdgeNormalExpression::RectilinearDeriveVariable
//
// Purpose:
// A method that does special handling for rectilinear generation.
//
// Note: Derived from avtSurfaceNormalExpression version of function
//
// Programmer: Jeremy Meredith
// Creation: March 10, 2014
//
// ****************************************************************************
vtkDataArray *
avtEdgeNormalExpression::RectilinearDeriveVariable(vtkRectilinearGrid *rgrid)
{
int dims[3];
rgrid->GetDimensions(dims);
int nMatch = 0;
bool doX = (dims[0] == 1);
if (doX)
nMatch++;
bool doY = (dims[1] == 1);
if (doY)
nMatch++;
bool doZ = (dims[2] == 1);
if (doZ)
nMatch++;
if (nMatch == 0)
{
EXCEPTION2(ExpressionException, outputVariableName, "Can not determine "
"edge normals for a 3D data set.");
}
if (nMatch == 1)
{
EXCEPTION2(ExpressionException, outputVariableName, "Can not determine "
"edge normals for polygons.");
}
if (nMatch == 3)
{
EXCEPTION2(ExpressionException, outputVariableName, "Can not determine "
"edge normals for vertices.");
}
vtkDataArray *n = CreateArrayFromMesh(rgrid);
n->SetNumberOfComponents(3);
vtkIdType ntuples = (isPoint ? rgrid->GetNumberOfPoints()
: rgrid->GetNumberOfCells());
n->SetNumberOfTuples(ntuples);
double norm[3] = { 0, 0, 0 };
if (doY)
norm[1] = 1.0;
else
norm[0] = 1.0;
for (vtkIdType i = 0 ; i < ntuples ; i++)
{
n->SetTuple(i, norm);
}
return n;
}
/*****************************************************************************
*
* Copyright (c) 2000 - 2013, 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.
*
*****************************************************************************/
// ************************************************************************* //
// avtEdgeNormalExpression.h //
// ************************************************************************* //
#ifndef AVT_EDGE_NORMAL_EXPRESSION_H
#define AVT_EDGE_NORMAL_EXPRESSION_H
#include <avtSingleInputExpressionFilter.h>
class vtkDataArray;
class vtkRectilinearGrid;
// ****************************************************************************
// Class: avtEdgeNormalExpression
//
// Purpose:
// Find normals for (assumed 2D) edges / line segments.
//
// Programmer: Jeremy Meredith
// Creation: March 10, 2014
//
// Modifications:
//
// ****************************************************************************
class EXPRESSION_API avtEdgeNormalExpression
: public avtSingleInputExpressionFilter
{
public:
avtEdgeNormalExpression();
virtual ~avtEdgeNormalExpression();
virtual const char *GetType(void)
{ return "avtEdgeNormalExpression"; };
virtual const char *GetDescription(void)
{return "Calculating edge normal"; };
void DoPointNormals(bool val) { isPoint = val; };
protected:
bool isPoint;
virtual vtkDataArray *DeriveVariable(vtkDataSet *, int currentDomainsIndex);
virtual bool IsPointVariable(void) { return isPoint; };
virtual int GetVariableDimension(void) { return 2; };
vtkDataArray *RectilinearDeriveVariable(vtkRectilinearGrid *);
};
#endif
......@@ -44,6 +44,7 @@
#include <avtFindExternalExpression.h>
#include <avtNeighborEvaluatorExpression.h>
#include <avtSurfaceNormalExpression.h>
#include <avtEdgeNormalExpression.h>
#include <avtZoneTypeExpression.h>
#include <string>
......@@ -75,6 +76,9 @@
// Hank Childs, Fri Feb 4 14:00:21 PST 2011
// Add external_node and external_cell.
//
// Jeremy Meredith, Mon Mar 10 14:35:18 EDT 2014
// Added edge normal expressions.
//
// ****************************************************************************
avtExpressionFilter *
......@@ -93,6 +97,19 @@ avtFunctionExpr::CreateMeshFilters(const std::string &functionName) const
ff->DoPointNormals(false);
return ff;
}
else if (functionName == "edge_normal" ||
functionName == "point_edge_normal")
{
avtEdgeNormalExpression *ff = new avtEdgeNormalExpression;
ff->DoPointNormals(true);
return ff;
}
else if (functionName == "cell_edge_normal")
{
avtEdgeNormalExpression *ff = new avtEdgeNormalExpression;
ff->DoPointNormals(false);
return ff;
}
else if (functionName == "zoneid")
{
avtDataIdExpression *ff = new avtDataIdExpression;
......
......@@ -386,6 +386,9 @@ const char *expr_misc[] = {
"surface_normal",
" point_surface_normal",
" cell_surface_normal",
"edge_normal",
" point_edge_normal",
" cell_edge_normal",
"time",
"timestep",
"zonal_constant",
......
......@@ -85,6 +85,7 @@ vtkVisItFeatureEdges.C
vtkVisItGlyph3D.C
vtkVisItInterpolatedVelocityField.C
vtkVisItPolyDataNormals.C
vtkVisItPolyDataNormals2D.C
vtkVisItProbeFilter.C
vtkVisItRectilinearGrid.C
vtkVisItSTLWriter.C
......
......@@ -91,12 +91,6 @@ vtkVisItPolyDataNormals::vtkVisItPolyDataNormals()
// Eric Brugger, Thu Oct 2 16:08:56 PDT 2008
// Added code to not calculate the normals if they were already present.
//
// Jeremy Meredith, Wed Mar 5 11:43:07 EST 2014
// I extended the non-splitting case (and the cell case) to support lines
// in 2D space, but not the splitting case. We don't use the splitting
// case much, and this whole thing never even worked for lines before.
// Therefore, I fall back to the non-splitting case if we don't have polys.
//
// ****************************************************************************
int
vtkVisItPolyDataNormals::RequestData(vtkInformation *vtkNotUsed(request),
......@@ -116,7 +110,7 @@ vtkVisItPolyDataNormals::RequestData(vtkInformation *vtkNotUsed(request),
}
// Point normals
if (Splitting && input->GetPolys()->GetNumberOfCells() > 0)
if (Splitting)
{
ExecutePointWithSplitting(input, output);
}
......@@ -178,27 +172,23 @@ vtkVisItPolyDataNormals::RequestData(vtkInformation *vtkNotUsed(request),
// Hank Childs, Thu Jun 5 15:00:05 PDT 2008
// Call ShallowCopy, not SetFieldData.
//
// Jeremy Meredith, Wed Mar 5 11:45:35 EST 2014
// Added support for lines in assumed 2D space.
//
// ****************************************************************************
void
vtkVisItPolyDataNormals::ExecutePointWithoutSplitting(
vtkPolyData *input, vtkPolyData *output)
{
{
int i;
// Get all the input and output objects we'll need to reference
vtkCellArray *inCA = input->GetPolys();
vtkCellArray *inCL = input->GetLines();
vtkPointData *inPD = input->GetPointData();
vtkCellData *inCD = input->GetCellData();
vtkPoints *inPts = input->GetPoints();
int nPolys = inCA->GetNumberOfCells();
int nLines = inCL->GetNumberOfCells();
int nVerts = input->GetVerts()->GetNumberOfCells();
int nTotalCells = nPolys + nLines + nVerts;
int nCells = inCA->GetNumberOfCells();
int nOtherCells = input->GetVerts()->GetNumberOfCells() +
input->GetLines()->GetNumberOfCells();
int nTotalCells = nCells + nOtherCells;
int nPoints = input->GetNumberOfPoints();
......@@ -242,49 +232,10 @@ vtkVisItPolyDataNormals::ExecutePointWithoutSplitting(
output->Allocate(inCA->GetNumberOfConnectivityEntries());
outCD->CopyAllocate(inCD, nTotalCells);
vtkIdType *connPtrL = inCL->GetPointer();
for (i = 0 ; i < nLines ; i++)
{
outCD->CopyData(inCD, nVerts+i, nVerts+i);
int nVerts = *connPtrL++;
if (nVerts == 2)
{
output->InsertNextCell(VTK_LINE, 2,
connPtrL);
}
else
{
output->InsertNextCell(VTK_POLY_LINE, nVerts,
connPtrL);
}
double pt0[3], pt1[3];
inPts->GetPoint(connPtrL[0], pt0);
inPts->GetPoint(connPtrL[1], pt1);
double dx = pt1[0] - pt0[0];
double dy = pt1[1] - pt0[1];
// this gets normalized later
double normal[3];
normal[0] = dy;
normal[1] = -dx;
normal[2] = 0;
for (int j = 0 ; j < nVerts ; j++)
{
int p = connPtrL[j];
dnormals[p*3+0] += normal[0];
dnormals[p*3+1] += normal[1];
dnormals[p*3+2] += normal[2];
}
// Increment our connectivity pointer
connPtrL += nVerts;
}
vtkIdType *connPtr = inCA->GetPointer();
for (i = 0 ; i < nPolys ; i++)
for (i = 0 ; i < nCells ; i++)
{
outCD->CopyData(inCD, nVerts+nLines+i, nVerts+nLines+i);
outCD->CopyData(inCD, nOtherCells+i, nOtherCells+i);
int nVerts = *connPtr++;
if (nVerts == 3)
{
......@@ -351,11 +302,12 @@ vtkVisItPolyDataNormals::ExecutePointWithoutSplitting(
newNormals->Delete();
delete [] dnormals;
// copy the original vertices to the output
// copy the original vertices and lines to the output
output->SetVerts(input->GetVerts());
output->SetLines(input->GetLines());
// copy the data from the vertices now.
for (i = 0 ; i < nVerts ; i++)
// copy the data from the lines and vertices now.
for (i = 0 ; i < nOtherCells ; i++)
outCD->CopyData(inCD, i, i);
}
......@@ -819,9 +771,6 @@ vtkVisItPolyDataNormals::ExecutePointWithSplitting(vtkPolyData *input,
// Make sure there is one normal for every primitive, not just one normal
// for every polygon.
//
// Jeremy Meredith, Wed Mar 5 11:45:35 EST 2014
// Added support for lines in assumed 2D space.
//
// ****************************************************************************
void
vtkVisItPolyDataNormals::ExecuteCell(vtkPolyData *input, vtkPolyData *output)
......@@ -846,6 +795,7 @@ vtkVisItPolyDataNormals::ExecuteCell(vtkPolyData *input, vtkPolyData *output)
// The verts and lines come before the polys. So add normals for them.
int numPrimitivesWithoutNormals = 0;
numPrimitivesWithoutNormals += input->GetVerts()->GetNumberOfCells();
numPrimitivesWithoutNormals += input->GetLines()->GetNumberOfCells();
for (i = 0 ; i < numPrimitivesWithoutNormals ; i++)
{
newNormalPtr[0] = 0.;
......@@ -854,41 +804,6 @@ vtkVisItPolyDataNormals::ExecuteCell(vtkPolyData *input, vtkPolyData *output)
newNormalPtr += 3;
}
vtkCellArray *inCL = input->GetLines();
vtkIdType *connPtrL = inCL->GetPointer();
int nLines = inCL->GetNumberOfCells();
for (i = 0 ; i < nLines ; i++)
{
int nVerts = *connPtrL++;
vtkIdType *cell = connPtrL;
double v0[3], v1[3], v2[3];
double normal[3] = {0, 0, 1};
if (nVerts == 2)
{
inPts->GetPoint(cell[0], v0);
inPts->GetPoint(cell[1], v1);
double dx = v1[0] - v0[0];
double dy = v1[1] - v0[1];
double len = sqrt(dx*dx + dy*dy);
if (len != 0)
{
normal[0] = dy / len;
normal[1] = -dx / len;
normal[2] = 0;
}
}
newNormalPtr[0] = (float)(normal[0]);
newNormalPtr[1] = (float)(normal[1]);
newNormalPtr[2] = (float)(normal[2]);
newNormalPtr += 3;
//
// Step through connectivity
//
connPtrL += nVerts;
}
vtkCellArray *inCA = input->GetPolys();
vtkIdType *connPtr = inCA->GetPointer();
int nPolys = inCA->GetNumberOfCells();
......
This diff is collapsed.
/*****************************************************************************
*
* Copyright (c) 2000 - 2013, 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.
*
*****************************************************************************/
#ifndef __vtkVisItPolyDataNormals2D_h
#define __vtkVisItPolyDataNormals2D_h
#include <visit_vtk_exports.h>
#include <vtkPolyDataAlgorithm.h>
class vtkPolyData;
class vtkInformation;
class vtkInformationVector;
// ****************************************************************************
// Class: vtkVisItPolyDataNormals2D
//
// Purpose:
// Calculate cell or point centered normals.
//
// Note: Derived from avtSurfaceNormalExpression version of function
//
// Programmer: Jeremy Meredith
// Creation: March 10, 2014
//
// ****************************************************************************
class VISIT_VTK_API vtkVisItPolyDataNormals2D : public vtkPolyDataAlgorithm
{
public:
vtkTypeMacro(vtkVisItPolyDataNormals2D,vtkPolyDataAlgorithm);
static vtkVisItPolyDataNormals2D *New();
void SetNormalTypeToCell() { ComputePointNormals = false; }
void SetNormalTypeToPoint() { ComputePointNormals = true; }
protected:
vtkVisItPolyDataNormals2D();
~vtkVisItPolyDataNormals2D() {};
// Usual data generation method
int RequestData(vtkInformation*, vtkInformationVector**,
vtkInformationVector*);
void ExecutePoint(vtkPolyData*, vtkPolyData*);
void ExecuteCell(vtkPolyData *, vtkPolyData*);
bool ComputePointNormals;
private:
vtkVisItPolyDataNormals2D(const vtkVisItPolyDataNormals2D&); // Not implemented.
void operator=(const vtkVisItPolyDataNormals2D&); // Not implemented.
};
#endif
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