Newer
Older
BleedingDetectionKimura-sanMethod / raw_image_class.h
#pragma once
#include <stdio.h>
//#include <myOpenCV.h>
//#include <mymist_ver2.h>
#include "myOpenCV3.h"
#include "mymist.h"

//Raw画像の読み込みを行うクラス
//なんかデストラクタでエラーが出たので今は直接解放している(おそらくfunction.hの出血検出の関数が原因)
template <class Type>
class Raw_image
{
public:
	//Raw画像の3次元情報の保存構造体
	struct DataInfo {
		int Width = 512;
		int Height = 512;
		int IMAGESIZE = Width * Height;
		int Depth = 0;
		int VOXELS = 0;
		float reso = 0.5;
	};
	DataInfo data;

	//画像配列
	Type* image = NULL;

	//コンストラクタとデストラクタ
	Raw_image(char* filename)
	{
		//画像読み込み
		FILE* file;
		fopen_s(&file, filename, "rb");
		if (file == NULL) {
			image = NULL;
			return;
		}

		// ファイルサイズ確認
		fseek(file, 0, SEEK_END);
		int fileSize = ftell(file);
		int depth = fileSize / (data.Width * data.Height * sizeof(Type));

		if (depth != data.Depth) {
			if (data.Depth == 0) {
				data.Depth = depth;
				data.VOXELS = data.Width * data.Height * data.Depth;
			}
			else {
				data.Depth = depth > data.Depth ? data.Depth : depth;
				data.VOXELS = data.Width * data.Height * data.Depth;
			}
		}
		else {
			data.Depth = depth;
			data.VOXELS = data.Width * data.Height * data.Depth;
		}

		image = new Type[data.VOXELS];

		// データ読み込み
		fseek(file, 0, SEEK_SET);
		fread(image, sizeof(Type), data.VOXELS, file);
		fclose(file);

		return;
	}
	Raw_image()
	{
	}
	~Raw_image()
	{
		if (image != NULL) {
			//delete[] image;
		}
		return;
	}

	//読み込めているかの確認
	bool empty()
	{
		if (image == NULL) {
			return true;
		}
		else {
			return false;
		}
	}
};