tMore progress on implementing raytracer into DEM module - sphere - GPU-based 3D discrete element method algorithm with optional fluid coupling
(HTM) git clone git://src.adamsgaard.dk/sphere
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) LICENSE
---
(DIR) commit 6c15212f6bc2ff22a3331b26bc6c1ab842132944
(DIR) parent 472d81e85b29f2ad92df2031ff56a9ac2cdf8699
(HTM) Author: Anders Damsgaard <adc@geo.au.dk>
Date: Sun, 4 Nov 2012 13:05:28 +0100
More progress on implementing raytracer into DEM module
Diffstat:
M src/Makefile | 14 +++++++++-----
M src/constants.cuh | 14 ++++++++++++--
M src/datatypes.h | 8 ++++++++
M src/file_io.cpp | 23 +++++++++++++++++++++++
M src/sphere.h | 45 ++++++++++++++++++++++---------
5 files changed, 84 insertions(+), 20 deletions(-)
---
(DIR) diff --git a/src/Makefile b/src/Makefile
t@@ -34,7 +34,7 @@ DATE=`date +'%Y.%m.%d-%H:%M:%S'`
BACKUPNAME=sphere.$(DATE).tar.gz
CCFILES=main.cpp file_io.cpp sphere.cpp
-CUFILES=device.cu utility.cu
+CUFILES=device.cu utility.cu raytracer.cu
CCOBJECTS=$(CCFILES:.cpp=.o)
CUOBJECTS=$(CUFILES:.cu=.o)
OBJECTS=$(CCOBJECTS) $(CUOBJECTS)
t@@ -67,10 +67,11 @@ LDFLAGS+=-L$(CUDA_INSTALL_PATH)/lib
LDFLAGS+=-L$(SDKPATH)/../../shared/lib -L$(SDKPATH)/../lib
LDFLAGS+=-lcutil_x86_64 -lcuda -lcudart
-all: $(CCFILES) $(CUFILES) $(EXECUTABLE) raytracer
+#all: $(CCFILES) $(CUFILES) $(EXECUTABLE) raytracer
+all: $(CCFILES) $(CUFILES) $(EXECUTABLE)
-raytracer:
- $(MAKE) -C ../raytracer/
+#raytracer:
+# $(MAKE) -C ../raytracer/
$(EXECUTABLE): $(OBJECTS)
$(LINKER) $(OBJECTS) $(LDFLAGS) -o $@
t@@ -90,6 +91,9 @@ main.o: main.cpp $(DEPS)
sphere.o: sphere.cpp $(DEPS)
$(CC) $(CCFLAGS) $(INCLUDES) -c $< -o $@
+raytracer.o: raytracer.cu $(DEPS)
+ $(NVCC) $(NVCCFLAGS) $(INCLUDES) -c $< -o $@
+
../sphere_status: sphere_status.cpp
$(CC) $(CCFLAGS) sphere_status.cpp -o ../sphere_status
t@@ -103,7 +107,7 @@ backup:
clean:
$(RM) $(OBJECTS)
$(RM) ../sphere_*
- $(MAKE) -C ../raytracer clean
+# $(MAKE) -C ../raytracer clean
clear:
# Remove all output data and images
(DIR) diff --git a/src/constants.cuh b/src/constants.cuh
t@@ -14,7 +14,17 @@ __constant__ int devC_nc; // Max. number of contacts a particle can have
__constant__ Float devC_dt; // Computational time step length
// Device constant memory structures
-__constant__ Params devC_params;
-__constant__ Grid devC_grid;
+__constant__ Params devC_params;
+__constant__ Grid devC_grid;
+// Raytracer constants
+__constant__ float3 devC_u;
+__constant__ float3 devC_v;
+__constant__ float3 devC_w;
+__constant__ float3 devC_eye;
+__constant__ float4 devC_imgplane;
+__constant__ float devC_d;
+__constant__ float3 devC_light;
+__constant__ unsigned int devC_pixels;
+
#endif
(DIR) diff --git a/src/datatypes.h b/src/datatypes.h
t@@ -97,4 +97,12 @@ struct Walls {
Float4* mvfd; // Wall mass, velocity, force and dev. stress
};
+// Image structure
+struct rgba {
+ unsigned char r; // Red
+ unsigned char g; // Green
+ unsigned char b; // Blue
+ unsigned char a; // Alpha
+};
+
#endif
(DIR) diff --git a/src/file_io.cpp b/src/file_io.cpp
t@@ -345,3 +345,26 @@ void DEM::writebin(const char *target)
}
}
+// Write image structure to PPM file
+void DEM::writePPM(const char *target)
+{
+ // Open output file
+ std::ofstream ofs(target);
+ if (!ofs) {
+ std::cerr << "could create output PPM file '"
+ << target << std::endl;
+ exit(1); // Return unsuccessful exit status
+ }
+
+ // Write PPM header
+ ofs << "P6 " << width << " " << height << " 255\n";
+
+ // Write pixel array to ppm image file
+ for (unsigned int i=0; i<height*width; ++i)
+ ofs << img[i].r << img[i].g << img[i].b;
+
+ // Close file if it is still open
+ if (ofs.is_open())
+ ofs.close();
+}
+
(DIR) diff --git a/src/sphere.h b/src/sphere.h
t@@ -28,28 +28,27 @@ class DEM {
// HOST STRUCTURES
// Structure containing individual particle kinematics
Kinematics k; // host
- //Kinematics *dev_k; // device
// Structure containing energy values
- Energies e; // host
- //Energies *dev_e; // device
+ Energies e;
// Structure of global parameters
- Params params; // host
+ Params params;
// Structure containing spatial parameters
- Grid grid; // host
-
- // Structure containing sorting arrays
- //Sorting *dev_sort; // device
+ Grid grid;
// Structure of temporal parameters
- Time time; // host
- //Time *dev_time; // device
+ Time time;
// Structure of wall parameters
- Walls walls; // host
- //Walls *dev_walls; // device
+ Walls walls;
+
+ // Image structure (red, green, blue, alpa)
+ rgba* img;
+ unsigned int width;
+ unsigned int height;
+
// DEVICE ARRAYS
Float4 *dev_x;
t@@ -81,28 +80,42 @@ class DEM {
Float4 *dev_walls_mvfd; // Mass, velocity, force, dev. stress
Float *dev_walls_force_partial; // Pre-sum per wall
Float *dev_walls_force_pp; // Force per particle per wall
+ unsigned char *dev_img;
+ float4 *dev_ray_origo; // Ray data always single precision
+ float4 *dev_ray_direction;
+
// GPU initialization, must be called before startTime()
void initializeGPU(void);
// Copy all constant data to constant device memory
void transferToConstantDeviceMemory(void);
+ void rt_transferToConstantDeviceMemory(void);
// Check values stored in constant device memory
void checkConstantMemory(void);
+ // Initialize camera values and transfer to constant device memory
+ void cameraInit(float3 eye, float3 lookat,
+ float imgw, float hw_ratio,
+ float focalLength);
+
// Allocate global device memory to hold data
void allocateGlobalDeviceMemory(void);
+ void rt_allocateGlobalDeviceMemory(void);
// Free dynamically allocated global device memory
void freeGlobalDeviceMemory(void);
+ void rt_freeGlobalDeviceMemory(void);
// Copy non-constant data to global GPU memory
void transferToGlobalDeviceMemory(void);
// Copy non-constant data from global GPU memory to host RAM
void transferFromGlobalDeviceMemory(void);
+ void rt_transferFromGlobalDeviceMemory(void);
+
// Values and functions accessible from the outside
public:
t@@ -137,7 +150,13 @@ class DEM {
const Float3 lookat,
const Float3 eye,
const Float focalLength = 1.0,
- const int method = 1);
+ const int method = 1,
+ const Float maxval = 1.0e3,
+ const unsigned int img_width = 800,
+ const unsigned int img_height = 800);
+
+ // Write image data to PPM file
+ void writePPM(const char *target);
};