bool ResponseEstimator::operator() (const FODSegResult& in) { Image::Nav::set_pos (dwi, in.get_vox(), 0, 3); // Load the raw DWI data Math::Vector<float> dwi_data (shared.dwis.size()); for (size_t n = 0; n < shared.dwis.size(); n++) { dwi[3] = shared.dwis[n]; dwi_data[n] = dwi.value(); if (dwi_data[n] < 0.0) dwi_data[n] = 0.0; } // Rotate the diffusion gradient orientations into a new reference frame, // where the Z direction is defined by the FOD peak Math::Matrix<float> R = gen_rotation_matrix (in.get_peak_dir()); Math::Matrix<float> rotated_grad (shared.grad.rows(), 4); Math::Vector<float> vec (3), rot (3); for (size_t row = 0; row != shared.grad.rows(); ++row) { vec[0] = shared.grad (row, 0); vec[1] = shared.grad (row, 1); vec[2] = shared.grad (row, 2); Math::mult (rot, R, vec); rotated_grad (row, 0) = rot[0]; rotated_grad (row, 1) = rot[1]; rotated_grad (row, 2) = rot[2]; rotated_grad (row, 3) = shared.grad (row, 3); } // Convert directions from Euclidean space to azimuth/elevation pairs Math::Matrix<float> dirs = DWI::gen_direction_matrix (rotated_grad, shared.dwis); try { // Convert the DWI signal to spherical harmonics in the new reference frame Math::SH::Transform<float> transform (dirs, lmax); Math::Vector<float> SH; transform.A2SH (SH, dwi_data); // Extract the m=0 components and save Math::Vector<float> response (lmax/2+1); for (size_t l = 0; l <= lmax; l += 2) response[l/2] = SH[Math::SH::index (l, 0)]; std::lock_guard<std::mutex> lock (*mutex); output += response; } catch (...) { WARN ("Invalid rotated-gradient SH transformation in voxel " + str(in.get_vox())); } return true; }
static void do_render(bool alt_color) { glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(0.0f, 0.0f, -2.0f); glRotatef(g_angle_x, 1.0f, 0.0f, 0.0f); glRotatef(g_angle_y, 0.0f, 1.0f, 0.0f); if (!alt_color) glColor3f(0.3f, 0.4f, 0.7f); else glColor3f(0.2f, 0.3f, 0.5f); for (World::sphere_array_t::const_iterator it = g_world->spheres.begin(); it != g_world->spheres.end(); ++it) { Sphere *sp = *it; glPushMatrix(); glTranslatef(sp->origin.x, sp->origin.y, sp->origin.z); glutSolidSphere(sp->r - sphere_r_bias, 20, 20); glPopMatrix(); } for (World::plane_array_t::const_iterator it = g_world->planes.begin(); it != g_world->planes.end(); ++it) { Plane *pl = *it; glPushMatrix(); glm::vec3 offset = -pl->n * pl->d; glTranslatef(offset.x, offset.y, offset.z); glm::mat4 rot_matrix = gen_rotation_matrix(pl->n, glm::vec3(0.f, 1.f, 0.f)); glMultMatrixf(glm::value_ptr(rot_matrix)); g_plane_surface->draw(); glPopMatrix(); } if (!alt_color) glColor3f(0.4f, 0.7f, 0.8f); else glColor3f(0.75f, 0.3f, 0.25f); g_cloth->draw(); }