VTK----VTK数据结构详解3(代码篇)

news2024/12/30 4:04:37

上篇文章(VTK----VTK数据结构详解(计算机篇)-CSDN博客)从计算机数据结构(数组、链表等)的角度对数据数组数据对象数据属性的实现原理进行了说明,下面从代码的层面详细说明它们的使用及相关实现逻辑。

1 数据数组

vtkFloatArray为例,下面是它的使用及其VTK内部实现的代码:

vtkNew<vtkFloatArray> scalars;
scalars->InsertTuple1(0, 1);

void vtkDataArray::InsertTuple1(vtkIdType i, double value)
{
  int numComp = this->GetNumberOfComponents();
  if (numComp != 1)
  {
    vtkErrorMacro(
      "The number of components do not match the number requested: " << numComp << " != 1");
  }
  this->InsertTuple(i, &value);
}


template <class ValueTypeT>
void vtkAOSDataArrayTemplate<ValueTypeT>::InsertTuple(vtkIdType tupleIdx, const double* tuple)
{
  if (this->EnsureAccessToTuple(tupleIdx))
  {
    // See note in SetTuple about std::copy vs for loops on MSVC.
    const vtkIdType valueIdx = tupleIdx * this->NumberOfComponents;
    ValueTypeT* data = this->Buffer->GetBuffer() + valueIdx;
    for (int i = 0; i < this->NumberOfComponents; ++i)
    {
      data[i] = static_cast<ValueType>(tuple[i]);
    }
    this->MaxId = std::max(this->MaxId, valueIdx + this->NumberOfComponents - 1);
  }
}


template <class DerivedT, class ValueTypeT>
bool vtkGenericDataArray<DerivedT, ValueTypeT>::EnsureAccessToTuple(vtkIdType tupleIdx)
{
  if (tupleIdx < 0)
  {
    return false;
  }
  vtkIdType minSize = (1 + tupleIdx) * this->NumberOfComponents;
  vtkIdType expectedMaxId = minSize - 1;
  if (this->MaxId < expectedMaxId)
  {
    if (this->Size < minSize)
    {
      if (!this->Resize(tupleIdx + 1))
      {
        return false;
      }
    }
    this->MaxId = expectedMaxId;
  }
  return true;
}

从代码可以看出,插入值采用的是数组指针偏移的方式。插入前,通过EnsureAccessToTuple函数先检查是否需要Resize。插入时,指针偏移tupleIdx * NumberOfComponents,tupleIdx是当前准备在元组中插入的索引位置,NumberOfComponents是元组大小(可以理解为子一级的数组,子一级数组大小是固定值),上面的例子调用的是InsertTuple1,对应是一元组,所以NumberOfComponents等于1。在vtkDataArray.h中可以看到其提供了InsertTuple1、InsertTuple2、InsertTuple3、InsertTuple4、InsertTuple6、InsertTuple9这些接口分别用于插入对应大小的元组元素。

2 数据对象

vtkPolyData

上一篇文章提到vtkPolyData通过维护四个单独的列表(顶点(vertices)、线(lines)、多边形(polygons)和三角形带(triangle strips))来间接表示单元的类型,下面通过一个例子来看看它的使用。

#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL2);
VTK_MODULE_INIT(vtkInteractionStyle);
VTK_MODULE_INIT(vtkRenderingFreeType);
VTK_MODULE_INIT(vtkRenderingVolumeOpenGL2);
#include <vtkActor.h>
#include <vtkNamedColors.h>
#include <vtkPolyData.h>
#include <vtkPolyDataMapper.h>
#include <vtkProperty.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
#include <vtkSphereSource.h>
#include <vtkOpenGLRenderer.h>
#include <vtkOpenGLState.h>

