avtVertexNormalsFilter.C 9.65 KB
Newer Older
hrchilds's avatar
hrchilds committed
1 2
/*****************************************************************************
*
3
* Copyright (c) 2000 - 2013, Lawrence Livermore National Security, LLC
hrchilds's avatar
hrchilds committed
4
* Produced at the Lawrence Livermore National Laboratory
5
* LLNL-CODE-442911
hrchilds's avatar
hrchilds committed
6 7
* All rights reserved.
*
8
* This file is  part of VisIt. For  details, see https://visit.llnl.gov/.  The
hrchilds's avatar
hrchilds committed
9 10 11 12 13 14 15 16 17 18
* 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
19 20 21
*    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
hrchilds's avatar
hrchilds committed
22 23 24 25 26
*    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
27 28 29
* 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
hrchilds's avatar
hrchilds committed
30 31 32 33 34 35 36 37 38
* 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.
*
*****************************************************************************/

hrchilds's avatar
hrchilds committed
39 40 41 42 43 44 45
// ************************************************************************* //
//                          avtVertexNormalsFilter.C                         //
// ************************************************************************* //

#include <avtVertexNormalsFilter.h>

#include <vtkPolyData.h>
hrchilds's avatar
hrchilds committed
46
#include <vtkStructuredGrid.h>
hrchilds's avatar
hrchilds committed
47
#include <vtkVisItPolyDataNormals.h>
hrchilds's avatar
hrchilds committed
48
#include <vtkVisItStructuredGridNormals.h>
hrchilds's avatar
hrchilds committed
49 50 51

#include <avtDataset.h>

hrchilds's avatar
hrchilds committed
52 53
#include <DebugStream.h>

hrchilds's avatar
hrchilds committed
54

hrchilds's avatar
hrchilds committed
55 56 57 58 59 60 61 62 63 64
// ****************************************************************************
//  Method: avtVertexNormalsFilter constructor
//
//  Purpose:
//      Defines the constructor.  Note: this should not be inlined in the
//      header because it causes problems for certain compilers.
//
//  Programmer: Hank Childs
//  Creation:   February 5, 2004
//
hrchilds's avatar
hrchilds committed
65 66 67 68 69 70
//  Modifications:
//
//    Hank Childs, Thu Feb 26 09:55:59 PST 2004
//    Removed pointNormals variable.  Whether or not to do point normals is
//    now decided dynamically.
//
hrchilds's avatar
hrchilds committed
71 72 73 74
// ****************************************************************************

avtVertexNormalsFilter::avtVertexNormalsFilter()
{
hrchilds's avatar
hrchilds committed
75
    ;
hrchilds's avatar
hrchilds committed
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
}


// ****************************************************************************
//  Method: avtVertexNormalsFilter destructor
//
//  Purpose:
//      Defines the destructor.  Note: this should not be inlined in the header
//      because it causes problems for certain compilers.
//
//  Programmer: Hank Childs
//  Creation:   February 5, 2004
//
// ****************************************************************************

avtVertexNormalsFilter::~avtVertexNormalsFilter()
{
    ;
}


hrchilds's avatar
hrchilds committed
97 98 99 100 101 102 103
// ****************************************************************************
//  Method: avtVertexNormalsFilter::ExecuteData
//
//  Purpose:
//      Sends the specified input and output through the VertexNormals filter.
//
//  Arguments:
104
//      in_dr      The input data representation.
hrchilds's avatar
hrchilds committed
105
//
106
//  Returns:       The output data representation.
hrchilds's avatar
hrchilds committed
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
//
//  Programmer: Hank Childs 
//  Creation:   December 31, 2001
//
//  Modifications:
//
//    Hank Childs, Thu Jun 20 13:59:01 PDT 2002
//    Be more careful about what sort of poly data gets sent in (no lines).
//
//    Hank Childs, Tue Aug  6 11:11:50 PDT 2002
//    Do not execute if normals have been deemed inappropriate.
//
//    Hank Childs, Sun Aug 18 11:14:20 PDT 2002
//    Do not find normals for disjoint element meshes.
//
//    Hank Childs, Tue Sep 10 15:17:21 PDT 2002
//    Manage the output's memory without the use of data members.
//
//    Jeremy Meredith, Thu Oct 24 17:40:18 PDT 2002
//    Upped the feature angle to 45 degrees.
//
//    Jeremy Meredith, Mon Jan  6 10:44:59 PST 2003
//    Disabled consistency checking because (1) it has bugs, (2) it is slow,
//    and (3) we are careful enough about cell orderings that we don't need it.
//
hrchilds's avatar
hrchilds committed
132 133 134 135
//    Jeremy Meredith, Wed Aug 13 18:13:14 PDT 2003
//    Made it use the new VisIt poly data normals filter.  Allowed
//    cell normals as well as just point normals.
//
hrchilds's avatar
hrchilds committed
136 137 138
//    Hank Childs, Thu Feb 26 09:50:37 PST 2004
//    Decide what type of normals (point, cell) to do from inside this filter.
//
hrchilds's avatar
hrchilds committed
139 140 141 142 143 144 145 146 147
//    Jeremy Meredith, Wed Oct 27 15:22:32 PDT 2004
//    Removed check for ensuring that polgons actually existed before doing
//    the normals.  The vtkVisItPolyDataNormals filter accepts them just fine,
//    and we can count on the spatial/topological tests to rule out cases
//    where it will be inefficient to compute normals anyway.  There were
//    cases where some domains had polgons, and others only had lines, but
//    the final append filter removed *all* normals because some domains
//    did not have any.
//
hrchilds's avatar
hrchilds committed
148 149 150 151
//    Hank Childs, Sat Feb 19 14:58:42 PST 2005
//    Break all memory references.  I didn't think this was necessary, but
//    the data wouldn't delete until I did this.
//
hrchilds's avatar
hrchilds committed
152 153 154 155
//    Kathleen Bonnell, Tue May 16 09:41:46 PDT 2006 
//    Removed call to SetSource(NULL), with new vtk pipeline, it also removes
//    necessary information from the dataset. 
//
hrchilds's avatar
hrchilds committed
156 157 158
//    Hank Childs, Thu Dec 28 15:25:50 PST 2006
//    Add support for direct normals calculation of structured grids.
//
159 160 161
//    Eric Brugger, Tue Jul 22 12:19:31 PDT 2014
//    Modified the class to work with avtDataRepresentation.
//
hrchilds's avatar
hrchilds committed
162 163
// ****************************************************************************

