2
0

fIntensityMeshC.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "fIntensityMeshC.h"
  5. //---------------------------------------------------------------------------
  6. #pragma package(smart_init)
  7. #pragma link "GLS.BitmapFont"
  8. #pragma link "GLS.Coordinates"
  9. #pragma link "GLS.HUDObjects"
  10. #pragma link "GLS.Material"
  11. #pragma link "GLS.Objects"
  12. #pragma link "GLS.Scene"
  13. #pragma link "GLS.VectorFileObjects"
  14. #pragma link "GLS.SceneViewer"
  15. #pragma link "GLS.WindowsFont"
  16. #pragma resource "*.dfm"
  17. TForm1 *Form1;
  18. //---------------------------------------------------------------------------
  19. __fastcall TForm1::TForm1(TComponent* Owner)
  20. : TForm(Owner)
  21. {
  22. }
  23. //---------------------------------------------------------------------------
  24. void __fastcall TForm1::FormCreate(TObject *Sender)
  25. {
  26. TMeshObject *mo;
  27. TFGVertexIndexList *fgQuads, *fgTris;
  28. int i;
  29. TFileStream *str;
  30. // load our raw data
  31. str = new TFileStream("IntensityMesh.data", fmOpenRead);
  32. str->Read(0, 4);
  33. //-System::AnsiString::SetLength(DataNodes, i);
  34. str->Read(0, 4);
  35. /*
  36. Ex:
  37. DynamicArray<int> arrayOfInt;
  38. arrayOfInt.Length = 10;
  39. cout << "ArrayLength: " << arrayOfInt.Length << endl;
  40. SetLength(arrayOfInt, 10);
  41. */
  42. //-SetLength(DataPrimitives, i);
  43. //-str->Read(DataNodes[0], Length(DataNodes)*SizeOf(TDataNode));
  44. //-str->Read(DataPrimitives[0], Length(DataPrimitives)*SizeOf(TDataPrimitive));
  45. str->Free();
  46. // fill the freeform with our data
  47. // first create a mesh object
  48. mo = new TMeshObject(); //Delphi - mo = TMeshObject.CreateOwned(GLFreeForm.MeshObjects);
  49. mo = (TMeshObject *) (GLFreeForm->MeshObjects);
  50. mo->Mode = momFaceGroups;
  51. // Specify vertex and texcoords data (intensity is stored a texcoord)
  52. /*
  53. Ex:
  54. int TotalArray(const DynamicArray<int>& arrayOfInt)
  55. {
  56. int total=0;
  57. for (int i=arrayOfInt.Low; i<=arrayOfInt.High; i++)
  58. total += arrayOfInt[i];
  59. return total;
  60. }
  61. */
  62. //--------------------------------
  63. /*
  64. for (i=0; i<High(DataNodes);i++)
  65. {
  66. mo->Vertices->Add(DataNodes[i]->X, DataNodes[i]->Y, DataNodes[i]->Z);
  67. mo->TexCoords->Add(DataNodes[i]->Intensity*0.001, 0);
  68. }
  69. // Then create the facegroups that will hold our quads and triangles
  70. fgQuads = TFGVertexIndexList.CreateOwned(mo.FaceGroups);
  71. fgQuads->Mode = fgmmQuads;
  72. fgTris = TFGVertexIndexList.CreateOwned(mo.FaceGroups);
  73. fgTris->Mode = fgmmTriangles;
  74. // and fill them with our primitives
  75. for (i=1; i < High(DataPrimitives);i++)
  76. with DataPrimitives[i]-> do
  77. {
  78. if (Node4<>$FFFF)
  79. {
  80. fgQuads.VertexIndices.Add(Node1, Node2);
  81. fgQuads.VertexIndices.Add(Node4, Node3);
  82. }
  83. else
  84. fgTris->VertexIndices->Add(Node1, Node2, Node3);
  85. }
  86. */
  87. // auto center
  88. GLFreeForm->PerformAutoCentering();
  89. // and initialize scale
  90. TBScaleChange(this);
  91. }
  92. //---------------------------------------------------------------------------
  93. void __fastcall TForm1::GLSceneViewer1MouseDown(TObject *Sender, TMouseButton Button,
  94. TShiftState Shift, int X, int Y)
  95. {
  96. mx=X; my=Y;
  97. GLSceneViewer1->SetFocus();
  98. }
  99. //---------------------------------------------------------------------------
  100. void __fastcall TForm1::GLSceneViewer1MouseMove(TObject *Sender, TShiftState Shift,
  101. int X, int Y)
  102. {
  103. if (Shift.Contains(ssLeft))
  104. GLCamera->MoveAroundTarget(my-Y, mx-X);
  105. if (Shift.Contains(ssRight)) {
  106. DCTarget->Position->AddScaledVector((mx-X)/30, GLCamera->AbsoluteRightVectorToTarget());
  107. DCTarget->Position->AddScaledVector((Y-my)/30, GLCamera->AbsoluteUpVectorToTarget());
  108. }
  109. mx=X; my=Y;
  110. }
  111. //---------------------------------------------------------------------------
  112. void __fastcall TForm1::TBScaleChange(TObject *Sender)
  113. {
  114. GLMaterialLibrary1->Materials->Items[0]->TextureScale->X = (float)TBScale->Position/100;
  115. HTPaletteRight->Text = FormatFloat("%d", (TBScale->Position*10));
  116. GLSceneViewer1->Invalidate();
  117. }
  118. //---------------------------------------------------------------------------