예제 #1
0
파일: cav2.cpp 프로젝트: paul-thomson/cav2
void averageValue() {

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glBegin(GL_POINTS);

	for(int y = 0; y < head->GetHeight(); y++)
		for(int z = 0; z < head->GetDepth(); z++) {
			double totalValue = 0;
			for (int x = 0; x < head->GetWidth(); x++) {

				unsigned char val = head->Get(x, y, z);

				double normalisedVal = val/255.0;
				totalValue += normalisedVal;
			}

			Vector3 color = whiteTransfer(totalValue/(double)head->GetWidth());
			glColor4f(color.r(), color.g(), color.b(), 1);

			glVertex3f(y, z, 0);
		}
	glEnd();

	glFlush();
	glutSwapBuffers();
}
예제 #2
0
파일: cav2.cpp 프로젝트: paul-thomson/cav2
void maximumIntensityProjection() {

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glBegin(GL_POINTS);

	for(int y = 0; y < head->GetHeight(); y++)
		for(int z = 0; z < head->GetDepth(); z++) {
			double maxValue = 0;
			for (int x = 0; x < head->GetWidth(); x++) {

				unsigned char val = head->Get(x, y, z);

				double normalisedVal = val/255.0;
				if (normalisedVal > maxValue) {
					maxValue = normalisedVal;
				}
			}

			Vector3 color = whiteTransfer(maxValue);
			glColor4f(color.r(), color.g(), color.b(), 1);

			glVertex3f(y, z, 0);
		}
	glEnd();

	glFlush();
	glutSwapBuffers();
}
예제 #3
0
파일: cav2.cpp 프로젝트: paul-thomson/cav2
int withinBounds(int width, int height, int depth, Vector3 loc) {
	if (loc.r() > 0 && loc.g() > 0 && loc.b() > 0 && loc.r() < width && loc.g() < height && loc.b() < depth) {
		return 1;
	} else {
		return 0;
	}
}
예제 #4
0
파일: cav2.cpp 프로젝트: paul-thomson/cav2
void redWhiteDraw() {
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glBegin(GL_POINTS);

	for(int y = 0; y < head->GetHeight(); y++)
		for(int z = 0; z < head->GetDepth(); z++) {

			for (int x = head->GetWidth(); x > 0 ; x--) {

				unsigned char val = head->Get(x, y, z);

				double normalisedVal = val/255.0;
				if (normalisedVal > 0.2) {
					Vector3 color = redToWhite(normalisedVal);
					glColor4f(color.r(), color.g(), color.b(), normalisedVal);

					glVertex3f(y, z, 0);
				}
			}
		}
	glEnd();

	glFlush();
	glutSwapBuffers();

}
예제 #5
0
파일: cav2.cpp 프로젝트: paul-thomson/cav2
void draw3DFrontToBack() {

	glEnable(GL_BLEND);
	glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glBegin(GL_POINTS);

	for(int c = 0; c < WIDTH; c++) {
		for(int r = 0; r < HEIGHT; r++) {
			double currentA = 0;
			Vector3 currentI = Vector3(0,0,0);
			Vector3 voxelLocation = rotationMatrix * Vector3(c, r, 0) + startingPosition;
			for (int i = 0; i < 256; i++) {
				if (withinBounds(head->GetWidth(), head->GetHeight(), 256, voxelLocation) ) {
					double val = trilinearInterpolate(voxelLocation.r(), voxelLocation.g(), voxelLocation.b()*(100.0/256.0));

					double normalisedVal = val/255.0;
					if (normalisedVal > 0.2) {
						Vector4 color = manualColoursAndOpacities(normalisedVal);
						Vector3 justColor = Vector3(color.r(), color.g(), color.b());

						currentI = currentI + justColor*color.a()*(1-currentA);
						currentA = color.a() + currentA*(1-color.a());
						if (currentA > 0.95) {
							break;
						}
					}
				}
				voxelLocation += directionVector;
			}
			glColor4f(currentI.r(), currentI.g(), currentI.b(), currentA);
			glVertex3f(c, r,0);
		}
	}
	glEnd();
	glFlush();
	glutSwapBuffers();
}
예제 #6
0
void Vector3Test::access() {
    Vector3 vec(1.0f, -2.0f, 5.0f);
    CORRADE_COMPARE(vec.x(), 1.0f);
    CORRADE_COMPARE(vec.r(), 1.0f);
    CORRADE_COMPARE(vec.y(), -2.0f);
    CORRADE_COMPARE(vec.g(), -2.0f);
    CORRADE_COMPARE(vec.z(), 5.0f);
    CORRADE_COMPARE(vec.b(), 5.0f);

    constexpr Vector3 cvec(1.0f, -2.0f, 5.0f);
    constexpr Float x = cvec.x();
    constexpr Float r = cvec.r();
    constexpr Float y = cvec.y();
    constexpr Float g = cvec.g();
    constexpr Float z = cvec.z();
    constexpr Float b = cvec.b();
    CORRADE_COMPARE(x, 1.0f);
    CORRADE_COMPARE(r, 1.0f);
    CORRADE_COMPARE(y, -2.0f);
    CORRADE_COMPARE(g, -2.0f);
    CORRADE_COMPARE(z, 5.0f);
    CORRADE_COMPARE(b, 5.0f);
}
예제 #7
0
void Draw() {
  
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glBegin(GL_POINTS);
	
  
  

    	switch(mode) {
    		case demo:
    			for(int y = 0; y < head->GetHeight(); y++)
  				for(int z = 0; z < head->GetDepth(); z++) {

				for (int x = 0; x < head->GetWidth(); x++) {
					
	        		unsigned char val = head->Get(x, y, z);
	        
			        // Change this value to see different contours
			        unsigned int threshold = modThresh;
					if (val > threshold) {

						Vector3 color = Vector3(val, val, val) / 255.0;
						glColor3f(color.r(), color.g(), color.b());

						switch(perp2d)
							{
								case front:
									glVertex3f(y, z, 0);
								break;

								case top:
									glVertex3f(x, z, 0);
								break;

								case side:
									glVertex3f(x, y, 0);
								break;
							}
						break;
					}
				}
				}
			break;

			case ray2d:
							
				for(int y = 0; y < head->GetHeight(); y++)
	  				for(int z = 0; z < head->GetDepth(); z++) {
		  				// Starting at front
		  				float r,g,b;
		  				float dist = 1;
		  				r = g = b = 0;
		  				bool draw = true;
						float total = 0;
						Vector3 divides = Vector3(0.2,0.28,0.37);
						for (int x = 0; x < head->GetWidth(); x++) {
							
			        		unsigned char val = head->Get(x, y, z);
			        		float alpha = (float)val/255.0f;
			        		// r is skin 55 - 70
			        		// b is dense skull 160

			        		// New alpha = Current Alpha + (1-Current Alpha) * Accumulated Alpha
					        if(alpha > divides[0] && alpha < divides[1])
					        {
					        	r = r + (1-r)*alpha;
					        }
					      		
					        if(alpha > divides[1] && alpha < divides[2])
					        {
					        	g = g + (1-g)*alpha;
					        }

					        if(alpha > divides[2] )
					        {

					        	b = b + (1-b)*alpha;
					        }
						if(alpha > 0.05)
					        	total = alpha + (1-alpha)*total;
					        
					        dist = (float)x/(float)head->GetWidth();
					        if(total > 0.99) break;	
							


						}
						// RAY TRACED
						//float dist = (float)x/(float)head->GetWidth();
						switch(colormode) {
							case red:
								glColor3f(r,0,0);
							break;

							case green:
								glColor3f(0,g,0);
							break;

							case blue:
								glColor3f(0,0,b);
							break;

							case all:
								glColor3f(r/1.75f,0,b);
							break;
						}
						
						glVertex3f(y,z,0);
					} 
				
			break;
    	
  }
  
	glEnd();
	
	glFlush();
	glutSwapBuffers();
  
}
예제 #8
0
파일: cav2.cpp 프로젝트: paul-thomson/cav2
void draw3DBackToFront() {

	glEnable(GL_BLEND);
	glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glBegin(GL_POINTS);

	for(int c = 0; c < WIDTH; c++) {
		for(int r = 0; r < HEIGHT; r++) {
			//
			Vector3 voxelLocation = rotationMatrix * Vector3(c, r, 0) + startingPosition + (directionVector * 256);
			for (int i = 0; i < 256; i++) {
				if (withinBounds(head->GetWidth(), head->GetHeight(), 256, voxelLocation) ) {
					unsigned char val = head->Get((int)voxelLocation.r(), (int)voxelLocation.g(), (int)voxelLocation.b()*(100.0/256.0));

					double normalisedVal = val/255.0;
					if (normalisedVal > 0.3) {
						Vector4 color = manualColoursAndOpacities(normalisedVal);
						glColor4f(color.r(), color.g(), color.b(), color.a());

						glVertex3f(c, r,0);
					}
				}
				voxelLocation -= directionVector;
			}

		}
	}
	glEnd();
	glFlush();
	glutSwapBuffers();
}