int main(int, char*[])
{
  vtkNew<vtkNamedColors> colors;

  static double pts[25][3] = {
    {0.00, 1.00, 0.00   }, {0.00, 0.71, 0.71   }, {0.00, 0.00, 1.00   }, {0.00, -0.71, 0.71  }, {0.00, -1.00, 0.00  }, 
    {0.00, 1.00, 0.00   }, {0.71, 0.71, 0.00   }, {1.00, 0.00, 0.00   }, {0.71, -0.71, 0.00  }, {0.00, -1.00, 0.00  }, 
    {0.00, 1.00, 0.00   }, {0.00, 0.71, -0.71  }, {0.00, 0.00, -1.00  }, {0.00, -0.71, -0.71 }, {0.00, -1.00, 0.00  }, 
    {0.00, 1.00, 0.00   }, {-0.71, 0.71, 0.00  }, {-1.00, 0.00, 0.00  }, {-0.71, -0.71, 0.00 }, {0.00, -1.00, 0.00  }, 
    {0.00, 1.00, 0.00   }, {0.00, 0.71, 0.71   }, {0.00, 0.00, 1.00   }, {0.00, -0.71, 0.71  }, {0.00, -1.00, 0.00  }
  } ;
  
  static vtkIdType lines[80][2] = {
    {0, 5    }, {0, 1    }, {1, 6    }, {5, 6    }, {5, 1    }, {1, 6    }, {1, 2    }, {2, 7    }, 
    {6, 7    }, {6, 2    }, {2, 7    }, {2, 3    }, {3, 8    }, {7, 8    }, {7, 3    }, {3, 8    }, 
    {3, 4    }, {4, 9    }, {8, 9    }, {8, 4    }, {5, 10   }, {5, 6    }, {6, 11   }, {10, 11  }, 
    {10, 6   }, {6, 11   }, {6, 7    }, {7, 12   }, {11, 12  }, {11, 7   }, {7, 12   }, {7, 8    }, 
    {8, 13   }, {12, 13  }, {12, 8   }, {8, 13   }, {8, 9    }, {9, 14   }, {13, 14  }, {13, 9   }, 
    {10, 15  }, {10, 11  }, {11, 16  }, {15, 16  }, {15, 11  }, {11, 16  }, {11, 12  }, {12, 17  }, 
    {16, 17  }, {16, 12  }, {12, 17  }, {12, 13  }, {13, 18  }, {17, 18  }, {17, 13  }, {13, 18  }, 
    {13, 14  }, {14, 19  }, {18, 19  }, {18, 14  }, {15, 20  }, {15, 16  }, {16, 21  }, {20, 21  }, 
    {20, 16  }, {16, 21  }, {16, 17  }, {17, 22  }, {21, 22  }, {21, 17  }, {17, 22  }, {17, 18  }, 
    {18, 23  }, {22, 23  }, {22, 18  }, {18, 23  }, {18, 19  }, {19, 24  }, {23, 24  }, {23, 19  }
  };
  static vtkIdType strips[32][3] = {
    {0, 5, 1    }, {5, 1, 6    }, {1, 6, 2    }, {6, 2, 7    }, {2, 7, 3    }, {7, 3, 8    }, {3, 8, 4    }, {8, 4, 9    }, 
    {5, 10, 6   }, {10, 6, 11  }, {6, 11, 7   }, {11, 7, 12  }, {7, 12, 8   }, {12, 8, 13  }, {8, 13, 9   }, {13, 9, 14  }, 
    {10, 15, 11 }, {15, 11, 16 }, {11, 16, 12 }, {16, 12, 17 }, {12, 17, 13 }, {17, 13, 18 }, {13, 18, 14 }, {18, 14, 19 }, 
    {15, 20, 16 }, {20, 16, 21 }, {16, 21, 17 }, {21, 17, 22 }, {17, 22, 18 }, {22, 18, 23 }, {18, 23, 19 }, {23, 19, 24 }
  };
  vtkIdType numVerts = 25;
  vtkIdType numLines = 80;
  vtkIdType numStrips = 32;
  vtkIdType numCells = numVerts + numLines + numStrips;

  vtkIdType i;
  vtkPoints* points = vtkPoints::New();
  points->SetNumberOfPoints(25);
  for (i = 0; i < 25; i++)
  {
    points->InsertPoint(i, pts[i]);
  }
  vtkSmartPointer<vtkPolyData> poly = vtkSmartPointer<vtkPolyData>::New();
  poly->AllocateExact(numCells, numCells);
  poly->SetPoints(points);
  points->Delete();

  for (i = 0; i < numVerts; i++)
  {
    poly->InsertNextCell(VTK_VERTEX, 1, &i);
  }

  for (i = 0; i < numLines; i++)
  {
    poly->InsertNextCell(VTK_LINE, 2, lines[i]);
  }

  for (i = 0; i < numStrips; i++)
  {
    poly->InsertNextCell(VTK_TRIANGLE_STRIP, 3, strips[i]);
  }

  poly->BuildCells();

  vtkNew<vtkPolyDataMapper> mapper;
  mapper->SetInputData(poly);

  vtkNew<vtkActor> actor;
  actor->SetMapper(mapper);
  actor->GetProperty()->SetLineWidth(6);
  actor->GetProperty()->SetPointSize(25);
  actor->GetProperty()->SetRenderLinesAsTubes(1);
  actor->GetProperty()->SetRenderPointsAsSpheres(1);
  actor->GetProperty()->SetColor(colors->GetColor3d("Cornsilk").GetData());

  vtkNew<vtkRenderer> renderer;
  vtkNew<vtkRenderWindow> renderWindow;
  renderWindow->SetSize(500, 500);
  renderWindow->AddRenderer(renderer);
  vtkNew<vtkRenderWindowInteractor> renderWindowInteractor;
  renderWindowInteractor->SetRenderWindow(renderWindow);

  renderer->AddActor(actor);
  renderer->SetBackground(colors->GetColor3d("DarkGreen").GetData());
  renderWindow->Render();
  renderWindowInteractor->Start();
  getchar();
  return EXIT_SUCCESS;
}

运行效果图如下:

从图中可以看到绘制了点、线、由三角网渲染出来的面。

vtkUnstructuredGrid

vtkUnstructuredGrid可以表示所有单元类型(规则和不规则的),下面通过一个例子来看看它的使用。

#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL2);
VTK_MODULE_INIT(vtkInteractionStyle);
VTK_MODULE_INIT(vtkRenderingFreeType);
VTK_MODULE_INIT(vtkRenderingVolumeOpenGL2);
#include <vtkActor.h>
#include <vtkCamera.h>
#include <vtkCellType.h>
#include <vtkDataSetMapper.h>
#include <vtkNamedColors.h>
#include <vtkNew.h>
#include <vtkPoints.h>
#include <vtkProperty.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
#include <vtkUnstructuredGrid.h>

int main(int, char*[])
{
  int i;
  static double x[27][3] = {
      {0, 0, 0}, {1, 0, 0}, {2, 0, 0}, {0, 1, 0}, {1, 1, 0}, {2, 1, 0},
      {0, 0, 1}, {1, 0, 1}, {2, 0, 1}, {0, 1, 1}, {1, 1, 1}, {2, 1, 1},
      {0, 1, 2}, {1, 1, 2}, {2, 1, 2}, {0, 1, 3}, {1, 1, 3}, {2, 1, 3},
      {0, 1, 4}, {1, 1, 4}, {2, 1, 4}, {0, 1, 5}, {1, 1, 5}, {2, 1, 5},
      {0, 1, 6}, {1, 1, 6}, {2, 1, 6}};
  static vtkIdType pts[12][8] = {
      {0, 1, 4, 3, 6, 7, 10, 9},      {1, 2, 5, 4, 7, 8, 11, 10},
      {6, 10, 9, 12, 0, 0, 0, 0},     {8, 11, 10, 14, 0, 0, 0, 0},
      {16, 17, 14, 13, 12, 15, 0, 0}, {18, 15, 19, 16, 20, 17, 0, 0},
      {22, 23, 20, 19, 0, 0, 0, 0},   {21, 22, 18, 0, 0, 0, 0, 0},
      {22, 19, 18, 0, 0, 0, 0, 0},    {23, 26, 0, 0, 0, 0, 0, 0},
      {21, 24, 0, 0, 0, 0, 0, 0},     {25, 0, 0, 0, 0, 0, 0, 0}};

  vtkNew<vtkNamedColors> colors;

  vtkNew<vtkRenderer> renderer;

  vtkNew<vtkRenderWindow> renWin;
  renWin->AddRenderer(renderer);
  vtkNew<vtkRenderWindowInteractor> iren;
  iren->SetRenderWindow(renWin);

  vtkNew<vtkPoints> points;
  for (i = 0; i < 27; i++) points->InsertPoint(i, x[i]);

  vtkNew<vtkUnstructuredGrid> ugrid;
  ugrid->Allocate(100);
  ugrid->InsertNextCell(VTK_HEXAHEDRON, 8, pts[0]);
  ugrid->InsertNextCell(VTK_HEXAHEDRON, 8, pts[1]);
  ugrid->InsertNextCell(VTK_TETRA, 4, pts[2]);
  ugrid->InsertNextCell(VTK_TETRA, 4, pts[3]);
  ugrid->InsertNextCell(VTK_POLYGON, 6, pts[4]);
  ugrid->InsertNextCell(VTK_TRIANGLE_STRIP, 6, pts[5]);
  ugrid->InsertNextCell(VTK_QUAD, 4, pts[6]);
  ugrid->InsertNextCell(VTK_TRIANGLE, 3, pts[7]);
  ugrid->InsertNextCell(VTK_TRIANGLE, 3, pts[8]);
  ugrid->InsertNextCell(VTK_LINE, 2, pts[9]);
  ugrid->InsertNextCell(VTK_LINE, 2, pts[10]);
  ugrid->InsertNextCell(VTK_VERTEX, 1, pts[11]);

  ugrid->SetPoints(points);

  vtkNew<vtkDataSetMapper> ugridMapper;
  ugridMapper->SetInputData(ugrid);

  vtkNew<vtkActor> ugridActor;
  ugridActor->SetMapper(ugridMapper);
  ugridActor->GetProperty()->SetColor(colors->GetColor3d("Peacock").GetData());
  ugridActor->GetProperty()->EdgeVisibilityOn();

  renderer->AddActor(ugridActor);
  renderer->SetBackground(colors->GetColor3d("Beige").GetData());

  renderer->ResetCamera();
  renderer->GetActiveCamera()->Elevation(60.0);
  renderer->GetActiveCamera()->Azimuth(30.0);
  renderer->GetActiveCamera()->Dolly(1.2);

  renWin->SetSize(640, 480);
  renWin->SetWindowName("UGrid)");

  // interact with data
  renWin->Render();

  iren->Start();

  getchar();

  return EXIT_SUCCESS;
}

