551 this->cache =
new PolyDataCache();
562 this->Points = points;
563 this->Colors = colors;
564 this->CellColors->SetNumberOfComponents(colors->GetNumberOfComponents());
569 this->DrawLines(polyData, scalarMode, x, y, scale);
573 this->DrawPolygons(polyData, scalarMode, x, y, scale);
584 struct PolyDataCacheItem
588 std::vector<float> PolyTri;
592 std::vector<float> Lines;
601 std::map<vtkPolyData*, PolyDataCacheItem*>::iterator itPrev = this->PrevFrameCache.begin();
602 for (; itPrev != this->PrevFrameCache.end(); ++itPrev)
604 delete itPrev->second;
607 std::map<vtkPolyData*, PolyDataCacheItem*>::iterator it = this->CurrentFrameCache.begin();
608 for (; it != this->CurrentFrameCache.end(); ++it)
614 PolyDataCacheItem* GetCacheEntry(vtkPolyData* key)
616 PolyDataCacheItem* cacheItem = this->CurrentFrameCache[
key];
617 if (cacheItem ==
nullptr)
619 cacheItem = this->PrevFrameCache[
key];
620 if (cacheItem ==
nullptr)
622 cacheItem =
new PolyDataCacheItem();
629 this->PrevFrameCache.erase(key);
633 this->CurrentFrameCache[
key] = cacheItem;
644 std::map<vtkPolyData*, PolyDataCacheItem*>::iterator itPrev = this->PrevFrameCache.begin();
645 for (; itPrev != this->PrevFrameCache.end(); ++itPrev)
647 delete itPrev->second;
651 this->PrevFrameCache.clear();
654 std::swap(this->PrevFrameCache, this->CurrentFrameCache);
659 std::map<vtkPolyData*, PolyDataCacheItem*> PrevFrameCache;
660 std::map<vtkPolyData*, PolyDataCacheItem*> CurrentFrameCache;
667 float const posX,
float const posY,
float const scale,
vtkIdType cellId,
int scalarMode)
669 this->CellPoints.reserve(this->NumPointsCell * 2);
670 this->CellColors->SetNumberOfTuples(this->NumPointsCell);
671 for (
int i = 0; i < this->NumPointsCell; i++)
674 this->Points->GetPoint(this->PointIds[i], point);
677 float const x =
static_cast<float>(
point[0]) + posX;
678 float const y =
static_cast<float>(
point[1]) + posY;
679 this->CellPoints.push_back(x * scale);
680 this->CellPoints.push_back(y * scale);
687 mappedColorId = this->PointIds[i];
690 mappedColorId = cellId;
693 std::cerr <<
"Scalar mode not supported!" << std::endl;
697 this->CellColors->SetTuple(i, mappedColorId, this->Colors);
707 vtkPolyData* polyData,
int scalarMode,
float const x,
float const y,
float const scale)
709 PolyDataCacheItem* cacheItem = this->cache->GetCacheEntry(polyData);
711 if (polyData->
GetMTime() > cacheItem->LinesLoadingTime)
713 vtkNew<vtkGenericCell> genericCell;
714 cacheItem->Lines.clear();
715 cacheItem->LineColors->Reset();
719 cacheItem->Lines.reserve(numVertices * 2);
720 cacheItem->LineColors->SetNumberOfComponents(this->Colors->GetNumberOfComponents());
721 cacheItem->LineColors->SetNumberOfTuples(numVertices);
725 vtkCellIterator* cellIter =
nullptr;
733 vtkIdType actualNumPointsCell = genericCell->GetNumberOfPoints();
735 for (
int i = 0; i < actualNumPointsCell - 1; ++i)
737 this->NumPointsCell = 2;
738 this->PointIds = genericCell->GetPointIds()->
GetPointer(i);
740 this->MapCurrentCell(x, y, scale, cellId, scalarMode);
743 for (
int j = 0; j < this->NumPointsCell; j++)
745 cacheItem->Lines.push_back(this->CellPoints[2 * j]);
746 cacheItem->Lines.push_back(this->CellPoints[2 * j + 1]);
748 double* color4 = this->CellColors->GetTuple(j);
749 cacheItem->LineColors->InsertTuple4(
750 vertOffset + j, color4[0], color4[1], color4[2], color4[3]);
753 vertOffset += this->NumPointsCell;
754 this->CellColors->Reset();
755 this->CellPoints.clear();
760 cacheItem->LinesLoadingTime.Modified();
764 if (!cacheItem->Lines.empty())
766 this->Device->DrawLines(&cacheItem->Lines[0],
static_cast<int>(cacheItem->Lines.size() / 2),
767 static_cast<unsigned char*
>(cacheItem->LineColors->GetVoidPointer(0)),
768 cacheItem->LineColors->GetNumberOfComponents());
776 vtkIdType GetCountTriangleVertices(vtkPolyData* polyData)
780 vtkNew<vtkGenericCell> genericCell;
781 vtkCellIterator* cellIter =
nullptr;
787 this->NumPointsCell = genericCell->GetNumberOfPoints();
788 this->PointIds = genericCell->GetPointIds()->
GetPointer(0);
789 numTriVert += 3 * (this->NumPointsCell - 2);
802 vtkPolyData* polyData,
int scalarMode,
float const x,
float const y,
float const scale)
804 PolyDataCacheItem* cacheItem = this->cache->GetCacheEntry(polyData);
806 if (polyData->
GetMTime() > cacheItem->PolygonsLoadingTime)
808 cacheItem->PolyTri.clear();
809 cacheItem->PolyColors->Reset();
812 vtkIdType const totalTriVert = this->GetCountTriangleVertices(polyData);
813 cacheItem->PolyTri.reserve(totalTriVert * 2);
814 cacheItem->PolyColors->SetNumberOfComponents(this->Colors->GetNumberOfComponents());
815 cacheItem->PolyColors->SetNumberOfTuples(totalTriVert);
820 cacheItem->PolyColors->SetNumberOfComponents(this->Colors->GetNumberOfComponents());
822 vtkNew<vtkGenericCell> genericCell;
823 vtkCellIterator* cellIter =
nullptr;
832 this->NumPointsCell = genericCell->GetNumberOfPoints();
833 this->PointIds = genericCell->GetPointIds()->
GetPointer(0);
835 this->MapCurrentCell(x, y, scale, cellId, scalarMode);
838 for (
int i = 0; i < this->NumPointsCell - 2; i++)
840 cacheItem->PolyTri.push_back(this->CellPoints[0]);
841 cacheItem->PolyTri.push_back(this->CellPoints[1]);
842 cacheItem->PolyTri.push_back(this->CellPoints[i * 2 + 2]);
843 cacheItem->PolyTri.push_back(this->CellPoints[i * 2 + 3]);
844 cacheItem->PolyTri.push_back(this->CellPoints[i * 2 + 4]);
845 cacheItem->PolyTri.push_back(this->CellPoints[i * 2 + 5]);
848 vtkIdType const triangOffset = vertOffset + 3 * i;
849 double* color4 = this->CellColors->GetTuple(0);
850 cacheItem->PolyColors->InsertTuple4(
851 triangOffset, color4[0], color4[1], color4[2], color4[3]);
853 color4 = this->CellColors->GetTuple(i + 1);
854 cacheItem->PolyColors->InsertTuple4(
855 triangOffset + 1, color4[0], color4[1], color4[2], color4[3]);
857 color4 = this->CellColors->GetTuple(i + 2);
858 cacheItem->PolyColors->InsertTuple4(
859 triangOffset + 2, color4[0], color4[1], color4[2], color4[3]);
862 vertOffset += 3 * (this->NumPointsCell - 2);
863 this->CellColors->Reset();
864 this->CellPoints.clear();
868 cacheItem->PolygonsLoadingTime.Modified();
872 if (!cacheItem->PolyTri.empty())
874 this->Device->CoreDrawTriangles(cacheItem->PolyTri,
875 static_cast<unsigned char*
>(cacheItem->PolyColors->GetVoidPointer(0)), 4);
883 vtkUnsignedCharArray* Colors;
890 std::vector<float> CellPoints;
891 vtkNew<vtkUnsignedCharArray> CellColors;
894 PolyDataCache* cache;