~ElementIterator() { if (0 != id) { Cmiss_element_iterator_destroy(&id); } }
ElementIterator& operator=(const ElementIterator& elementIterator) { Cmiss_element_iterator_id temp_id = Cmiss_element_iterator_access(elementIterator.id); if (0 != id) { Cmiss_element_iterator_destroy(&id); } id = temp_id; return *this; }
StrainMeasures::StrainMeasures(std::vector<std::string> mesh) : mySegments(NULL) { num_level_sets = 10; num_elements = 48; num_nodes = 98; elements.resize(num_elements); x_discret = 25; y_discret = 25; lagrangian = true; modelPGS = 0.0; computeModelPGS = false; ejectionFraction = 0.0; extraNodeStartID = 100000; LVMyocardialVolume* lvm = new LVMyocardialVolume(mesh); volumes = lvm->getMyocardialVolumes(); delete lvm; //Read the mesh context_ = Cmiss_context_create("strainmeasure"); /**< Handle to the context */ Cmiss_region_id root_region = Cmiss_context_get_default_region(context_); //This required for using the cmiss_context_execute_command Cmiss_context_enable_user_interface(context_, NULL); //Load the finite element mesh of the heart std::string region_name = "heart"; Cmiss_region_id heart_region = Cmiss_region_create_child(root_region, region_name.c_str()); //Get the field module of the heart region field_module = Cmiss_region_get_field_module(heart_region); fieldCache = Cmiss_field_module_create_cache(field_module); numberOfModelFrames_ = mesh.size(); double denom = numberOfModelFrames_ - 1; for (unsigned int i = 0; i < numberOfModelFrames_; i++) { double time = static_cast<double>(i) / denom; Cmiss_stream_information_id stream_information = Cmiss_region_create_stream_information(root_region); Cmiss_stream_information_region_id stream_information_region = Cmiss_stream_information_cast_region(stream_information); Cmiss_stream_resource_id stream_resource = Cmiss_stream_information_create_resource_memory_buffer(stream_information, mesh[i].c_str(), mesh[i].length()); Cmiss_stream_information_region_set_resource_attribute_real(stream_information_region, stream_resource, CMISS_STREAM_INFORMATION_REGION_ATTRIBUTE_TIME, time); Cmiss_region_read(root_region, stream_information); Cmiss_stream_resource_destroy(&stream_resource); Cmiss_stream_information_destroy(&stream_information); Cmiss_stream_information_region_destroy(&stream_information_region); } { //Define the necessary fields std::string referenceMesh = mesh[0]; //Change coordinate name to reference_coordinates boost::replace_all(referenceMesh, "1) coordinates", "1) reference_coordinates"); //Load the reference coordinates mesh Cmiss_stream_information_id stream_information = Cmiss_region_create_stream_information(root_region); Cmiss_stream_information_region_id stream_information_region = Cmiss_stream_information_cast_region(stream_information); Cmiss_stream_resource_id stream_resource = Cmiss_stream_information_create_resource_memory_buffer(stream_information, referenceMesh.c_str(), referenceMesh.length()); Cmiss_region_read(root_region, stream_information); Cmiss_stream_resource_destroy(&stream_resource); Cmiss_stream_information_destroy(&stream_information); } coordianteField = Cmiss_field_module_find_field_by_name(field_module, "reference_coordinates"); if (!coordianteField) { std::cout << "reference_coordinates field not found " << std::endl; } Cmiss_region_destroy(&heart_region); //#Calculate the strains Cmiss_field_module_define_field(field_module, "F", "gradient coordinate reference_coordinates field coordinates"); Cmiss_field_module_define_field(field_module, "F_transpose", "transpose source_number_of_rows 3 field F"); Cmiss_field_module_define_field(field_module, "C", "matrix_multiply number_of_rows 3 fields F_transpose F"); Cmiss_field_module_define_field(field_module, "principal_strains", "eigenvalues field C"); Cmiss_field_destroy(&coordianteField); //Assign the coordinates field to the handle for downstream use coordianteField = Cmiss_field_module_find_field_by_name(field_module, "coordinates"); //Define the fibre field { //Load the reference fibre data and reference coordinates { if (Cmiss_field_module_find_field_by_name(field_module, "fibres") == NULL) { Cmiss_stream_information_id stream_information = Cmiss_region_create_stream_information(root_region); Cmiss_stream_information_region_id stream_information_region = Cmiss_stream_information_cast_region(stream_information); //Cmiss_stream_resource_id stream_resource = Cmiss_stream_information_create_resource_memory_buffer(stream_information, reffibre_exregion, reffibre_exregion_len); Cmiss_stream_resource_id stream_resource = Cmiss_stream_information_create_resource_memory_buffer(stream_information, humandtifibre_exregion, humandtifibre_exregion_len); Cmiss_region_read(root_region, stream_information); Cmiss_stream_resource_destroy(&stream_resource); Cmiss_stream_information_destroy(&stream_information); } //Define fibre field //#Calculate the deformed fibre axes Cmiss_field_module_define_field(field_module, "fibre_axes", "fibre_axes coordinate reference_coordinates fibre fibres"); Cmiss_field_module_define_field(field_module, "deformed_fibre_axes", "matrix_multiply number_of_rows 3 fields fibre_axes F_transpose"); Cmiss_field_module_define_field(field_module, "deformed_fibre", "composite deformed_fibre_axes.1 deformed_fibre_axes.2 deformed_fibre_axes.3"); Cmiss_field_module_define_field(field_module, "principal_fibre_strain1", "composite deformed_fibre_axes.1"); } } //Determine the myocardial volume //Get the element and node handles Cmiss_mesh_id cmiss_mesh = Cmiss_field_module_find_mesh_by_name(field_module, "cmiss_mesh_3d"); Cmiss_element_iterator_id elementIterator = Cmiss_mesh_create_element_iterator(cmiss_mesh); Cmiss_element_id element = Cmiss_element_iterator_next(elementIterator); while (element != NULL) { int elementId = Cmiss_element_get_identifier(element) - 1; //Cmiss numbering starts at 1 elements[elementId] = element; element = Cmiss_element_iterator_next(elementIterator); } Cmiss_element_iterator_destroy(&elementIterator); Cmiss_mesh_destroy(&cmiss_mesh); Cmiss_region_destroy(&root_region); }