运行效果图如下:

3 数据模型

VTK中数据模型由单元(cell)点(point)组成,点对应vtkPoints类,单元对应vtkCellArray类。

vtkPoints

vtkPoints用来表示和操作3D点。vtkPoints的数据模型是可通过(点或单元)id访问的vx-vy-vz三元组数组。

vtkPoints::vtkPoints(int dataType)
{
  this->Data = vtkFloatArray::New();
  this->Data->Register(this);
  this->Data->Delete();
  this->SetDataType(dataType);

  this->Data->SetNumberOfComponents(3);
  this->Data->SetName("Points");

  this->Bounds[0] = this->Bounds[2] = this->Bounds[4] = VTK_DOUBLE_MAX;
  this->Bounds[1] = this->Bounds[3] = this->Bounds[5] = -VTK_DOUBLE_MAX;
}

从vtkPoints类构造函数中的代码可以看出,它创建了一个vtkFloatArray数据数组,NumberOfComponents为3表示其为一个三元组。

  void InsertPoint(vtkIdType id, const float x[3]) VTK_EXPECTS(0 <= id)
  {
    this->Data->InsertTuple(id, x);
  }
  void InsertPoint(vtkIdType id, const double x[3]) VTK_EXPECTS(0 <= id)
  {
    this->Data->InsertTuple(id, x);
  }

  vtkIdType InsertNextPoint(const float x[3]) { return this->Data->InsertNextTuple(x); }
  vtkIdType InsertNextPoint(const double x[3]) { return this->Data->InsertNextTuple(x); }
  vtkIdType InsertNextPoint(double x, double y, double z);

InsertPoint和InsertNextPoint内部调用的是数据数组的InsertTuple和InsertNextTuple函数。

vtkCellArray

vtkCellArray用来表示单元内部连接性的对象。其将数据集的拓扑结构存为显示连接性(connectivity)表,表中列出组成每个单元的点ID。

在vtkCellArray内部,连接性表表示为两个数组:Offsets(偏移)Connectivity(连接性)。Offsets是一个[numCells+1]值的数组,指示Connectivity数组中每个单元点开始的索引,最后一个值始终是Connectivity数组的长度。Connectivity数组存每个单元的点ID列表。因此,对于由两个三角形、一个四边形和一条线组成的数据集,内部数组将如下所示:

Topology:
---------
Cell 0: Triangle | point ids: {0, 1, 2}
Cell 1: Triangle | point ids: {5, 7, 2}
Cell 2: Quad     | point ids: {3, 4, 6, 7}
Cell 4: Line     | point ids: {5, 8}
 
vtkCellArray (current):
-----------------------
Offsets:      {0, 3, 6, 10, 12}
Connectivity: {0, 1, 2, 5, 7, 2, 3, 4, 6, 7, 5, 8}

虽然此类提供了遍历方法(旧的InitTraversal()、GetNextCell()方法和较新的方法GetCellAtId()),但这些方法通常不是线程安全的。最好使用本地线程安全的vtkCellArrayInterator对象,可以通过以下方式获取该对象:

auto iter = vtk::TakeSmartPointer(cellArray->NewIterator());
for (iter->GoToFirstCell(); !iter->IsDoneWithTraversal(); iter->GoToNextCell())
{
  // do work with iter
}

(但请注意,根据内部存的类型和结构,由于额外的数据复制,单元数组迭代器可能比直接遍历单元数组慢得多。另外,如果vtkCellArray内部存储被修改,迭代器可能变得无效。)

vtkCellArray内部的数组可以存32或64位的值,尽管大多数API更喜欢使用vtkIdType来对应数组中的元素。允许将64位存储于32位vtkIdType一起使用,但太大而无法容纳32位有符号整数的值在通过API访问时将被截断。(特定的内部存储类型对性能有影响,具体取决于vtkIdType。如果内部存储等效于vtkIdType,则返回指向点"id"数组的指针的方法可以共享内部存储,否则必须执行复制内存)。

