void ImageFunction::initImageData() { #ifdef LIBMESH_HAVE_VTK // Get access to the Mesh object FEProblem * fe_problem = getParam<FEProblem *>("_fe_problem"); MooseMesh & mesh = fe_problem->mesh(); // Set the dimensions from the Mesh if not set by the User if (isParamValid("dimensions")) _physical_dims = getParam<Point>("dimensions"); else { _physical_dims(0) = mesh.getParam<Real>("xmax") - mesh.getParam<Real>("xmin"); #if LIBMESH_DIM > 1 _physical_dims(1) = mesh.getParam<Real>("ymax") - mesh.getParam<Real>("ymin"); #endif #if LIBMESH_DIM > 2 _physical_dims(2) = mesh.getParam<Real>("zmax") - mesh.getParam<Real>("zmin"); #endif } // Set the origin from the Mesh if not set in the input file if (isParamValid("origin")) _origin = getParam<Point>("origin"); else { _origin(0) = mesh.getParam<Real>("xmin"); #if LIBMESH_DIM > 1 _origin(1) = mesh.getParam<Real>("ymin"); #endif #if LIBMESH_DIM > 2 _origin(2) = mesh.getParam<Real>("zmin"); #endif } // Check the file range and do some error checking if (isParamValid("file_range")) { _file_range = getParam<std::vector<unsigned int> >("file_range"); if (_file_range.size() == 1) _file_range.push_back(_file_range[0]); if (_file_range.size() != 2) mooseError("Image range must specify one or two interger values"); if (_file_range[1] < _file_range[0]) mooseError("Image range must specify exactly two interger values, with the second larger than the first"); } else { _file_range.push_back(0); _file_range.push_back(std::numeric_limits<unsigned int>::max()); } #endif }
int tarch::plotter::griddata::regular::CartesianGridArrayWriter::getCellIndex( const tarch::la::Vector<3,double>& position ) { logTraceInWith1Argument( "getCellIndex(Vector)", position ); int result(0); int base = 1; tarch::la::Vector<3,double> h; h = getH(); for (int d=0; d<3; d++) { double translatedPointPosition = position(d)-_origin(d) +h(d)/2.0 + tarch::la::NUMERICAL_ZERO_DIFFERENCE; int index = 0; if (tarch::la::greater(h(d),0.0)) { translatedPointPosition = translatedPointPosition/h(d); index = static_cast<int>(floor(translatedPointPosition)); } if (index<0) { index = 0; } if (index>=_numberOfGridPoints(d)-1) { index = _numberOfGridPoints(d)-2; } result += index * base; base *= (_numberOfGridPoints(d)-1); } logTraceOutWith1Argument( "getCellIndex(Vector)", result); return result; }
Real ImageSampler::sample(const Point & p) { #ifdef LIBMESH_HAVE_VTK // Do nothing if the point is outside of the image domain if (!_bounding_box.contains_point(p)) return 0.0; // Determine pixel coordinates std::vector<int> x(3,0); for (int i = 0; i < LIBMESH_DIM; ++i) { // Compute position, only if voxel size is greater than zero if (_voxel[i] == 0) x[i] = 0; else { x[i] = std::floor((p(i) - _origin(i))/_voxel[i]); // If the point falls on the mesh extents the index needs to be decreased by one if (x[i] == _dims[i]) x[i]--; } } // Return the image data at the given point return _data->GetScalarComponentAsDouble(x[0], x[1], x[2], _component); #else libmesh_ignore(p); // avoid un-used parameter warnings return 0.0; #endif }
bool tarch::plotter::griddata::regular::CartesianGridArrayWriter::containsCell( const tarch::la::Vector<3,double>& offset, const tarch::la::Vector<3,double>& boundingBox ) const { tarch::la::Vector<3,double> centerOfVoxel; tarch::la::Vector<3,double> hHalfOfVoxel; hHalfOfVoxel = boundingBox / 2.0; centerOfVoxel = offset + hHalfOfVoxel; bool result = true; for (int d=0; d<3; d++) { result &= centerOfVoxel(d) >= _origin(d)-hHalfOfVoxel(d); result &= centerOfVoxel(d) <= _origin(d)+_domainSize(d)+hHalfOfVoxel(d); } return result; }
tarch::plotter::griddata::regular::CartesianGridArrayWriter::CartesianGridArrayWriter( const tarch::la::Vector<2,int>& numberOfGridPoints, const tarch::la::Vector<2,double>& domainSize, const tarch::la::Vector<2,double>& origin ): _writtenToFile( false ), _numberOfGridPoints(1), _domainSize(0.0), _origin(0.0), _vertexData(), _cellData() { for (int d=0; d<2; d++) { _numberOfGridPoints(d) = numberOfGridPoints(d); _domainSize(d) = domainSize(d); _origin(d) = origin(d); } }
void tarch::plotter::griddata::regular::vtk::VTKTextFileWriter::writeToFile( const std::string& filename ) { logTraceInWith5Arguments( "writeToFile(filename)", filename, _writtenToFile, _numberOfGridPoints, _domainSize, _origin ); std::ofstream out; out.open( filename.c_str() ); if ( (!out.fail()) && out.is_open() ) { _log.debug( "close()", "opened data file " + filename ); out << HEADER << std::endl << std::endl; out << "DATASET STRUCTURED_POINTS" << std::endl << "DIMENSIONS " << _numberOfGridPoints(0) << " " << _numberOfGridPoints(1) << " " << _numberOfGridPoints(2) << std::endl << std::endl; out << "ORIGIN " << static_cast<float>(_origin(0)) << " " << static_cast<float>(_origin(1)) << " " << static_cast<float>(_origin(2)) << std::endl << std::endl; out << "SPACING " << static_cast<float>(getH()(0)) << " " << static_cast<float>(getH()(1)) << " " << static_cast<float>(getH()(2)) << std::endl << std::endl; assertion(static_cast<float>(getH()(0))>0); assertion(static_cast<float>(getH()(1))>0); assertion(static_cast<float>(getH()(2))>=0); if (!_vertexData.empty()) { out << "POINT_DATA " << tarch::la::volume(_numberOfGridPoints) << std::endl << std::endl; for (int i=0; i<static_cast<int>(_vertexData.size()); i++) { if (_vertexData[i]._recordsPerEntry == 3) { out << "VECTORS " << _vertexData[i]._identifier << " float " << std::endl; } else { out << "SCALARS " << _vertexData[i]._identifier << " float " << _vertexData[i]._recordsPerEntry << std::endl; out << "LOOKUP_TABLE default" << std::endl; } for (int j=0; j<tarch::la::volume(_numberOfGridPoints); j++) { for (int k=0; k<_vertexData[i]._recordsPerEntry; k++) { out << static_cast<float>(_vertexData[i]._data[j*_vertexData[i]._recordsPerEntry+k]) << " "; } out << std::endl; } out << std::endl << std::endl; } } if (!_cellData.empty()) { out << "CELL_DATA " << tarch::la::volume(_numberOfGridPoints-1) << std::endl << std::endl; for (int i=0; i<static_cast<int>(_cellData.size()); i++) { if (_cellData[i]._recordsPerEntry == 3) { out << "VECTORS " << _cellData[i]._identifier << " float " << std::endl; } else { out << "SCALARS " << _cellData[i]._identifier << " float " << _cellData[i]._recordsPerEntry << std::endl; } for (int j=0; j<tarch::la::volume(_numberOfGridPoints-1); j++) { for (int k=0; k<_cellData[i]._recordsPerEntry; k++) { out << static_cast<float>(_cellData[i]._data[j*_cellData[i]._recordsPerEntry+k]) << " "; } out << std::endl; } out << std::endl << std::endl; } } _writtenToFile = true; } logTraceOut( "writeToFile(filename)" ); }
void ImageSampler::setupImageSampler(MooseMesh & mesh) { #ifdef LIBMESH_HAVE_VTK // Get access to the Mesh object MeshTools::BoundingBox bbox = MeshTools::bounding_box(mesh.getMesh()); // Set the dimensions from the Mesh if not set by the User if (_is_pars.isParamValid("dimensions")) _physical_dims = _is_pars.get<Point>("dimensions"); else { _physical_dims(0) = bbox.max()(0) - bbox.min()(0); #if LIBMESH_DIM > 1 _physical_dims(1) = bbox.max()(1) - bbox.min()(1); #endif #if LIBMESH_DIM > 2 _physical_dims(2) = bbox.max()(2) - bbox.min()(2); #endif } // Set the origin from the Mesh if not set in the input file if (_is_pars.isParamValid("origin")) _origin = _is_pars.get<Point>("origin"); else { _origin(0) = bbox.min()(0); #if LIBMESH_DIM > 1 _origin(1) = bbox.min()(1); #endif #if LIBMESH_DIM > 2 _origin(2) = bbox.min()(2); #endif } // An array of filenames, to be filled in std::vector<std::string> filenames; // The file suffix, to be determined std::string file_suffix; // Try to parse our own file range parameters. If that fails, then // see if the associated Mesh is an ImageMesh and use its. If that // also fails, then we have to throw an error... // // The parseFileRange method sets parameters, thus a writable reference to the InputParameters // object must be obtained from the warehouse. Generally, this should be avoided, but // this is a special case. if (_status != 0) { // We don't have parameters, so see if we can get them from ImageMesh ImageMesh * image_mesh = dynamic_cast<ImageMesh*>(&mesh); if (!image_mesh) mooseError("No file range parameters were provided and the Mesh is not an ImageMesh."); // Get the ImageMesh's parameters. This should work, otherwise // errors would already have been thrown... filenames = image_mesh->filenames(); file_suffix = image_mesh->fileSuffix(); } else { // Use our own parameters (using 'this' b/c of conflicts with filenames the local variable) filenames = this->filenames(); file_suffix = fileSuffix(); } // Storage for the file names _files = vtkSmartPointer<vtkStringArray>::New(); for (unsigned i=0; i<filenames.size(); ++i) _files->InsertNextValue(filenames[i]); // Error if no files where located if (_files->GetNumberOfValues() == 0) mooseError("No image file(s) located"); // Read the image stack. Hurray for VTK not using polymorphism in a // smart way... we actually have to explicitly create the type of // reader based on the file extension, using an if-statement... if (file_suffix == "png") _image = vtkSmartPointer<vtkPNGReader>::New(); else if (file_suffix == "tiff" || file_suffix == "tif") _image = vtkSmartPointer<vtkTIFFReader>::New(); else mooseError("Un-supported file type '" << file_suffix << "'"); // Now that _image is set up, actually read the images // Indicate that data read has started _is_console << "Reading image(s)..." << std::endl; // Extract the data _image->SetFileNames(_files); _image->Update(); _data = _image->GetOutput(); _algorithm = _image->GetOutputPort(); // Set the image dimensions and voxel size member variable int * dims = _data->GetDimensions(); for (unsigned int i = 0; i < 3; ++i) { _dims.push_back(dims[i]); _voxel.push_back(_physical_dims(i)/_dims[i]); } // Set the dimensions of the image and bounding box _data->SetSpacing(_voxel[0], _voxel[1], _voxel[2]); _data->SetOrigin(_origin(0), _origin(1), _origin(2)); _bounding_box.min() = _origin; _bounding_box.max() = _origin + _physical_dims; // Indicate data read is completed _is_console << " ...image read finished" << std::endl; // Set the component parameter // If the parameter is not set then vtkMagnitude() will applied if (_is_pars.isParamValid("component")) { unsigned int n = _data->GetNumberOfScalarComponents(); _component = _is_pars.get<unsigned int>("component"); if (_component >= n) mooseError("'component' parameter must be empty or have a value of 0 to " << n-1); } else _component = 0; // Apply filters, the toggling on and off of each filter is handled internally vtkMagnitude(); vtkShiftAndScale(); vtkThreshold(); vtkFlip(); #endif }
OptionsMenu::OptionsMenu(ID3D11Device* Device, ID3D11DeviceContext* DeviceContext, int ScreenHeight, int ScreenWidth, Input* input, SoundManager* SoundManager) : Screen(Device, DeviceContext, ScreenHeight, ScreenWidth, input) { m_font = make_unique<SpriteFont>(Device, L"Resources/moonhouse.spritefont"); CreateWICTextureFromFile(Device, L"Resources/Sprites/Background.png", nullptr, m_background.ReleaseAndGetAddressOf()); ReadSetttings(); SimpleMath::Vector2 _offsetV,_originV; _offsetV.x = 0.0f; _offsetV.y = 50.f; _originV.x = 0; _originV.y = 0; m_soundManager = SoundManager; for (int i = 0; i < 10; i++) { m_volym[i] = i; } ReadSetttings(); m_soundManager->SetEffectVolume(m_currentMVol); m_soundManager->SetMusicVolume(m_currentSVol); m_volumeMusic = L"Music Volume: "; m_choices[MUSICVOLUME].m_position.y = m_screenHeight*1/10; m_choices[MUSICVOLUME].m_origin = _originV; m_choices[MUSICVOLUME].m_position.x = m_choices[MUSICVOLUME].m_origin.x; m_choices[MUSICVOLUME].m_color = Colors::White; m_volumeEffect = L"Shots Volume: "; m_choices[SHOTSVOLUME].m_position.y = m_screenHeight*2/10; m_choices[SHOTSVOLUME].m_origin = _originV; m_choices[SHOTSVOLUME].m_position.x = m_choices[SHOTSVOLUME].m_origin.x; m_choices[SHOTSVOLUME].m_color = Colors::Crimson; m_resolution = L"Resolution: " + to_wstring(m_screenHeight) + L" x " + to_wstring(m_screenWidth); m_choices[RESOLUTION].m_position.y = m_screenHeight*3/10; m_choices[RESOLUTION].m_origin = _originV; m_choices[RESOLUTION].m_position.x = m_choices[RESOLUTION].m_origin.x; m_choices[RESOLUTION].m_color = Colors::Crimson; m_keyBin = L"KeyBindings:"; m_choices[KEYBINDING].m_position.y = m_screenHeight *4/10; m_choices[KEYBINDING].m_origin = _originV; m_choices[KEYBINDING].m_position.x = m_choices[KEYBINDING].m_origin.x; m_choices[KEYBINDING].m_color = Colors::Crimson; m_apply = L"Apply"; m_choices[APPLY].m_position.y = m_screenHeight* 8/10; m_choices[APPLY].m_origin = m_font->MeasureString(m_apply.c_str()) / 2.f; m_choices[APPLY].m_position.x = m_screenWidth / 2.f; m_choices[APPLY].m_color = Colors::Crimson; m_pause = L"Back"; m_menu = L"Return to Main Menu"; m_choices[MAINMENU].m_position.y = m_screenHeight*9/10 ; m_choices[MAINMENU].m_origin = m_font->MeasureString(m_menu.c_str()) / 2.f; m_choices[MAINMENU].m_position.x = m_screenWidth / 2.f; m_choices[MAINMENU].m_color = Colors::Crimson; //The different Resolutions. m_unBound = L"Press a Key"; for (int i = 0; i < 9; i++) m_keyBindings[i] = m_input->GetKeyBiningArray(i); m_res[0].first = 480; m_res[1].first = 720; m_res[2].first = 793; m_res[3].first = 1058; m_res[0].second = L"480 x 653 "; m_res[1].second = L"720 x 980 "; m_res[2].second = L"793 x 1080 "; m_res[3].second = L"1058 x 1440"; m_resolutions[0].first = 480; m_resolutions[1].first = 720; m_resolutions[2].first = 793; m_resolutions[3].first = 1058; m_resolutions[0].second = 653; m_resolutions[1].second = 980; m_resolutions[2].second = 1080; m_resolutions[3].second = 1440; float _tempSy = m_resolutions[m_defRes].second/10.f; float _tempSx = m_resolutions[m_defRes].first/4.f; m_scaleMenu = SimpleMath::Vector3(0.7f,0.7f, 1.0f); for (int i = 0; i < 4; i++) { if (m_res[i].first == m_screenWidth) m_currentRes = i; } m_defRes = m_currentRes; //Keybindings m_keys[WEAPON_1] = L"Weapon 1:" ; m_keys[WEAPON_2] = L"Weapon 2:" ; m_keys[WEAPON_3] = L"Weapon 3:" ; m_keys[WEAPON_4] = L"Weapon 4:" ; m_keys[MOVELEFT] = L"Move Left:" ; m_keys[MOVERIGHT] = L"Move Right:"; m_keys[MOVEDOWN] = L"Move Down:" ; m_keys[MOVEUP] = L"Move up:" ; m_keys[COMBO] = L"Combo key:" ; m_boundKeys[WEAPON_1 ] = m_input->GetKeyBinding( m_keyBindings[WEAPON_1]); m_boundKeys[WEAPON_2 ] = m_input->GetKeyBinding( m_keyBindings[WEAPON_2]); m_boundKeys[WEAPON_3 ] = m_input->GetKeyBinding( m_keyBindings[WEAPON_3]); m_boundKeys[WEAPON_4 ] = m_input->GetKeyBinding( m_keyBindings[WEAPON_4]); m_boundKeys[MOVELEFT ] = m_input->GetKeyBinding( m_keyBindings[MOVELEFT]); m_boundKeys[MOVERIGHT] = m_input->GetKeyBinding(m_keyBindings[MOVERIGHT]); m_boundKeys[MOVEDOWN ] = m_input->GetKeyBinding( m_keyBindings[MOVEDOWN]); m_boundKeys[MOVEUP ] = m_input->GetKeyBinding( m_keyBindings[MOVEUP]); m_boundKeys[COMBO ] = m_input->GetKeyBinding( m_keyBindings[COMBO]); SimpleMath::Vector2 _origin(0.0, 0.0); m_keyChoice[WEAPON_1].m_color = Colors::Crimson; m_keyChoice[WEAPON_1].m_length = m_font->MeasureString(m_keys[WEAPON_1].c_str()); m_keyChoice[WEAPON_2].m_color = Colors::Crimson; m_keyChoice[WEAPON_2].m_length = m_font->MeasureString(m_keys[WEAPON_2].c_str()); m_keyChoice[WEAPON_3].m_color = Colors::Crimson; m_keyChoice[WEAPON_3].m_length = m_font->MeasureString(m_keys[WEAPON_3].c_str()); m_keyChoice[WEAPON_4].m_color = Colors::Crimson; m_keyChoice[WEAPON_4].m_length = m_font->MeasureString(m_keys[WEAPON_4].c_str()); m_keyChoice[MOVELEFT].m_color = Colors::Crimson; m_keyChoice[MOVELEFT].m_length = m_font->MeasureString(m_keys[MOVELEFT].c_str()); m_keyChoice[MOVERIGHT].m_color = Colors::Crimson; m_keyChoice[MOVERIGHT].m_length = m_font->MeasureString(m_keys[MOVERIGHT].c_str()); m_keyChoice[MOVEUP].m_color = Colors::Crimson; m_keyChoice[MOVEUP].m_length = m_font->MeasureString(m_keys[MOVEUP].c_str()); m_keyChoice[MOVEDOWN].m_color = Colors::Crimson; m_keyChoice[MOVEDOWN].m_length = m_font->MeasureString(m_keys[MOVEDOWN].c_str()); m_keyChoice[COMBO].m_color = Colors::Crimson; m_keyChoice[COMBO].m_length = m_font->MeasureString(m_keys[COMBO].c_str()); float _tempScale = (m_resolutions[m_defRes].first / (2*(m_keyChoice[WEAPON_1].m_length.x + m_keyChoice[WEAPON_2].m_length.x + m_keyChoice[WEAPON_3].m_length.x + m_keyChoice[WEAPON_4].m_length.x))); m_scaleKey = SimpleMath::Vector3(_tempScale, _tempScale,1.0f); float _offset[4]; for (auto i = 0; i < 4; i++) _offset[i] = i*(m_resolutions[m_defRes].first / 4); m_keyChoice[WEAPON_1].m_position = SimpleMath::Vector2(_offset[0], m_screenHeight *5/10 ); m_keyChoice[WEAPON_2].m_position = SimpleMath::Vector2(_offset[1], m_screenHeight *5/10 ); m_keyChoice[WEAPON_3].m_position = SimpleMath::Vector2(_offset[2], m_screenHeight *5/10 ); m_keyChoice[WEAPON_4].m_position = SimpleMath::Vector2(_offset[3], m_screenHeight *5/10 ); m_keyChoice[MOVELEFT].m_position = SimpleMath::Vector2(_offset[0], m_screenHeight *6/10 ); m_keyChoice[MOVERIGHT].m_position = SimpleMath::Vector2(_offset[1],m_screenHeight *6/10 ); m_keyChoice[MOVEUP].m_position = SimpleMath::Vector2(_offset[2], m_screenHeight *6/10 ); m_keyChoice[MOVEDOWN].m_position = SimpleMath::Vector2(_offset[3], m_screenHeight *6/10 ); m_keyChoice[COMBO].m_position = SimpleMath::Vector2(_offset[0], m_screenHeight *7/10); m_boundKeyPos[WEAPON_1] = m_keyChoice[WEAPON_1].m_position + m_keyChoice[WEAPON_1].m_length*m_scaleKey.x; m_boundKeyPos[WEAPON_1].y = m_keyChoice[WEAPON_1].m_position.y; m_boundKeyPos[WEAPON_2] = m_keyChoice[WEAPON_2].m_position + m_keyChoice[WEAPON_2].m_length*m_scaleKey.x; m_boundKeyPos[WEAPON_2].y = m_keyChoice[WEAPON_2].m_position.y; m_boundKeyPos[WEAPON_3] = m_keyChoice[WEAPON_3].m_position + m_keyChoice[WEAPON_3].m_length*m_scaleKey.x; m_boundKeyPos[WEAPON_3].y = m_keyChoice[WEAPON_3].m_position.y; m_boundKeyPos[WEAPON_4] = m_keyChoice[WEAPON_4].m_position + m_keyChoice[WEAPON_4].m_length*m_scaleKey.x; m_boundKeyPos[WEAPON_4].y = m_keyChoice[WEAPON_4].m_position.y; m_boundKeyPos[MOVELEFT] = m_keyChoice[MOVELEFT].m_position + m_keyChoice[MOVELEFT].m_length*m_scaleKey.x; m_boundKeyPos[MOVELEFT].y = m_keyChoice[MOVELEFT].m_position.y; m_boundKeyPos[MOVERIGHT] = m_keyChoice[MOVERIGHT].m_position + m_keyChoice[MOVERIGHT].m_length*m_scaleKey.x; m_boundKeyPos[MOVERIGHT].y = m_keyChoice[MOVERIGHT].m_position.y; m_boundKeyPos[MOVEUP] = m_keyChoice[MOVEUP].m_position + m_keyChoice[MOVEUP].m_length*m_scaleKey.x; m_boundKeyPos[MOVEUP].y = m_keyChoice[MOVEUP].m_position.y; m_boundKeyPos[MOVEDOWN] = m_keyChoice[MOVEDOWN].m_position + m_keyChoice[MOVEDOWN].m_length*m_scaleKey.x; m_boundKeyPos[MOVEDOWN].y = m_keyChoice[MOVEDOWN].m_position.y; m_boundKeyPos[COMBO] = m_keyChoice[COMBO].m_position + m_keyChoice[COMBO].m_length*m_scaleKey.x; m_boundKeyPos[COMBO].y = m_keyChoice[COMBO].m_position.y; //Determening what the current resolutions is. switch (m_screenHeight) { case 653: m_currentRes = 0; break; case 980: m_currentRes = 1; break; case 1080: m_currentRes = 2; break; case 1440: m_currentRes = 3; break; } m_currentFont = 0; m_ifKey = NOT_KEY; m_currentTargetMenu = OPTION; }