@@ -362,21 +362,14 @@ Result<> WritePoleFigure::operator()()
362362 // Find how many phases we have by getting the number of Crystal Structures
363363 const size_t numPhases = crystalStructures.getNumberOfTuples ();
364364
365- // Loop over all the voxels gathering the Eulers for a specific phase into an array
365+ // Create the Image Geometry that will serve as the final storage location for each
366+ // pole figure. We are just giving it a default size for now, it will be resized
367+ // further down the algorithm.
366368 std::vector<usize> tupleShape = {1 , static_cast <usize>(m_InputValues->ImageSize ), static_cast <usize>(m_InputValues->ImageSize )};
367369 auto & imageGeom = m_DataStructure.getDataRefAs <ImageGeom>(m_InputValues->OutputImageGeometryPath );
368370 auto cellAttrMatPath = imageGeom.getCellDataPath ();
369371 imageGeom.setDimensions ({static_cast <usize>(m_InputValues->ImageSize ), static_cast <usize>(m_InputValues->ImageSize ), 1 });
370372 imageGeom.getCellData ()->resizeTuples (tupleShape);
371- for (size_t phase = 1 ; phase < numPhases; ++phase)
372- {
373- auto imageArrayPath = cellAttrMatPath.createChildPath (fmt::format (" {}Phase_{}" , m_InputValues->ImagePrefix , phase));
374- auto arrayCreationResult = nx::core::CreateArray<uint8>(m_DataStructure, tupleShape, {4ULL }, imageArrayPath, IDataAction::Mode::Execute);
375- if (arrayCreationResult.invalid ())
376- {
377- return arrayCreationResult;
378- }
379- }
380373
381374 // Loop over all the voxels gathering the Eulers for a specific phase into an array
382375 for (size_t phase = 1 ; phase < numPhases; ++phase)
@@ -666,22 +659,41 @@ Result<> WritePoleFigure::operator()()
666659 }
667660
668661 // Fetch the rendered RGBA pixels from the entire canvas.
669- std::vector<unsigned char > image (static_cast <size_t >(pageHeight * pageWidth * 4 ));
670- context.get_image_data (image .data (), pageWidth, pageHeight, pageWidth * 4 , 0 , 0 );
662+ std::vector<unsigned char > rgbaCanvasImage (static_cast <size_t >(pageHeight * pageWidth * 4 ));
663+ context.get_image_data (rgbaCanvasImage .data (), pageWidth, pageHeight, pageWidth * 4 , 0 , 0 );
671664 if (m_InputValues->SaveAsImageGeometry )
672665 {
666+ // Ensure the final Image Geometry is sized correctly.
673667 imageGeom.setDimensions ({static_cast <usize>(pageWidth), static_cast <usize>(pageHeight), 1 });
674668 imageGeom.getCellData ()->resizeTuples ({1 , static_cast <usize>(pageHeight), static_cast <usize>(pageWidth)});
675-
669+ tupleShape[0 ] = 1 ;
670+ tupleShape[1 ] = pageHeight;
671+ tupleShape[2 ] = pageWidth;
672+ // Create an output array to hold the RGB formatted color image
676673 auto imageArrayPath = cellAttrMatPath.createChildPath (fmt::format (" {}Phase_{}" , m_InputValues->ImagePrefix , phase));
674+ auto arrayCreationResult = nx::core::CreateArray<uint8>(m_DataStructure, tupleShape, {3ULL }, imageArrayPath, IDataAction::Mode::Execute);
675+ if (arrayCreationResult.invalid ())
676+ {
677+ return arrayCreationResult;
678+ }
679+ // Get a reference to the RGB final array and then copy ONLY the RGB pixels from the
680+ // canvas RGBA data.
677681 auto & imageData = m_DataStructure.getDataRefAs <UInt8Array>(imageArrayPath);
678- std::copy (image.begin (), image.end (), imageData.begin ());
682+ imageData.fill (0 );
683+ size_t tupleCount = pageHeight * pageWidth;
684+ for (size_t t = 0 ; t < tupleCount; t++)
685+ {
686+ imageData[t * 3 + 0 ] = rgbaCanvasImage[t * 4 + 0 ];
687+ imageData[t * 3 + 1 ] = rgbaCanvasImage[t * 4 + 1 ];
688+ imageData[t * 3 + 2 ] = rgbaCanvasImage[t * 4 + 2 ];
689+ }
679690 }
680691
692+ // Write out the full RGBA data
681693 if (m_InputValues->WriteImageToDisk )
682694 {
683695 const std::string filename = fmt::format (" {}/{}Phase_{}.tiff" , m_InputValues->OutputPath .string (), m_InputValues->ImagePrefix , phase);
684- auto result = TiffWriter::WriteImage (filename, pageWidth, pageHeight, 4 , image .data ());
696+ auto result = TiffWriter::WriteImage (filename, pageWidth, pageHeight, 4 , rgbaCanvasImage .data ());
685697 if (result.first < 0 )
686698 {
687699 return MakeErrorResult (-53900 , fmt::format (" Error writing pole figure image '{}' to disk.\n Error Code from Tiff Writer: {}\n Message: {}" , filename, result.first , result.second ));
0 commit comments