/*--------------------------------------------------------------------------*/
/* Choose an implementation for vtkIdType.  */
#define VTK_HAS_ID_TYPE
#ifdef VTK_USE_64BIT_IDS
#if VTK_SIZEOF_LONG_LONG == 8
typedef long long vtkIdType;
#define VTK_ID_TYPE_IMPL VTK_LONG_LONG
#define VTK_SIZEOF_ID_TYPE VTK_SIZEOF_LONG_LONG
#define VTK_ID_MIN VTK_LONG_LONG_MIN
#define VTK_ID_MAX VTK_LONG_LONG_MAX
#define VTK_ID_TYPE_PRId "lld"
#elif VTK_SIZEOF_LONG == 8
typedef long vtkIdType;
#define VTK_ID_TYPE_IMPL VTK_LONG
#define VTK_SIZEOF_ID_TYPE VTK_SIZEOF_LONG
#define VTK_ID_MIN VTK_LONG_MIN
#define VTK_ID_MAX VTK_LONG_MAX
#define VTK_ID_TYPE_PRId "ld"
#else
#error "VTK_USE_64BIT_IDS is ON but no 64-bit integer type is available."
#endif
#else
typedef int vtkIdType;
#define VTK_ID_TYPE_IMPL VTK_INT
#define VTK_SIZEOF_ID_TYPE VTK_SIZEOF_INT
#define VTK_ID_MIN VTK_INT_MIN
#define VTK_ID_MAX VTK_INT_MAX
#define VTK_ID_TYPE_PRId "d"
#endif

InsertNextCell

InsertNextCell是用来插入单元的函数,各种数据对象中都有实现该接口,用以构造本对象中的各种类型的单元。下面我们通过vtkPolyData中InsertNextCell函数的内部实现代码看下它是如何构造单元的。

vtkIdType vtkPolyData::InsertNextCell(int type, vtkIdList* pts)
{
  return this->InsertNextCell(type, static_cast<int>(pts->GetNumberOfIds()), pts->GetPointer(0));
}

vtkIdType vtkPolyData::InsertNextCell(int type, int npts, const vtkIdType ptsIn[])
{
...
  // Insert next cell into the lookup map:
  TaggedCellId& tag = this->Cells->InsertNextCell(VTKCellType(type));
  vtkCellArray* cells = this->GetCellArrayInternal(tag);

  // Validate and update the internal cell id:
  const vtkIdType internalCellId = cells->InsertNextCell(npts, pts);
  if (internalCellId < 0)
  {
    vtkErrorMacro("Internal error: Invalid cell id (" << internalCellId << ").");
    return -1;
  }
...

  // Return the dataset cell id:
  return this->Cells->GetNumberOfCells() - 1;
}

inline vtkCellArray* vtkPolyData::GetCellArrayInternal(vtkPolyData::TaggedCellId tag)
{
  switch (tag.GetTarget())
  {
    case vtkPolyData_detail::Target::Verts:
      return this->Verts;
    case vtkPolyData_detail::Target::Lines:
      return this->Lines;
    case vtkPolyData_detail::Target::Polys:
      return this->Polys;
    case vtkPolyData_detail::Target::Strips:
      return this->Strips;
  }
  return nullptr; // unreachable
}

vtkPolyData::InsertNextCell函数中调用:

vtkCellArray* cells = this->GetCellArrayInternal(tag);

获取当前要插入单元的类型对应的vtkCellArray。然后调用:

const vtkIdType internalCellId = cells->InsertNextCell(npts, pts);

插入单元到vtkCellArray。

inline vtkIdType vtkCellArray::InsertNextCell(vtkIdType npts, const vtkIdType* pts)
  VTK_SIZEHINT(pts, npts)
{
  return this->Visit(vtkCellArray_detail::InsertNextCellImpl{}, npts, pts);
}

template <typename Functor, typename... Args,
	typename = typename std::enable_if<!ReturnsVoid<Functor, Args...>::value>::type>
GetReturnType<Functor, Args...> Visit(Functor&& functor, Args&&... args)
{
	if (this->Storage.Is64Bit())
	{
	  // If you get an error on the next line, a call to Visit(functor, Args...)
	  // is being called with arguments that do not match the functor's call
	  // signature. See the Visit documentation for details.
	  return functor(this->Storage.GetArrays64(), std::forward<Args>(args)...);
	}
	else
	{
	  // If you get an error on the next line, a call to Visit(functor, Args...)
	  // is being called with arguments that do not match the functor's call
	  // signature. See the Visit documentation for details.
	  return functor(this->Storage.GetArrays32(), std::forward<Args>(args)...);
	}
}

Visit(Functor&& functor, Args&&... args)函数的第一个参数是一个InsertNextCellImpl对象(&&可以理解为std::move操作),第二个参数是一个可变参数列表。

functor(this->Storage.GetArrays64(), std::forward<Args>(args)...);调用的是InsertNextCellImpl中()操作符函数:

struct InsertNextCellImpl
{
  // Insert full cell
  template <typename CellStateT>
  vtkIdType operator()(CellStateT& state, const vtkIdType npts, const vtkIdType pts[])
  {
    using ValueType = typename CellStateT::ValueType;
    auto* conn = state.GetConnectivity();
    auto* offsets = state.GetOffsets();

    const vtkIdType cellId = offsets->GetNumberOfValues() - 1;

    offsets->InsertNextValue(static_cast<ValueType>(conn->GetNumberOfValues() + npts));

    for (vtkIdType i = 0; i < npts; ++i)
    {
      conn->InsertNextValue(static_cast<ValueType>(pts[i]));
    }

    return cellId;
  }
...
};

