626 G4int returnvalue = 0;
size_t rflag = 0;
631 fTab =
new G4int*[fRows];
632 for (
G4int i = 0; i < fRows; i ++ ) {
633 fTab[i] =
new G4int[fColumns];
636 if(fBitAllocated == 8) {
638 std::printf(
"@@@ Error! Picture != 16 bits...\n");
639 std::printf(
"@@@ Error! Picture != 16 bits...\n");
640 std::printf(
"@@@ Error! Picture != 16 bits...\n");
642 unsigned char ch = 0;
644 for(
G4int j = 0; j < fRows; j++) {
645 for(
G4int i = 0; i < fColumns; i++) {
647 rflag = std::fread( &ch, 1, 1, dicom);
648 fTab[j][i] = ch*fRescaleSlope + fRescaleIntercept;
656 for(
G4int j = 0; j < fRows; j++) {
657 for(
G4int i = 0; i < fColumns; i++) {
659 rflag = std::fread(sbuff, 2, 1, dicom);
660 GetValue(sbuff, pixel);
661 fTab[j][i] = pixel*fRescaleSlope + fRescaleIntercept;
667 char * nameProcessed =
new char[FILENAMESIZE];
670 std::sprintf(nameProcessed,
"%s.g4dcmb",filename2);
671 fileOut = std::fopen(nameProcessed,
"w+b");
672 std::printf(
"### Writing of %s ###\n",nameProcessed);
674 unsigned int nMate = fMaterialIndices.size();
675 rflag = std::fwrite(&nMate,
sizeof(
unsigned int), 1, fileOut);
677 std::map<G4float,G4String>::const_iterator ite;
678 for( ite = fMaterialIndices.begin(); ite != fMaterialIndices.end(); ite++ ){
680 for(
G4int ii = (*ite).second.length(); ii < 40; ii++ ) {
684 const char* mateNameC = mateName.c_str();
685 rflag = std::fwrite(mateNameC,
sizeof(
char),40, fileOut);
688 unsigned int fRowsC = fRows/fCompression;
689 unsigned int fColumnsC = fColumns/fCompression;
690 unsigned int planesC = 1;
691 G4float pixelLocationXM = -fPixelSpacingX*fColumns/2.;
692 G4float pixelLocationXP = fPixelSpacingX*fColumns/2.;
693 G4float pixelLocationYM = -fPixelSpacingY*fRows/2.;
694 G4float pixelLocationYP = fPixelSpacingY*fRows/2.;
695 G4float fSliceLocationZM = fSliceLocation-fSliceThickness/2.;
696 G4float fSliceLocationZP = fSliceLocation+fSliceThickness/2.;
698 rflag = std::fwrite(&fRowsC,
sizeof(
unsigned int), 1, fileOut);
699 rflag = std::fwrite(&fColumnsC,
sizeof(
unsigned int), 1, fileOut);
700 rflag = std::fwrite(&planesC,
sizeof(
unsigned int), 1, fileOut);
702 rflag = std::fwrite(&pixelLocationXM,
sizeof(
G4float), 1, fileOut);
703 rflag = std::fwrite(&pixelLocationXP,
sizeof(
G4float), 1, fileOut);
704 rflag = std::fwrite(&pixelLocationYM,
sizeof(
G4float), 1, fileOut);
705 rflag = std::fwrite(&pixelLocationYP,
sizeof(
G4float), 1, fileOut);
706 rflag = std::fwrite(&fSliceLocationZM,
sizeof(
G4float), 1, fileOut);
707 rflag = std::fwrite(&fSliceLocationZP,
sizeof(
G4float), 1, fileOut);
710 std::printf(
"%8i %8i\n",fRows,fColumns);
711 std::printf(
"%8f %8f\n",fPixelSpacingX,fPixelSpacingY);
712 std::printf(
"%8f\n", fSliceThickness);
713 std::printf(
"%8f\n", fSliceLocation);
714 std::printf(
"%8i\n", fCompression);
716 G4int compSize = fCompression;
723 for(
G4int ww = 0; ww < fRows; ww++) {
724 for(
G4int xx = 0; xx < fColumns; xx++) {
726 density = Pixel2density(mean);
727 unsigned int mateID = GetMaterialIndex( density );
728 rflag = std::fwrite(&mateID,
sizeof(
unsigned int), 1, fileOut);
735 for(
G4int ww = 0; ww < fRows ;ww += compSize ) {
736 for(
G4int xx = 0; xx < fColumns ;xx +=compSize ) {
739 for(
int sumx = 0; sumx < compSize; sumx++) {
740 for(
int sumy = 0; sumy < compSize; sumy++) {
741 if(ww+sumy >= fRows || xx+sumx >= fColumns) overflow =
true;
742 mean += fTab[ww+sumy][xx+sumx];
746 mean /= compSize*compSize;
749 density = Pixel2density(mean);
750 unsigned int mateID = GetMaterialIndex( density );
751 rflag = std::fwrite(&mateID,
sizeof(
unsigned int), 1, fileOut);
760 for(
G4int ww = 0; ww < fRows; ww++) {
761 for(
G4int xx = 0; xx < fColumns; xx++) {
763 density = Pixel2density(mean);
764 rflag = std::fwrite(&density,
sizeof(
G4float), 1, fileOut);
771 for(
G4int ww = 0; ww < fRows ;ww += compSize ) {
772 for(
G4int xx = 0; xx < fColumns ;xx +=compSize ) {
775 for(
int sumx = 0; sumx < compSize; sumx++) {
776 for(
int sumy = 0; sumy < compSize; sumy++) {
777 if(ww+sumy >= fRows || xx+sumx >= fColumns) overflow =
true;
778 mean += fTab[ww+sumy][xx+sumx];
782 mean /= compSize*compSize;
785 density = Pixel2density(mean);
786 rflag = std::fwrite(&density,
sizeof(
G4float), 1, fileOut);
793 rflag = std::fclose(fileOut);
795 delete [] nameProcessed;
803 if (rflag)
return returnvalue;