164 165
avtDataRepresentation *
avtVertexNormalsFilter::ExecuteData(avtDataRepresentation *in_dr)
hrchilds's avatar
hrchilds committed
166
{
167 168 169 170 171
    //
    // Get the VTK data set.
    //
    vtkDataSet *in_ds = in_dr->GetDataVTK();

hrchilds's avatar
hrchilds committed
172 173 174
    avtDataAttributes &atts = GetInput()->GetInfo().GetAttributes();

    if (atts.GetSpatialDimension() != 3 || atts.GetTopologicalDimension() != 2)
hrchilds's avatar
hrchilds committed
175
    {
176
        return in_dr;
hrchilds's avatar
hrchilds committed
177 178 179 180
    }

    if (GetInput()->GetInfo().GetValidity().NormalsAreInappropriate())
    {
181
        return in_dr;
hrchilds's avatar
hrchilds committed
182 183 184 185
    }

    if (GetInput()->GetInfo().GetValidity().GetDisjointElements() == true)
    {
186
        return in_dr;
hrchilds's avatar
hrchilds committed
187 188
    }

hrchilds's avatar
hrchilds committed
189
    if (in_ds->GetDataObjectType() == VTK_POLY_DATA)
hrchilds's avatar
hrchilds committed
190
    {
hrchilds's avatar
hrchilds committed
191 192 193 194 195 196 197 198 199 200
        vtkPolyData *pd = (vtkPolyData *)in_ds;
    
        bool pointNormals = true;
        if (atts.ValidActiveVariable())
        {
            avtCentering cent = atts.GetCentering();
            if (cent == AVT_ZONECENT)
                pointNormals = false;
        }
        vtkVisItPolyDataNormals *normals = vtkVisItPolyDataNormals::New();
201
        normals->SetInputData(pd);
hrchilds's avatar
hrchilds committed
202 203 204 205 206 207 208 209 210
        normals->SetFeatureAngle(45.);
        if (pointNormals)
            normals->SetNormalTypeToPoint();
        else
            normals->SetNormalTypeToCell();
        normals->SetSplitting(true);
        normals->Update();
    
        vtkPolyData *out_ds = normals->GetOutput();
211 212 213 214

        avtDataRepresentation *out_dr = new avtDataRepresentation(out_ds,
            in_dr->GetDomain(), in_dr->GetLabel());

hrchilds's avatar
hrchilds committed
215 216
        normals->Delete();
    
217
        return out_dr;
hrchilds's avatar
hrchilds committed
218
    }
hrchilds's avatar
hrchilds committed
219
    else if (in_ds->GetDataObjectType() == VTK_STRUCTURED_GRID)
hrchilds's avatar
hrchilds committed
220
    {
hrchilds's avatar
hrchilds committed
221 222 223 224 225 226 227 228 229 230 231
        vtkStructuredGrid *sgrid = (vtkStructuredGrid *)in_ds;
    
        bool pointNormals = true;
        if (atts.ValidActiveVariable())
        {
            avtCentering cent = atts.GetCentering();
            if (cent == AVT_ZONECENT)
                pointNormals = false;
        }
        vtkVisItStructuredGridNormals *normals = 
                                            vtkVisItStructuredGridNormals::New();
232
        normals->SetInputData(sgrid);
hrchilds's avatar
hrchilds committed
233 234 235 236 237 238 239 240 241
        if (pointNormals)
            normals->SetNormalTypeToPoint();
        else
            normals->SetNormalTypeToCell();

        normals->Update();
    
        vtkStructuredGrid *out_ds = normals->GetOutput();
    
242 243 244 245 246 247
        avtDataRepresentation *out_dr = new avtDataRepresentation(out_ds,
            in_dr->GetDomain(), in_dr->GetLabel());

        normals->Delete();

        return out_dr;
hrchilds's avatar
hrchilds committed
248
    }
hrchilds's avatar
hrchilds committed
249 250 251

    // Don't know what to do with other grid types.
    debug1 << "Sent unsupported grid type into normals filter" << endl;
252
    return in_dr;
hrchilds's avatar
hrchilds committed
253 254 255
}


hrchilds's avatar
hrchilds committed
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278
// ****************************************************************************
//  Method:  avtVertexNormalsFilter::FilterUnderstandsTransformedRectMesh
//
//  Purpose:
//    If this filter returns true, this means that it correctly deals
//    with rectilinear grids having an implied transform set in the
//    data attributes.  It can do this conditionally if desired.
//
//  Arguments:
//    none
//
//  Programmer:  Jeremy Meredith
//  Creation:    February 15, 2007
//
// ****************************************************************************

bool
avtVertexNormalsFilter::FilterUnderstandsTransformedRectMesh()
{
    // Creating normals for a transformed rectilinar mesh is okay;
    // the normals will be transformed when the mesh is.
    return true;
}