operator()函数的第一个参数通过this->Storage.GetArrays64()获得。

  struct Storage
  {
    // Union type that switches 32 and 64 bit array storage
    union ArraySwitch {
      ArraySwitch() = default;  // handled by Storage
      ~ArraySwitch() = default; // handle by Storage
      VisitState<ArrayType32>* Int32;
      VisitState<ArrayType64>* Int64;
    };

    Storage()
    {
#ifdef VTK_USE_MEMKIND
      this->Arrays =
        static_cast<ArraySwitch*>(vtkObjectBase::GetCurrentMallocFunction()(sizeof(ArraySwitch)));
#else
      this->Arrays = new ArraySwitch;
#endif

      // Default to the compile-time setting:
#ifdef VTK_USE_64BIT_IDS

      this->Arrays->Int64 = new VisitState<ArrayType64>;
      this->StorageIs64Bit = true;

#else // VTK_USE_64BIT_IDS

      this->Arrays->Int32 = new VisitState<ArrayType32>;
      this->StorageIs64Bit = false;

#endif // VTK_USE_64BIT_IDS
#ifdef VTK_USE_MEMKIND
      if (vtkObjectBase::GetUsingMemkind())
      {
        this->IsInMemkind = true;
      }
#else
      (void)this->IsInMemkind; // comp warning workaround
#endif
    }

...
    // Get the VisitState for 32-bit arrays
    VisitState<ArrayType32>& GetArrays32()
    {
      assert(!this->StorageIs64Bit);
      return *this->Arrays->Int32;
    }

    const VisitState<ArrayType32>& GetArrays32() const
    {
      assert(!this->StorageIs64Bit);
      return *this->Arrays->Int32;
    }

    // Get the VisitState for 64-bit arrays
    VisitState<ArrayType64>& GetArrays64()
    {
      assert(this->StorageIs64Bit);
      return *this->Arrays->Int64;
    }

    const VisitState<ArrayType64>& GetArrays64() const
    {
      assert(this->StorageIs64Bit);
      return *this->Arrays->Int64;
    }

  private:
    // Access restricted to ensure proper union construction/destruction thru
    // API.
    ArraySwitch* Arrays;
    bool StorageIs64Bit;
    bool IsInMemkind = false;
  };

Storage内通过联合体(union)管理一个32位或64位的VisitState。

  template <typename ArrayT>
  struct VisitState
  {
    using ArrayType = ArrayT;
    using ValueType = typename ArrayType::ValueType;
    using CellRangeType = decltype(vtk::DataArrayValueRange<1>(std::declval<ArrayType>()));

    // We can't just use is_same here, since binary compatible representations
    // (e.g. int and long) are distinct types. Instead, ensure that ValueType
    // is a signed integer the same size as vtkIdType.
    // If this value is true, ValueType pointers may be safely converted to
    // vtkIdType pointers via reinterpret cast.
    static constexpr bool ValueTypeIsSameAsIdType = std::is_integral<ValueType>::value &&
      std::is_signed<ValueType>::value && (sizeof(ValueType) == sizeof(vtkIdType));

    ArrayType* GetOffsets() { return this->Offsets; }
    const ArrayType* GetOffsets() const { return this->Offsets; }

    ArrayType* GetConnectivity() { return this->Connectivity; }
    const ArrayType* GetConnectivity() const { return this->Connectivity; }

...

    friend class vtkCellArray;

  protected:
    VisitState()
    {
      this->Connectivity = vtkSmartPointer<ArrayType>::New();
      this->Offsets = vtkSmartPointer<ArrayType>::New();
      this->Offsets->InsertNextValue(0);
      if (vtkObjectBase::GetUsingMemkind())
      {
        this->IsInMemkind = true;
      }
    }

    vtkSmartPointer<ArrayType> Connectivity;
    vtkSmartPointer<ArrayType> Offsets;

...
  };

回到InsertNextCellImpl的operator()函数。我们可以看到,函数中根据InsertNextCell传入的单元类型对应的点数(npts)在进行遍历,依次插入单元对应的点的索引集合;将conn->GetNumberOfValues() + npts(当前已经插入的索引值总数+要插入单元的元组大小)的值作为偏移值插入Offsets数组中。

4 数据属性

vtkPointData 和 vtkCellData

上一篇文章讲到数据属性通常与点和单元关联关联的(也可以通过GetFieldData()关联到整个数据模型),VTK中使用vtkPointData和vtkCellData分别表示数据点和单元的属性,它们都是vtkFieldData的子类。下面我们通过一个例子来看下它们的使用。

#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL2);
VTK_MODULE_INIT(vtkInteractionStyle);
VTK_MODULE_INIT(vtkRenderingFreeType);
VTK_MODULE_INIT(vtkRenderingVolumeOpenGL2);
#include <vtkActor.h>
#include <vtkArrowSource.h>
#include <vtkCamera.h>
#include <vtkGlyph3D.h>
#include <vtkNamedColors.h>
#include <vtkNew.h>
#include <vtkPolyData.h>
#include <vtkPolyDataMapper.h>
#include <vtkProperty.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
#include <vtkCubeSource.h>
#include <vtkCellArray.h>
#include <vtkFloatArray.h>
#include <vtkPointData.h>
#include <vtkCellData.h>
#include <vtkPoints.h>

int main(int, char*[])
{
  vtkNew<vtkNamedColors> colors;

  std::array<std::array<double, 3>, 8> pts = {{{{0, 0, 0}},
                                               {{1, 0, 0}},
                                               {{1, 1, 0}},
                                               {{0, 1, 0}},
                                               {{0, 0, 1}},
                                               {{1, 0, 1}},
                                               {{1, 1, 1}},
                                               {{0, 1, 1}}}};
  // The ordering of the corner points on each face.
  std::array<std::array<vtkIdType, 4>, 6> ordering = {{{{0, 3, 2, 1}},
                                                       {{4, 5, 6, 7}},
                                                       {{0, 1, 5, 4}},
                                                       {{1, 2, 6, 5}},
                                                       {{2, 3, 7, 6}},
                                                       {{3, 0, 4, 7}}}};

  std::array<std::array<double, 3>, 8> vertex_normals;     
  for(auto i = 0; i < 8; ++i)
  {
    for(auto j = 0; j < 3; ++j)
    {
      vertex_normals[i][j] = pts[i][j] - 0.5;
    }
  }       

  // We'll create the building blocks of polydata including data attributes.
  vtkNew<vtkPolyData> cube;
  vtkNew<vtkPoints> points;
  vtkNew<vtkCellArray> polys;
  vtkNew<vtkFloatArray> vertex_normals_array;
  vtkNew<vtkFloatArray> scalar_array;

  // Load the point, cell, and data attributes.
  for (auto i = 0ul; i < pts.size(); ++i)
  {
    points->InsertPoint(i, pts[i].data());
  }

  for (auto&& i : ordering)
  {
    polys->InsertNextCell(vtkIdType(i.size()), i.data());
  }

  vertex_normals_array->SetNumberOfComponents(3);
  for(auto i = 0; i < vertex_normals.size(); ++i)
  {
    vertex_normals_array->InsertNextTuple3(vertex_normals[i][0], 
                                           vertex_normals[i][1], 
                                           vertex_normals[i][2]);
  }

  scalar_array->SetNumberOfComponents(1);
  for(auto i = 0; i < ordering.size(); ++i)
  {
    scalar_array->InsertNextTuple1(i);
  }
  // We now assign the pieces to the vtkPolyData.
  cube->SetPoints(points);
  cube->SetPolys(polys);
  cube->GetPointData()->SetNormals(vertex_normals_array);
  cube->GetCellData()->SetScalars(scalar_array);

  vtkNew<vtkPolyData> input;
  input->ShallowCopy(cube);
  vtkNew<vtkArrowSource> arrowSource;
  vtkNew<vtkGlyph3D> glyph3D;
  glyph3D->SetSourceConnection(arrowSource->GetOutputPort());
  glyph3D->SetInputData(input);
  glyph3D->ScalingOn();
  glyph3D->SetVectorModeToUseNormal();
  glyph3D->SetScaleFactor(0.25);
  glyph3D->Update();

  // Visualize
  vtkNew<vtkPolyDataMapper> mapper;
  mapper->SetInputConnection(glyph3D->GetOutputPort());
  vtkNew<vtkPolyDataMapper> cube_mapper;
  cube_mapper->SetInputData(cube);
  cube_mapper->SetScalarRange(cube->GetScalarRange());

  vtkNew<vtkActor> actor;
  actor->SetMapper(mapper);
  actor->GetProperty()->SetColor(colors->GetColor3d("Gold").GetData());
  vtkNew<vtkActor> cube_actor;
  cube_actor->SetMapper(cube_mapper);

  vtkNew<vtkRenderer> renderer;
  vtkNew<vtkRenderWindow> renderWindow;
  renderWindow->AddRenderer(renderer);
  renderWindow->SetWindowName("OrientedGlyphs");

  vtkNew<vtkRenderWindowInteractor> renderWindowInteractor;
  renderWindowInteractor->SetRenderWindow(renderWindow);

  renderer->AddActor(actor);
  renderer->AddActor(cube_actor);
  renderer->SetBackground(colors->GetColor3d("DarkGreen").GetData());

  renderWindow->Render();
  renderWindowInteractor->Start();
  getchar();
  return EXIT_SUCCESS;
}

