This file is indexed.

/usr/include/dune/grid-glue/extractors/vtksurfacewriter.hh is in libdune-grid-glue-dev 2.4.0-1build1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
/*
 *  Filename:    VtkSurfaceWriter.hh
 *  Version:     1.0
 *  Created on:  Jan 16, 2009
 *  Author:      Gerrit Buse
 *  ---------------------------------
 *  Project:     dune-grid-glue
 *  Description: helper class for graphical output of grids in generic representation
 *
 */
/**
 * @file
 * @brief helper class for graphical output of grids in generic representation
 */

#ifndef DUNE_GRIDGLUE_EXTRACTORS_VTKSURFACEWRITER_HH
#define DUNE_GRIDGLUE_EXTRACTORS_VTKSURFACEWRITER_HH

#include <fstream>
#include <iomanip>
#include <vector>
#include <cstring>

#include "../adapter/gridgluevtkwriter.hh"

namespace Dune {

  namespace GridGlue {

class VtkSurfaceWriter
{
public:


  VtkSurfaceWriter(const char* filename) : filename_(filename)
  {}

  ~VtkSurfaceWriter()
  {}

  void setFilename(const char* name)
  {
    if (std::strlen(name) > 0)
      this->filename_ = name;
  }


  template<typename K>
  void writeSurface(const std::vector<K>& coords, const std::vector<unsigned int>& indices, int corners, int dim)
  {
    std::ofstream fos;
    char buffer[64];
    sprintf(buffer, "%s.vtk", this->filename_);
    fos.open(buffer);
    fos << std::setprecision(8) << std::setw(1);
    // write preamble
    fos << "# vtk DataFile Version 2.0\nFilename: " << buffer << "\nASCII" << std::endl;
    this->writePoints(coords, dim, fos);
    const int polycount = indices.size()/corners;
    int corner_count[polycount];
    for (int i = 0; i < polycount; ++i)
      corner_count[i] = corners;
    this->writePolygons(indices, corner_count, polycount, dim, fos);
    fos.close();
  }


  template<typename K, typename T>
  void writeSurfaceElementData(const std::vector<K>& coords, const std::vector<unsigned int>& indices, int corners, const std::vector<T>& data, const char* dataname, int dim)
  {
    std::ofstream fos;
    char buffer[64];
    sprintf(buffer, "%s.vtk", this->filename_);
    fos.open(buffer);
    fos << std::setprecision(8) << std::setw(1);
    // write preamble
    fos << "# vtk DataFile Version 2.0\nFilename: " << buffer << "\nASCII" << std::endl;
    this->writePoints(coords, dim, fos);
    const int polycount = indices.size()/corners;
    int corner_count[polycount];
    for (int i = 0; i < polycount; ++i)
      corner_count[i] = corners;
    this->writePolygons(indices, corner_count, polycount, dim, fos);
    this->writeCellData(data, dataname, dim, fos);
    fos.close();
  }


  template<typename K, typename T>
  void writeSurfaceVertexData(const std::vector<K>& coords, const std::vector<unsigned int>& indices, int corners, const std::vector<T>& data, const char* dataname, int dim)
  {
    std::ofstream fos;
    char buffer[64];
    sprintf(buffer, "%s.vtk", this->filename_);
    fos.open(buffer);
    fos << std::setprecision(8) << std::setw(1);
    // write preamble
    fos << "# vtk DataFile Version 2.0\nFilename: " << buffer << "\nASCII" << std::endl;
    this->writePoints(coords, dim, fos);
    const int polycount = indices.size()/corners;
    int corner_count[polycount];
    for (int i = 0; i < polycount; ++i)
      corner_count[i] = corners;
    this->writePolygons(indices, corner_count, polycount, dim, fos);
    this->writePointData(data, dataname, dim, fos);
    fos.close();
  }

protected:

  template<typename K>
  void writePoints(const std::vector<K>& coords, int dim, std::ofstream& fos)
  {
    fos << "DATASET POLYDATA\nPOINTS " << coords.size() << " " << TypeNames[Nametraits<K>::nameidx] << std::endl;
    for (unsigned int i = 0; i < coords.size(); ++i)
    {
      fos << coords[i][0];
      if (dim == 2)
        fos << " " << coords[i][1] << " 0 \n" << coords[i][0] << " " << coords[i][1] << " 0.01" << std::endl;
      else       // dim == 3
        fos << " " << coords[i][1] << " "  << coords[i][2] << std::endl;
    }
  }

  void writePolygons(const std::vector<unsigned int>& indices, const int* corners, int ncorners, int dim, std::ofstream& fos)
  {
    if (dim == 2)
    {
      fos << "POLYGONS " << indices.size()/2 << " " << 5*(indices.size() / 2) << std::endl;
      for (unsigned int i = 0; i < indices.size(); i += 2)
        fos << "4 " << 2*indices[i] << " " << 2*indices[i+1] << " " << 2*indices[i+1]+1 << " "<< 2*indices[i]+1 << std::endl;

      // arbitrary shapes - ignored here!
      //                      int sum = ncorners;
      //                      for (int i = 0; i < ncorners; ++i)
      //                              sum += (corners[i] > 2 ? corners[i] : 3);
      //
      //                      fos << "POLYGONS " << ncorners << " " << sum << std::endl;
      //                      int index = 0;
      //                      for (int i = 0; i < ncorners; ++i)
      //                      {
      //                              // write the first index twice if it is an egde
      //                              // => triangle instead of edge - paraview can display it then
      //                              if (corners[i] > 2)
      //                                      fos << corners[i];
      //                              else
      //                                      fos << "3 " << indices[index];
      //
      //                              for (int j = 0; j < corners[i]; ++j)
      //                                      fos << " " << indices[index++];
      //                              fos << std::endl;
      //                       }
    }
    else
    {
      int sum = ncorners;
      for (int i = 0; i < ncorners; ++i)
        sum += corners[i];
      fos << "POLYGONS " << ncorners << " " << sum << std::endl;
      int index = 0;
      for (int i = 0; i < ncorners; ++i)
      {
        fos << corners[i];
        for (int j = 0; j < corners[i]; ++j)
          fos << " " << indices[index++];
        fos << std::endl;
      }
    }
  }

  template<typename T>
  void writeCellData(const std::vector<T>& data, const char* dataname, int dim, std::ofstream& fos)
  {
    fos << "CELL_DATA " << data.size()*(dim == 2 ? 2 : 1) << std::endl;
    fos << "SCALARS " << dataname << " " << TypeNames[Nametraits<T>::nameidx] << " 1" << std::endl;
    fos << "LOOKUP_TABLE default" << std::endl;
    for (unsigned int i = 0; i < data.size(); ++i)
    {
      fos << data[i] << std::endl;
      if (dim == 2)
        fos << data[i] << std::endl;
    }
  }

  template<typename T>
  void writePointData(const std::vector<T>& data, const char* dataname, int dim, std::ofstream& fos)
  {
    fos << "POINT_DATA " << data.size()*(dim == 2 ? 2 : 1) << std::endl;
    fos << "SCALARS " << dataname << " " << TypeNames[Nametraits<T>::nameidx] << " 1" << std::endl;
    fos << "LOOKUP_TABLE default" << std::endl;
    for (unsigned int i = 0; i < data.size(); ++i)
    {
      fos << data[i] << std::endl;
      if (dim == 2)
        fos << data[i] << std::endl;
    }
  }


private:
  const char*  filename_;
};

}  // namespace GridGlue

}  // namespace Dune

#endif // DUNE_GRIDGLUE_EXTRACTORS_VTKSURFACEWRITER_HH