Merged with python3 update. Not yet tested extensively in python3
This commit is contained in:
commit
a76764e24b
|
@ -71,7 +71,7 @@ static glXMakeContextCurrentARBProc glXMakeContextCurrentARB = NULL;
|
|||
#define checkCudaErrors(ans) { gpuAssert((ans), __FILE__, __LINE__); }
|
||||
inline void gpuAssert(cudaError_t code, const char *file, int line, bool abort=true)
|
||||
{
|
||||
if (code != cudaSuccess)
|
||||
if (code != cudaSuccess)
|
||||
{
|
||||
fprintf(stderr,"GPUassert: %s %s %d\n", cudaGetErrorString(code), file, line);
|
||||
if (abort) exit(code);
|
||||
|
@ -214,7 +214,7 @@ std::vector<size_t> str_to_vec(std::string str) {
|
|||
str.erase(0, pos + delimiter.length());
|
||||
idx += 1;
|
||||
}
|
||||
longs.push_back(std::stoul(str));
|
||||
longs.push_back(std::stoul(str));
|
||||
return longs;
|
||||
}
|
||||
|
||||
|
@ -462,7 +462,7 @@ int main( int argc, char * argv[] )
|
|||
|
||||
// The texture we're going to render to
|
||||
GLuint renderedTexture;
|
||||
|
||||
|
||||
glGenTextures(1, &renderedTexture);
|
||||
|
||||
// "Bind" the newly created texture : all future texture functions will modify this texture
|
||||
|
@ -547,38 +547,40 @@ int main( int argc, char * argv[] )
|
|||
socket.bind ("tcp://127.0.0.1:5555");
|
||||
cudaGetDevice( &cudaDevice );
|
||||
//int g_cuda_device = 0;
|
||||
cudaSetDevice(cudaDevice);
|
||||
cudaSetDevice(cudaDevice);
|
||||
cudaGLSetGLDevice(cudaDevice);
|
||||
cudaGraphicsResource* resource;
|
||||
cudaGraphicsResource* resource;
|
||||
checkCudaErrors(cudaGraphicsGLRegisterImage(&resource, renderedTexture, GL_TEXTURE_2D, cudaGraphicsRegisterFlagsNone));
|
||||
std::cout << "CUDA DEVICE:" << cudaDevice << std::endl;
|
||||
int pose_idx = 0;
|
||||
zmq::message_t request;
|
||||
|
||||
socket.recv (&request);
|
||||
|
||||
//socket.recv (&request);
|
||||
// std::string request_str = std::string(static_cast<char*>(request.data()), request.size());
|
||||
// std::vector<size_t> new_idxs = str_to_vec(request_str);
|
||||
size_t img_size = request.size();
|
||||
typedef boost::multi_array<uint, 3> array_type;
|
||||
const int ndims=3;
|
||||
boost::multi_array<uint, 3> reordering{boost::extents[img_size / sizeof(uint)][1][1]};
|
||||
// boost::array<array_type::size_type,ndims> orig_dims = {{img_size / sizeof(uint),1,1}};
|
||||
boost::array<array_type::index,ndims> dims = {{1024, 2048, 3}};
|
||||
|
||||
//size_t img_size = request.size();
|
||||
//size_t img_size = 1024 * 2048 * 3;
|
||||
//typedef boost::multi_array<uint, 3> array_type;
|
||||
//const int ndims=3;
|
||||
//boost::multi_array<uint, 3> reordering{boost::extents[img_size / sizeof(uint)][1][1]};
|
||||
// boost::array<array_type::size_type,ndims> orig_dims = {{img_size / sizeof(uint),1,1}};
|
||||
//boost::array<array_type::index,ndims> dims = {{1024, 2048, 3}};
|
||||
|
||||
// multi_array reordering(orig_dims);
|
||||
|
||||
for (int i = 0; i < (img_size / sizeof(uint)) ; i++) {
|
||||
reordering[i][0][0] = ((uint*)request.data())[i];
|
||||
}
|
||||
|
||||
reordering.reshape(dims);
|
||||
//for (int i = 0; i < (img_size / sizeof(uint)) ; i++) {
|
||||
//reordering[i][0][0] = ((uint*)request.data())[i];
|
||||
// reordering[i][0][0] = 0;
|
||||
//}
|
||||
|
||||
//reordering.reshape(dims);
|
||||
|
||||
std::vector<uint> cubeMapCoordToPanoCoord;
|
||||
for(size_t ycoord = 0; ycoord < panoHeight; ycoord++){
|
||||
for(size_t xcoord = 0; xcoord < panoWidth; xcoord++){
|
||||
size_t ind = reordering[ycoord][xcoord][0];
|
||||
size_t corrx = reordering[ycoord][xcoord][1];
|
||||
size_t corry = reordering[ycoord][xcoord][2];
|
||||
size_t ind = 0;//reordering[ycoord][xcoord][0];
|
||||
size_t corrx = 0;//reordering[ycoord][xcoord][1];
|
||||
size_t corry = 0;//reordering[ycoord][xcoord][2];
|
||||
|
||||
cubeMapCoordToPanoCoord.push_back(
|
||||
ind * windowWidth * windowHeight +
|
||||
|
@ -588,9 +590,9 @@ int main( int argc, char * argv[] )
|
|||
}
|
||||
|
||||
uint *d_cubeMapCoordToPanoCoord = copyToGPU(&(cubeMapCoordToPanoCoord[0]), cubeMapCoordToPanoCoord.size());
|
||||
zmq::message_t reply0 (sizeof(float));
|
||||
socket.send(reply0);
|
||||
|
||||
//zmq::message_t reply0 (sizeof(float));
|
||||
//socket.send(reply0);
|
||||
|
||||
float *cubeMapGpuBuffer = allocateBufferOnGPU(windowHeight * windowWidth * 6);
|
||||
cudaMemset(cubeMapGpuBuffer, 0, windowHeight * windowWidth * 6 * sizeof(float));
|
||||
|
||||
|
@ -602,7 +604,7 @@ int main( int argc, char * argv[] )
|
|||
// Wait for next request from client
|
||||
socket.recv (&request);
|
||||
boost::timer t;
|
||||
|
||||
|
||||
std::string request_str = std::string(static_cast<char*>(request.data()), request.size());
|
||||
|
||||
glm::mat4 viewMat = str_to_mat(request_str);
|
||||
|
@ -636,11 +638,11 @@ int main( int argc, char * argv[] )
|
|||
//if (!dataBuffer_c) return false;
|
||||
|
||||
bool pano = False;
|
||||
|
||||
|
||||
if (pano)
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
for (int k = 0; k < 6; k ++ )
|
||||
{
|
||||
// Render to our framebuffer
|
||||
|
@ -814,7 +816,7 @@ int main( int argc, char * argv[] )
|
|||
|
||||
//glGetTextureImage(renderedTexture, 0, GL_RGB, GL_UNSIGNED_SHORT, nSize*sizeof(unsigned short), dataBuffer);
|
||||
// float* loc = dataBuffer + windowWidth*windowHeight * k;
|
||||
// glGetTextureImage(renderedTexture, 0, GL_BLUE, GL_FLOAT,
|
||||
// glGetTextureImage(renderedTexture, 0, GL_BLUE, GL_FLOAT,
|
||||
// (nSize/3)*sizeof(float), loc);
|
||||
|
||||
// Map the OpenGL texture buffer to CUDA memory space
|
||||
|
@ -831,7 +833,7 @@ int main( int argc, char * argv[] )
|
|||
|
||||
}
|
||||
checkCudaErrors(cudaStreamSynchronize(0));
|
||||
zmq::message_t reply (panoWidth*panoHeight*sizeof(float));
|
||||
zmq::message_t reply (panoWidth*panoHeight*sizeof(float));
|
||||
projectCubeMapToEquirectangular((float*)reply.data(), cubeMapGpuBuffer, d_cubeMapCoordToPanoCoord, cubeMapCoordToPanoCoord.size(), (size_t) nSize/3);
|
||||
|
||||
std::cout << "Render time: " << t.elapsed() << std::endl;
|
||||
|
@ -842,7 +844,7 @@ int main( int argc, char * argv[] )
|
|||
}
|
||||
else {
|
||||
//Pinhole mode
|
||||
|
||||
|
||||
// Render to our framebuffer
|
||||
|
||||
// Clear the screen
|
||||
|
@ -858,7 +860,7 @@ int main( int argc, char * argv[] )
|
|||
glm::mat4 ProjectionMatrix = glm::perspective(fov, 1.0f, 0.1f, 5000.0f); // near & far are not verified, but accuracy seems to work well
|
||||
glm::mat4 ViewMatrix = getView(viewMat, 2);
|
||||
glm::mat4 viewMatPose = glm::inverse(ViewMatrix);
|
||||
|
||||
|
||||
glm::mat4 ModelMatrix = glm::mat4(1.0);
|
||||
|
||||
glm::mat4 MVP = ProjectionMatrix * ViewMatrix * ModelMatrix;
|
||||
|
@ -928,16 +930,16 @@ int main( int argc, char * argv[] )
|
|||
glDisableVertexAttribArray(0);
|
||||
glDisableVertexAttribArray(1);
|
||||
glDisableVertexAttribArray(2);
|
||||
|
||||
|
||||
zmq::message_t reply (windowWidth*windowHeight*sizeof(float));
|
||||
float * reply_data_handle = (float*)reply.data();
|
||||
glGetTextureImage(renderedTexture, 0, GL_BLUE, GL_FLOAT, windowWidth * windowHeight *sizeof(float), reply_data_handle);
|
||||
|
||||
|
||||
std::cout << "Render time: " << t.elapsed() << std::endl;
|
||||
|
||||
|
||||
|
||||
|
||||
float tmp;
|
||||
|
||||
|
||||
for (int i = 0; i < windowHeight/2; i++)
|
||||
for (int j = 0; j < windowWidth; j++) {
|
||||
tmp = reply_data_handle[i * windowWidth + j];
|
||||
|
@ -948,7 +950,7 @@ int main( int argc, char * argv[] )
|
|||
|
||||
//free(dataBuffer);
|
||||
//free(dataBuffer_c);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -80,7 +80,7 @@ class PCRenderer:
|
|||
self.k = 5
|
||||
|
||||
self.showsz = 512
|
||||
|
||||
|
||||
#self.show = np.zeros((self.showsz,self.showsz * 2,3),dtype='uint8')
|
||||
#self.show_rgb = np.zeros((self.showsz,self.showsz * 2,3),dtype='uint8')
|
||||
|
||||
|
@ -214,16 +214,16 @@ class PCRenderer:
|
|||
s = utils.mat_to_str(p)
|
||||
|
||||
#with Profiler("Depth request round-trip"):
|
||||
socket_mist.send(s)
|
||||
socket_mist.send_string(s)
|
||||
message = socket_mist.recv()
|
||||
|
||||
#with Profiler("Read from framebuffer and make pano"):
|
||||
wo, ho = self.showsz * 4, self.showsz * 3
|
||||
|
||||
# Calculate height and width of output image, and size of each square face
|
||||
h = wo/3
|
||||
h = wo//3
|
||||
w = 2*h
|
||||
n = ho/3
|
||||
n = ho//3
|
||||
|
||||
|
||||
pano = False
|
||||
|
@ -254,11 +254,13 @@ class PCRenderer:
|
|||
opengl_arr.ctypes.data_as(ct.c_void_p)
|
||||
)
|
||||
|
||||
threads = [
|
||||
Process(target=_render_pc, args=(opengl_arr,)),
|
||||
Process(target=_render_depth, args=(opengl_arr,))]
|
||||
[t.start() for t in threads]
|
||||
[t.join() for t in threads]
|
||||
#threads = [
|
||||
# Process(target=_render_pc, args=(opengl_arr,)),
|
||||
# Process(target=_render_depth, args=(opengl_arr,))]
|
||||
#[t.start() for t in threads]
|
||||
#[t.join() for t in threads]
|
||||
_render_pc(opengl_arr)
|
||||
_render_depth(opengl_arr)
|
||||
|
||||
if self.compare_filler:
|
||||
show_unfilled[:, :, :] = show[:, :, :]
|
||||
|
@ -349,7 +351,7 @@ class PCRenderer:
|
|||
cv2.setMouseCallback('show3d',self._onmouse)
|
||||
if self.compare_filler:
|
||||
cv2.namedWindow('show3d unfilled')
|
||||
|
||||
|
||||
|
||||
def renderToScreen(self, pose, k_views=None):
|
||||
t0 = time.time()
|
||||
|
@ -370,11 +372,13 @@ class PCRenderer:
|
|||
|
||||
@staticmethod
|
||||
def sync_coords():
|
||||
"""
|
||||
with Profiler("Transform coords"):
|
||||
new_coords = np.getbuffer(coords.flatten().astype(np.uint32))
|
||||
socket_mist.send(new_coords)
|
||||
message = socket_mist.recv()
|
||||
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
def show_target(target_img):
|
||||
|
|
|
@ -62,6 +62,7 @@ class MJCFBaseEnv(gym.Env):
|
|||
else:
|
||||
self.physicsClientId = p.connect(p.DIRECT)
|
||||
p.configureDebugVisualizer(p.COV_ENABLE_GUI,0)
|
||||
p.configureDebugVisualizer(p.COV_ENABLE_KEYBOARD_SHORTCUTS, 0)
|
||||
|
||||
if self.scene is None:
|
||||
self.scene = self.create_single_player_scene()
|
||||
|
|
|
@ -19,7 +19,7 @@ import cv2
|
|||
|
||||
|
||||
DEFAULT_TIMESTEP = 1.0/(4 * 9)
|
||||
DEFAULT_FRAMESKIP = 5
|
||||
DEFAULT_FRAMESKIP = 4
|
||||
|
||||
|
||||
class SensorRobotEnv(MJCFBaseEnv):
|
||||
|
|
|
@ -2,6 +2,9 @@ from realenv.envs.env_modalities import CameraRobotEnv, SensorRobotEnv
|
|||
from realenv.core.physics.robot_locomotors import Humanoid, Ant, Husky
|
||||
import gym
|
||||
|
||||
HUMANOID_TIMESTEP = 1.0/(4 * 22)
|
||||
HUMANOID_FRAMESKIP = 4
|
||||
|
||||
class HumanoidEnv(gym.Env):
|
||||
metadata = {
|
||||
'render.modes' : ['human', 'rgb_array'],
|
||||
|
@ -16,11 +19,14 @@ class HumanoidEnv(gym.Env):
|
|||
|
||||
|
||||
class HumanoidCameraEnv(HumanoidEnv, CameraRobotEnv):
|
||||
def __init__(self, human=True, enable_sensors=False):
|
||||
def __init__(self, human=True, timestep=HUMANOID_TIMESTEP,
|
||||
frame_skip=HUMANOID_FRAMESKIP, enable_sensors=False):
|
||||
HumanoidEnv.__init__(self)
|
||||
CameraRobotEnv.__init__(self, human, enable_sensors=enable_sensors)
|
||||
CameraRobotEnv.__init__(self, human, timestep=timestep,
|
||||
frame_skip=frame_skip, enable_sensors=enable_sensors)
|
||||
|
||||
class HumanoidSensorEnv(HumanoidEnv, SensorRobotEnv):
|
||||
def __init__(self, human=True):
|
||||
def __init__(self, human=True, timestep=HUMANOID_TIMESTEP,
|
||||
frame_skip=HUMANOID_FRAMESKIP, enable_sensors=False):
|
||||
HumanoidEnv.__init__(self)
|
||||
SensorRobotEnv.__init__(self, human)
|
||||
|
|
Loading…
Reference in New Issue