运行效果如下:

上面的代码中:

cube->GetPointData()->SetNormals(vertex_normals_array);将法向量数据数组设置给点,所以从图中可以看到箭头是在点的位置进行显示。

cube->GetCellData()->SetScalars(scalar_array);将标量数据数组设置给单元,可以看到每个单元(面)根据标量显示不同的颜色。

数据属性不仅仅只包含标量、向量,其所能支持的类型包括以下这些:

  // Always keep NUM_ATTRIBUTES as the last entry
  enum AttributeTypes
  {
    SCALARS = 0,
    VECTORS = 1,
    NORMALS = 2,
    TCOORDS = 3,
    TENSORS = 4,
    GLOBALIDS = 5,
    PEDIGREEIDS = 6,
    EDGEFLAG = 7,
    TANGENTS = 8,
    RATIONALWEIGHTS = 9,
    HIGHERORDERDEGREES = 10,
    NUM_ATTRIBUTES
  };

Ghost属性

考虑如下图所示的提取外表面(face)的操作。外表面操作用于识别没有本地邻居的所有面。当我们把这些面片放置一起时,我们发现一些面被错误地识别为外部面。当两个相邻的单元被放置在单独的处理中时,这些面的错误识别就会发生。

上图提取外部面结果错误是因为处理中丢失了一些重要的全局信息,这些单独的处理过程不需要所有的数据,但需要一些不属于它们自己数据,即它们需要知道相邻的其他分区中的单元。

这个问题可以通过引入Ghost单元来解决这个局部/全局问题。Ghost单元是属于数据的一个分区并重复在其他分区上的单元。Ghost单元的引入是通过领域信息进行的,并按层次进行组织。对于给定的分区,与分区中的单元相邻但不属于分区本身的任何单元都是Ghost单元1。与不属于层次1或原始分区层次1的Ghost单元相邻的任何单元都处于层次2。递归定义更深的层次。

将Ghost引用到提取外表面的示例中,效果如下图,图中某些面仍然被分类为外表面,但是,所有这些面都附着在Ghost单元上。这些Ghost面很容易被剔除,最终结果就是合适的外表面。

下面通过一个例子来看看VTK中Ghost单元的使用:

#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL2);
VTK_MODULE_INIT(vtkInteractionStyle);
VTK_MODULE_INIT(vtkRenderingFreeType);
VTK_MODULE_INIT(vtkRenderingVolumeOpenGL2);
#include "vtkActor.h"
#include "vtkCellData.h"
#include "vtkCellType.h"
#include "vtkDataSetSurfaceFilter.h"
#include "vtkGeometryFilter.h"
#include "vtkNew.h"
#include "vtkPoints.h"
#include "vtkPolyDataMapper.h"
#include "vtkRegressionTestImage.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkRenderer.h"
#include "vtkSmartPointer.h"
#include "vtkUnsignedCharArray.h"
#include "vtkUnstructuredGrid.h"
#include "vtkFloatArray.h"
#include "vtkColorTransferFunction.h"
#include "vtkTextActor.h"
#include "vtkTextProperty.h"
#include "vtkCamera.h"
#include "vtkCallbackCommand.h"
#include "vtkRendererCollection.h"
#include "vtkActor2DCollection.h"

void CallbackFunction(vtkObject* caller, long unsigned int eventId,
                      void* clientData, void* callData)
{
  vtkRenderWindowInteractor* iren = static_cast<vtkRenderWindowInteractor*>(caller);
  vtkRenderer* renderer = iren->GetRenderWindow()->GetRenderers()->GetFirstRenderer();
  if(clientData == nullptr)
    return;
  auto points = static_cast<vtkPoints*>(clientData);
  auto ac = renderer->GetActors2D();
  vtkActor2D* anActor;
  vtkCollectionSimpleIterator ait;
  for (ac->InitTraversal(ait); (anActor = ac->GetNextActor2D(ait));)
  {
    auto ta = vtkTextActor::SafeDownCast(anActor);
    if(ta == nullptr) continue;
    std::string text = ta->GetInput();
    int idx = std::stoi(text);
    auto pt = points->GetPoint(idx);
    renderer->WorldToDisplay(pt[0], pt[1], pt[2]);
    ta->SetDisplayPosition(pt[0], pt[1]);
  }
}

