/
yu_dev
/
tokm
Обзор
Документация
Войти
/
yu_dev
/
tokm
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Lab2/fStars.cpp
310 строк
10 KB
Юрий Щепилов
upload files
03 мар 2026, 15:32
Верифицирован
03 мар 2026, 15:32
748744f
Код
Авторство
О чём код?
//--------------------------------------------------------------------------- #include <vcl.h> #include <cstdlib> #include <ctime> #include <typeinfo> #pragma hdrstop #include "fStars.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma link "GLS.BaseClasses" #pragma link "GLS.Cadencer" #pragma link "GLS.Coordinates" #pragma link "GLS.Objects" #pragma link "GLS.Scene" #pragma link "GLS.SceneViewer" #pragma link "GLS.SimpleNavigation" #pragma resource "*.dfm" TForm1* Form1; int mouseX, mouseY; unsigned int perfStart, perfFinish; TStringList* RawData = new TStringList; TStringList* ParsedLine = new TStringList; int colX, colY, colZ, colSpect; float xPos, yPos, zPos; int starCount; double loadTime; int statO, statB, statA, statF, statG, statK, statM; const float SCALE = 0.15f; const float COLOR_O[3] = {0.3f, 0.5f, 1.0f}; const float COLOR_B[3] = {0.5f, 0.7f, 1.0f}; const float COLOR_A[3] = {1.0f, 1.0f, 1.0f}; const float COLOR_F[3] = {1.0f, 1.0f, 0.7f}; const float COLOR_G[3] = {1.0f, 0.9f, 0.4f}; const float COLOR_K[3] = {1.0f, 0.6f, 0.2f}; const float COLOR_M[3] = {1.0f, 0.3f, 0.1f}; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) {} //--------------------------------------------------------------------------- void __fastcall TForm1::FormCreate(TObject* Sender) { SetCurrentDir(ExtractFilePath(ParamStr(0))); OpenTextFileDialog1->InitialDir = GetCurrentDir() + "\\DATA"; OpenTextFileDialog1->Filter = "CSV files (*.csv)"; FormatSettings.DecimalSeparator = '.'; starCount = 0; loadTime = 0.0; statO = statB = statA = statF = statG = statK = statM = 0; } //--------------------------------------------------------------------------- void __fastcall TForm1::GLSceneViewer1MouseDown( TObject* Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { mouseX = X; mouseY = Y; } //--------------------------------------------------------------------------- void __fastcall TForm1::GLSceneViewer1MouseMove( TObject* Sender, TShiftState Shift, int X, int Y) { if (Shift.Contains(ssLeft)) { GLCamera1->MoveAroundTarget(mouseY - Y, mouseX - X); mouseX = X; mouseY = Y; } } //--------------------------------------------------------------------------- void __fastcall TForm1::Timer1Timer(TObject* Sender) { StatusBar1->Panels->Items[0]->Text = L"Stars: " + IntToStr(starCount) + L" | O:" + IntToStr(statO) + L" B:" + IntToStr(statB) + L" A:" + IntToStr(statA) + L" F:" + IntToStr(statF) + L" G:" + IntToStr(statG) + L" K:" + IntToStr(statK) + L" M:" + IntToStr(statM); StatusBar1->Panels->Items[1]->Text = L"Time: " + FloatToStrF(loadTime, ffFixed, 15, 3) + L" s"; GLSceneViewer1->ResetPerformanceMonitor(); } //--------------------------------------------------------------------------- void __fastcall TForm1::GLCadencer1Progress( TObject* Sender, const double deltaTime, const double newTime) { GLSceneViewer1->Invalidate(); } //--------------------------------------------------------------------------- void __fastcall TForm1::Exit1Click(TObject* Sender) { Close(); } //--------------------------------------------------------------------------- void __fastcall TForm1::btnClearClick(TObject* Sender) { GLTypeO->Free(); GLTypeB->Free(); GLTypeA->Free(); GLTypeF->Free(); GLTypeG->Free(); GLTypeK->Free(); GLTypeM->Free(); GLTypeO = static_cast<TGLPoints*>(GLDummyCube1->AddNewChild(__classid(TGLPoints))); GLTypeB = static_cast<TGLPoints*>(GLDummyCube1->AddNewChild(__classid(TGLPoints))); GLTypeA = static_cast<TGLPoints*>(GLDummyCube1->AddNewChild(__classid(TGLPoints))); GLTypeF = static_cast<TGLPoints*>(GLDummyCube1->AddNewChild(__classid(TGLPoints))); GLTypeG = static_cast<TGLPoints*>(GLDummyCube1->AddNewChild(__classid(TGLPoints))); GLTypeK = static_cast<TGLPoints*>(GLDummyCube1->AddNewChild(__classid(TGLPoints))); GLTypeM = static_cast<TGLPoints*>(GLDummyCube1->AddNewChild(__classid(TGLPoints))); starCount = 0; loadTime = 0.0; statO = statB = statA = statF = statG = statK = statM = 0; GLSceneViewer1->Invalidate(); } //--------------------------------------------------------------------------- String TrimQuotes(String s) { s = s.Trim(); if (s.Length() >= 2 && s[1] == '"' && s[s.Length()] == '"') { s = s.SubString(2, s.Length() - 2); } return s; } //--------------------------------------------------------------------------- void __fastcall TForm1::OpenCSV1Click(TObject* Sender) { if (!OpenTextFileDialog1->Execute()) return; RawData->LoadFromFile(OpenTextFileDialog1->FileName); if (RawData->Count == 0) return; ParsedLine->CommaText = RawData->Strings[0]; colX = colY = colZ = colSpect = -1; for (int i = 0; i < ParsedLine->Count; i++) { String name = TrimQuotes(ParsedLine->Strings[i]).LowerCase(); if (name == "x") colX = i; else if (name == "y") colY = i; else if (name == "z") colZ = i; else if (name == "spect") colSpect = i; } if (colX == -1 || colY == -1 || colZ == -1 || colSpect == -1) { ShowMessage("Error: Required columns (x, y, z, spect) not found!"); return; } perfStart = clock(); starCount = 0; statO = statB = statA = statF = statG = statK = statM = 0; GLTypeO->Size = 4; GLTypeB->Size = 4; GLTypeA->Size = 4; GLTypeF->Size = 4; GLTypeG->Size = 4; GLTypeK->Size = 4; GLTypeM->Size = 5; for (int row = 1; row < RawData->Count; row++) { ParsedLine->CommaText = RawData->Strings[row]; if (ParsedLine->Count <= colX || ParsedLine->Count <= colY || ParsedLine->Count <= colZ || ParsedLine->Count <= colSpect) continue; try { String xStr = TrimQuotes(ParsedLine->Strings[colX]); String yStr = TrimQuotes(ParsedLine->Strings[colY]); String zStr = TrimQuotes(ParsedLine->Strings[colZ]); if (xStr.IsEmpty() || yStr.IsEmpty() || zStr.IsEmpty()) continue; xPos = StrToFloat(xStr) * SCALE; yPos = StrToFloat(yStr) * SCALE; zPos = StrToFloat(zStr) * SCALE; String spectStr = TrimQuotes(ParsedLine->Strings[colSpect]); String specType = "M"; if (!spectStr.IsEmpty()) { String clean = spectStr.Trim(); if (clean.Length() > 0) { specType = clean.SubString(1, 1).UpperCase(); } } if (specType == "O") { GLTypeO->Colors->AddPoint(COLOR_O[0], COLOR_O[1], COLOR_O[2]); GLTypeO->Positions->Add(xPos, yPos, zPos); statO++; } else if (specType == "B") { GLTypeB->Colors->AddPoint(COLOR_B[0], COLOR_B[1], COLOR_B[2]); GLTypeB->Positions->Add(xPos, yPos, zPos); statB++; } else if (specType == "A") { GLTypeA->Colors->AddPoint(COLOR_A[0], COLOR_A[1], COLOR_A[2]); GLTypeA->Positions->Add(xPos, yPos, zPos); statA++; } else if (specType == "F") { GLTypeF->Colors->AddPoint(COLOR_F[0], COLOR_F[1], COLOR_F[2]); GLTypeF->Positions->Add(xPos, yPos, zPos); statF++; } else if (specType == "G") { GLTypeG->Colors->AddPoint(COLOR_G[0], COLOR_G[1], COLOR_G[2]); GLTypeG->Positions->Add(xPos, yPos, zPos); statG++; } else if (specType == "K") { GLTypeK->Colors->AddPoint(COLOR_K[0], COLOR_K[1], COLOR_K[2]); GLTypeK->Positions->Add(xPos, yPos, zPos); statK++; } else { GLTypeM->Colors->AddPoint(COLOR_M[0], COLOR_M[1], COLOR_M[2]); GLTypeM->Positions->Add(xPos, yPos, zPos); statM++; } starCount++; } catch (...) { continue; } } perfFinish = clock(); loadTime = (perfFinish - perfStart) / static_cast<double>(CLOCKS_PER_SEC); chbO->Checked = true; chbB->Checked = true; chbA->Checked = true; chbF->Checked = true; chbG->Checked = true; chbK->Checked = true; chbM->Checked = true; StatusBar1->Panels->Items[0]->Text = L"Loaded: " + IntToStr(starCount) + L" stars"; } //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject* Sender) { btnClearClick(Sender); } //--------------------------------------------------------------------------- void __fastcall TForm1::chbOClick(TObject *Sender) { GLTypeO->Visible = chbO->Checked; } //--------------------------------------------------------------------------- void __fastcall TForm1::chbBClick(TObject *Sender) { GLTypeB->Visible = chbB->Checked; } //--------------------------------------------------------------------------- void __fastcall TForm1::chbAClick(TObject *Sender) { GLTypeA->Visible = chbA->Checked; } //--------------------------------------------------------------------------- void __fastcall TForm1::chbFClick(TObject *Sender) { GLTypeF->Visible = chbF->Checked; } //--------------------------------------------------------------------------- void __fastcall TForm1::chbGClick(TObject *Sender) { GLTypeG->Visible = chbG->Checked; } //--------------------------------------------------------------------------- void __fastcall TForm1::chbKClick(TObject *Sender) { GLTypeK->Visible = chbK->Checked; } //--------------------------------------------------------------------------- void __fastcall TForm1::chbMClick(TObject *Sender) { GLTypeM->Visible = chbM->Checked; } //---------------------------------------------------------------------------