int main(int argc, char* argv[])
{
  vtkNew<vtkPoints> points;
  points->InsertPoint(0, 0, 0, 0);
  points->InsertPoint(1, 1, 0, 0);
  points->InsertPoint(2, 0.5, 1, 0);
  points->InsertPoint(3, 0.5, 0.5, 1);
  points->InsertPoint(4, 0.5, -1, 0);
  points->InsertPoint(5, 0.5, -0.5, 1);

  vtkIdType v[3][4] = { { 0, 1, 2, 3 }, { 0, 4, 1, 5 }, { 5, 3, 1, 0 } };
  //vtkIdType v[3][4] = { { 0, 1, 2, 3 }, { 5, 3, 1, 0 }, { 0, 4, 1, 5 } };

  vtkSmartPointer<vtkUnstructuredGrid> grid = vtkSmartPointer<vtkUnstructuredGrid>::New();
  grid->InsertNextCell(VTK_TETRA, 4, v[0]);
  grid->InsertNextCell(VTK_TETRA, 4, v[1]);
  grid->InsertNextCell(VTK_TETRA, 4, v[2]);
  grid->SetPoints(points);

  vtkNew<vtkFloatArray> cell_scalar_array;
  cell_scalar_array->SetNumberOfComponents(1);
  cell_scalar_array->InsertNextTuple1(0);
  cell_scalar_array->InsertNextTuple1(3);
  cell_scalar_array->InsertNextTuple1(7);

  grid->GetCellData()->SetScalars(cell_scalar_array);
  
  // vtkNew<vtkUnsignedCharArray> ghosts;
  // ghosts->InsertNextValue(0);
  // ghosts->InsertNextValue(1);
  // ghosts->InsertNextValue(2);
  // ghosts->SetName(vtkDataSetAttributes::GhostArrayName()); 
  // grid->GetCellData()->AddArray(ghosts);

  // this filter removes the ghost cells
  vtkNew<vtkGeometryFilter> surfaces;
  surfaces->SetInputData(grid);
  surfaces->Update(); 

	vtkNew<vtkColorTransferFunction> clrTransferFunc;
	clrTransferFunc->SetColorSpaceToRGB();
  clrTransferFunc->AddRGBPoint(0, 1, 0, 0);
  clrTransferFunc->AddRGBPoint(3, 0, 1, 0);
  clrTransferFunc->AddRGBPoint(7, 0, 1, 1);

  vtkNew<vtkPolyDataMapper> mapper;
  mapper->SetInputConnection(surfaces->GetOutputPort());
  mapper->SetScalarRange(grid->GetScalarRange());
  mapper->SetLookupTable(clrTransferFunc);

  vtkNew<vtkActor> actor;
  actor->SetMapper(mapper);

  vtkNew<vtkCamera> camera;
  camera->SetPosition(0, 0, 5);
  camera->SetFocalPoint(0, 0, 0);

  vtkNew<vtkRenderer> renderer;
  renderer->SetActiveCamera(camera);
  renderer->ResetCamera();
  renderer->AddActor(actor);

  vtkNew<vtkRenderWindow> renwin;
  renwin->AddRenderer(renderer);
  renwin->SetSize(500, 500);

  vtkNew<vtkRenderWindowInteractor> iren;
  iren->SetRenderWindow(renwin);
  iren->Initialize();

  vtkNew<vtkCallbackCommand> callback;
  callback->SetCallback(CallbackFunction);
  callback->SetClientData(points);
  iren->AddObserver(vtkCommand::LeftButtonPressEvent, callback);

  for(int i = 0; i < points->GetNumberOfPoints(); ++i)
  {
    auto pt = points->GetPoint(i);
    std::string text = std::to_string(i);
    vtkNew<vtkTextActor> ta;
    ta->SetInput(text.c_str());
    ta->GetTextProperty()->SetColor(0.5, 1.0, 0.0);
    renderer->WorldToDisplay(pt[0], pt[1], pt[2]);
    ta->SetDisplayPosition(pt[0], pt[1]);
    ta->GetTextProperty()->SetFontSize(32);
    renderer->AddActor(ta.Get());
  }

  renwin->Render();
  iren->Start();

  getchar();
  return EXIT_SUCCESS;
}

没应用ghost单元代码的情况下,效果如下图:

应用ghost单元代码的情况下,效果如下图:

可以看到vtkGeometryFilter移除了第二个Ghost单元。将第二个单元和第三个单元顺序换一下的效果图如下:

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1626874.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

【Leetcode笔记】501.二叉搜索树中的众数

文章目录 题目要求ACM 模式代码知识点 题目要求 给你一个含重复值的二叉搜索树&#xff08;BST&#xff09;的根节点 root &#xff0c;找出并返回 BST 中的所有 众数&#xff08;即&#xff0c;出现频率最高的元素&#xff09;。 如果树中有不止一个众数&#xff0c;可以按 …

智能合约——提案demo

目录 这是一个超超超级简单的智能合约提案项目&#xff0c;你确定不点进来看一下吗&#xff1f; 引言&#xff1a; 1、搭建开发环境&#xff1a; 2、编写智能合约&#xff1a; 3、部署智能合约&#xff1a; ​编辑​编辑4、编写前端交互代码&#xff08;使用web3.js&…

MySQL中的Performance Schema是什么?

MySQL中的Performance Schema是什么&#xff1f; Performance Schema 是 MySQL 的一个特性&#xff0c;主要用于监控 MySQL 服务器在运行时的性能和资源使用情况。它首次引入于 MySQL 5.5 版本&#xff0c;并在后续版本中得到增强。Performance Schema 提供了一种方式来收集数…

PID算法学习

PID算法介绍 在过程控制中&#xff0c;按偏差的比例&#xff08;P&#xff09;、积分&#xff08;I&#xff09;和微分&#xff08;D&#xff09;进行控制的PID控制器&#xff08;亦称PID调节器&#xff09;是应用最为广泛的一种自动控制器。它具有原理简单&#xff0c;易于实…

某会员商店App的api接口分析

1、目的 探索学习app接口的加解密机制&#xff0c;并通过api模拟调用的方式&#xff0c;发起业务请求。仅供学习。 2、工具准备 样本App版本&#xff1a;v5.0.80&#xff0c;v5.0.90 设备&#xff1a;Oppo R9s&#xff08;Android7.1.1&#xff09; MacOS Big Sur&#xff…

基于Spring Boot的口腔管理平台设计与实现

基于Spring Boot的口腔管理平台设计与实现 开发语言&#xff1a;Java框架&#xff1a;springbootJDK版本&#xff1a;JDK1.8数据库工具&#xff1a;Navicat11开发软件&#xff1a;eclipse/myeclipse/idea 系统部分展示 管理员登录界面图&#xff0c;管理员登录进入口腔管理平…

基于JAVA实现的推箱子小游戏

Java推箱子小游戏实现&#xff1a; 推箱子小游戏曾经在我们的童年给我们带来了很多乐趣。推箱子这款游戏现在基本上没人玩了&#xff0c;甚至在新一代人的印象中都已毫无记忆了。。。但是&#xff0c;这款游戏可以在一定程度上锻炼自己的编程能力。 窗口画面设计&#xff1a;i…

鸿蒙OpenHarmony【轻量系统 编译】 (基于Hi3861开发板)

编译 OpenHarmony支持hb和build.sh两种编译方式。此处介绍hb方式&#xff0c;build.sh脚本编译方式请参考[使用build.sh脚本编译源码]。 使用build.sh脚本编译源码 进入源码根目录&#xff0c;执行如下命令进行版本编译。 ./build.sh --product-name name --ccache 说明&…

今日arXiv最热大模型论文:大模型也来看球,还能判断是否犯规

在足球世界&#xff0c;裁判的哨声可谓“千金难买”&#xff0c;因为它能直接决定俱乐部的钱包是鼓是瘪。但球场变化莫测&#xff0c;非常考验裁判的水平。 2022年卡塔尔世界杯上&#xff0c;半自动越位识别技术&#xff08;SAOT&#xff09;闪亮登场&#xff0c;通过12台摄像…

Rabbitmq安装延迟插件rabbitmq_delayed_message_exchange失败

Docker里的Rabbitmq容器安装延迟插件rabbitmq_delayed_message_exchange失败 一启动插件Rabbitmq容器直接停止运行了 rabbitmq-plugins enable rabbitmq_delayed_message_exchange排除了版本问题和端口问题等&#xff0c;发现是虚拟机运行内存不够&#xff0c;增加虚拟机运行内…

游戏新手村18:游戏广告渠道与广告形式

上文我们说到&#xff0c;渠道为王&#xff0c;渠道可以为我们带来流量和用户&#xff0c;进而带来收入。我们可以通过哪些渠道导入用户呢&#xff1f;每个渠道有哪些优劣呢&#xff1f;在进行游戏营销推广的时候我们该如何选择呢&#xff1f; 根据付费性质&#xff0c;我们可…

Dbeaver客户端安装和使用

数据库管理软件&#xff08;DBMS&#xff09;&#xff1a; • 数据是数据库中存储的基本对象&#xff0c;种类包括文字、图形、图像、声音等等 • 数据库&#xff08;database&#xff09;是以某种有组织的方式存储的数据集合&#xff0c;保存有组织的数据的容器&#xff0c;通…

【C语言必刷题】7. 百钱百鸡

&#x1f4da;博客主页&#xff1a;爱敲代码的小杨. ✨专栏&#xff1a;《Java SE语法》 | 《数据结构与算法》 | 《C生万物》 |《MySQL探索之旅》 |《Web世界探险家》 ❤️感谢大家点赞&#x1f44d;&#x1f3fb;收藏⭐评论✍&#x1f3fb;&#xff0c;您的三连就是我持续更…

大模型_ ChatGLM-Med推理及微调部署

文章目录 ChatGLM-Med是什么数据集构建推理部署python环境切换到安装好的conda环境下载github数据切换目录在infer.py修改模型路径启动推理解决infer.py报错修改后再次启动推理完成 微调部署安装evaluate包修改模型路径启动微调 ChatGLM-Med是什么 经过中文医学指令精调/指令微…

echarts地图叠加百度地图底板实现数据可视化

这里写自定义目录标题 echarts地图叠加百度地图实现数据可视化echarts地图叠加百度地图实现数据可视化 实现数据可视化时,个别情况下需要在地图上实现数据的可视化,echarts加载geojson数据可以实现以地图形式展示数据,例如分层设色或者鼠标hover展示指标值,但如果要将echa…

国产麒麟系统下打包electron+vue项目(AppImage、deb)

需要用到的一些依赖包、安装包以及更详细的打包方法word以及麒麟官网给出的文档都已放网盘&#xff0c;链接在文章最后&#xff01;&#xff01;&#xff01;&#xff01;&#xff01;&#xff01;&#xff01;&#xff01;&#xff01;&#xff01;&#xff01;&#xff01;&a…

【系统架构师】-选择题(四)

1、“41”视图 ①逻辑视图(Logical View)&#xff0c;设计的对象模型(使用面向对象的设计方法时)。 ②过程视图(Process View)&#xff0c;捕捉设计的并发和同步特征。系统集成师 ③物理视图(Physical View)&#xff0c;描述了软件到硬件的映射&#xff0c;反映了分布式特性。系…

SCI一区级 | Matlab实现BES-CNN-GRU-Mutilhead-Attention多变量时间序列预测

SCI一区级 | Matlab实现BES-CNN-GRU-Mutilhead-Attention秃鹰算法优化卷积门控循环单元融合多头注意力机制多变量时间序列预测 目录 SCI一区级 | Matlab实现BES-CNN-GRU-Mutilhead-Attention秃鹰算法优化卷积门控循环单元融合多头注意力机制多变量时间序列预测预测效果基本介绍…

命令行启动pytest自动化程序时,程序卡住不动了,不继续往下执行了

一、问题描述 在执行pytestallure自动化测试工具的时候&#xff0c;命令行启动程序时&#xff0c;程序卡住不继续往下执行&#xff0c;如下图所示。 代码主函数如下&#xff1a; 二、解决方法 测试客户项目时遇到2次此类问题&#xff0c;2次问题原因不一样。 原因一&#xf…

【JVM】从i++到JVM栈帧

【JVM】从i到JVM栈帧 本篇博客将用两个代码例子&#xff0c;简单认识一下JVM与栈帧结构以及其作用 从i与i说起 先不急着看i和i&#xff0c;我们来看看JVM虚拟机&#xff08;请看VCR.JPG&#xff09; 我们初学JAVA的时候一定都听到过JAVA“跨平台”的特性&#xff0c;也就是…