Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into dev-sge
Browse files Browse the repository at this point in the history
  • Loading branch information
sguionni committed Oct 30, 2024
2 parents 1981d19 + 468df2c commit fa41d79
Show file tree
Hide file tree
Showing 110 changed files with 33,702 additions and 1,626 deletions.
10 changes: 5 additions & 5 deletions app/bench/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,19 @@ int main( int, char ** )
{
if ( p_key == SDL_SCANCODE_F1 )
{
renderer.addProxyMolecule( scene.addMolecule( "4hhb" ) );
renderer.addProxySystem( scene.addSystem( "4hhb" ) );
}
else if ( p_key == SDL_SCANCODE_F2 )
{
renderer.addProxyMolecule( scene.addMolecule( "1aga" ) );
renderer.addProxySystem( scene.addSystem( "1aga" ) );
}
else if ( p_key == SDL_SCANCODE_F3 )
{
renderer.addProxyMolecule( scene.addMolecule( "4v6x" ) );
renderer.addProxySystem( scene.addSystem( "4v6x" ) );
}
else if ( p_key == SDL_SCANCODE_F4 )
{
renderer.addProxyMolecule( scene.addMolecule( "3j3q" ) );
renderer.addProxySystem( scene.addSystem( "3j3q" ) );
}
else if ( p_key == SDL_SCANCODE_F5 )
{
Expand All @@ -105,7 +105,7 @@ int main( int, char ** )
{
try
{
renderer.addProxyMolecule( scene.addMolecule( p_filePath.string() ) );
renderer.addProxySystem( scene.addSystem( p_filePath.string() ) );
}
catch ( const std::exception & p_e )
{
Expand Down
70 changes: 35 additions & 35 deletions app/bench/src/scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,57 +31,57 @@ namespace VTX::Bench
_proxyLayoutColor.colors = &( _colorLayout.layout );
}

Renderer::Proxy::Molecule & Scene::addMolecule( const std::string & p_name )
Renderer::Proxy::System & Scene::addSystem( const std::string & p_name )
{
using namespace Util;

if ( p_name.find( '.' ) != std::string::npos )
{
_molecules.emplace_back( std::make_unique<Core::Struct::Molecule>( loadMolecule( p_name ) ) );
_systems.emplace_back( std::make_unique<Core::Struct::System>( loadSystem( p_name ) ) );
}
else
{
_molecules.emplace_back( std::make_unique<Core::Struct::Molecule>( downloadMolecule( p_name ) ) );
_systems.emplace_back( std::make_unique<Core::Struct::System>( downloadSystem( p_name ) ) );
}

//_molecules.back()->transform
// = Math::translate( _molecules.back()->transform, Math::randomVec3f() * 200.f - 100.f );
IO::Util::SecondaryStructure::computeStride( *_molecules.back() );
_proxyMolecules.emplace_back( _proxify( *_molecules.back() ) );
//_systems.back()->transform
// = Math::translate( _systems.back()->transform, Math::randomVec3f() * 200.f - 100.f );
IO::Util::SecondaryStructure::computeStride( *_systems.back() );
_proxySystems.emplace_back( _proxify( *_systems.back() ) );
_directions.emplace_back( Math::randomVec3f() * 2.f - 1.f );

return *_proxyMolecules.back();
return *_proxySystems.back();
};

void Scene::removeMolecule( const size_t p_index )
void Scene::removeSystem( const size_t p_index )
{
_proxyMolecules[ p_index ]->onRemove();
_molecules.erase( _molecules.begin() + p_index );
_proxyMolecules.erase( _proxyMolecules.begin() + p_index );
_proxySystems[ p_index ]->onRemove();
_systems.erase( _systems.begin() + p_index );
_proxySystems.erase( _proxySystems.begin() + p_index );
_directions.erase( _directions.begin() + p_index );
}

// TODO: remove renderer from here.
void Scene::removeAllMolecules( Renderer::Renderer * const p_renderer )
void Scene::removeAllSystems( Renderer::Renderer * const p_renderer )
{
std::vector<Renderer::Proxy::Molecule *> proxies;
for ( auto & proxy : _proxyMolecules )
std::vector<Renderer::Proxy::System *> proxies;
for ( auto & proxy : _proxySystems )
{
proxies.push_back( proxy.get() );
}

p_renderer->removeProxyMolecules( proxies );
p_renderer->removeProxySystems( proxies );

_molecules.clear();
_proxyMolecules.clear();
_systems.clear();
_proxySystems.clear();
_directions.clear();
}

std::unique_ptr<Renderer::Proxy::Molecule> Scene::_proxify( const Core::Struct::Molecule & p_molecule )
std::unique_ptr<Renderer::Proxy::System> Scene::_proxify( const Core::Struct::System & p_system )
{
const size_t sizeAtoms = p_molecule.trajectory.frames.front().size();
const std::vector<Core::ChemDB::Atom::SYMBOL> & symbols = p_molecule.atomSymbols;
const size_t sizeResidue = p_molecule.residueOriginalIds.size();
const size_t sizeAtoms = p_system.trajectory.frames.front().size();
const std::vector<Core::ChemDB::Atom::SYMBOL> & symbols = p_system.atomSymbols;
const size_t sizeResidue = p_system.residueOriginalIds.size();

std::vector<uchar> atomColors( sizeAtoms );
size_t i = 0;
Expand All @@ -108,27 +108,27 @@ namespace VTX::Bench
std::generate(
residueColors.begin(),
residueColors.end(),
[ & ] { return Core::ChemDB::Color::getColorIndex( p_molecule.residueSecondaryStructureTypes[ i++ ] ); }
[ & ] { return Core::ChemDB::Color::getColorIndex( p_system.residueSecondaryStructureTypes[ i++ ] ); }
);

const Core::Struct::Category & categoryPolymer
= p_molecule.getCategory( Core::ChemDB::Category::TYPE::POLYMER );
= p_system.getCategory( Core::ChemDB::Category::TYPE::POLYMER );
const Core::Struct::Category & categoryCarbohydrate
= p_molecule.getCategory( Core::ChemDB::Category::TYPE::CARBOHYDRATE );
= p_system.getCategory( Core::ChemDB::Category::TYPE::CARBOHYDRATE );

const std::vector<size_t> & polymerChainIds = categoryPolymer.getLinkedChains();
const std::vector<size_t> & carbohydrateChainIds = categoryCarbohydrate.getLinkedChains();

return std::make_unique<Renderer::Proxy::Molecule>( Renderer::Proxy::Molecule {
&p_molecule.transform,
&p_molecule.trajectory.frames.front(),
&p_molecule.bondPairAtomIndexes,
&p_molecule.atomNames,
reinterpret_cast<const std::vector<uchar> *>( &p_molecule.residueSecondaryStructureTypes ),
&p_molecule.residueFirstAtomIndexes,
&p_molecule.residueAtomCounts,
&p_molecule.chainFirstResidues,
&p_molecule.chainResidueCounts,
return std::make_unique<Renderer::Proxy::System>( Renderer::Proxy::System {
&p_system.transform,
&p_system.trajectory.frames.front(),
&p_system.bondPairAtomIndexes,
&p_system.atomNames,
reinterpret_cast<const std::vector<uchar> *>( &p_system.residueSecondaryStructureTypes ),
&p_system.residueFirstAtomIndexes,
&p_system.residueAtomCounts,
&p_system.chainFirstResidues,
&p_system.chainResidueCounts,
atomColors,
atomRadii,
atomIds,
Expand Down
36 changes: 18 additions & 18 deletions app/bench/src/scene.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

#include "camera.hpp"
#include <core/struct/color_layout.hpp>
#include <core/struct/molecule.hpp>
#include <core/struct/system.hpp>
#include <renderer/proxy/camera.hpp>
#include <renderer/proxy/color_layout.hpp>
#include <renderer/proxy/molecule.hpp>
#include <renderer/proxy/system.hpp>

namespace VTX::Renderer
{
Expand All @@ -24,11 +24,11 @@ namespace VTX::Bench
inline Camera & getCamera() { return _camera; }
inline Renderer::Proxy::Camera & getProxyCamera() { return _proxyCamera; }

Renderer::Proxy::Molecule & addMolecule( const std::string & p_name );
void removeMolecule( const size_t p_index );
Renderer::Proxy::System & addSystem( const std::string & p_name );
void removeSystem( const size_t p_index );

// TODO: remove renderer from here.
void removeAllMolecules( Renderer::Renderer * const p_renderer );
void removeAllSystems( Renderer::Renderer * const p_renderer );

inline void update( const float p_deltaTime )
{
Expand All @@ -40,22 +40,22 @@ namespace VTX::Bench
int i = 0;
// static uint currentFrame = 0;

for ( auto & molecule : _molecules )
for ( auto & system : _systems )
{
molecule->transform = Util::Math::rotate( molecule->transform, p_deltaTime, _directions[ i ] );
system->transform = Util::Math::rotate( system->transform, p_deltaTime, _directions[ i ] );

//_proxyMolecules[ i ]->atomPositions
// = &molecule->trajectory.frames[ currentFrame++ % molecule->trajectory.frames.size() ];
//_proxyMolecules[ i ]->onAtomPositions();
//_proxySystems[ i ]->atomPositions
// = &system->trajectory.frames[ currentFrame++ % system->trajectory.frames.size() ];
//_proxySystems[ i ]->onAtomPositions();

_proxyMolecules[ i++ ]->onTransform();
_proxySystems[ i++ ]->onTransform();
}
}

inline const std::vector<std::unique_ptr<Core::Struct::Molecule>> & getMolecules() const { return _molecules; }
inline const std::vector<std::unique_ptr<Renderer::Proxy::Molecule>> & getProxiesMolecules() const
inline const std::vector<std::unique_ptr<Core::Struct::System>> & getSystems() const { return _systems; }
inline const std::vector<std::unique_ptr<Renderer::Proxy::System>> & getProxiesSystems() const
{
return _proxyMolecules;
return _proxySystems;
}
inline const Core::Struct::ColorLayout & getColorLayout() const { return _colorLayout; }
inline void setColorLayout( const Core::Struct::ColorLayout & p_colorLayout )
Expand All @@ -71,14 +71,14 @@ namespace VTX::Bench
Camera _camera;
Renderer::Proxy::Camera _proxyCamera;

std::vector<std::unique_ptr<Core::Struct::Molecule>> _molecules;
std::vector<std::unique_ptr<Renderer::Proxy::Molecule>> _proxyMolecules;
std::vector<Vec3f> _directions;
std::vector<std::unique_ptr<Core::Struct::System>> _systems;
std::vector<std::unique_ptr<Renderer::Proxy::System>> _proxySystems;
std::vector<Vec3f> _directions;

Core::Struct::ColorLayout _colorLayout;
Renderer::Proxy::ColorLayout _proxyLayoutColor;

std::unique_ptr<Renderer::Proxy::Molecule> _proxify( const Core::Struct::Molecule & p_molecule );
std::unique_ptr<Renderer::Proxy::System> _proxify( const Core::Struct::System & p_system );
};

} // namespace VTX::Bench
Expand Down
26 changes: 13 additions & 13 deletions app/bench/src/user_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -408,19 +408,19 @@ namespace VTX::Bench
ImGui::SameLine();
if ( ImGui::Button( "X all" ) )
{
p_scene->removeAllMolecules( p_renderer );
p_scene->removeAllSystems( p_renderer );
}

size_t idMolecule = 0;
size_t idSystem = 0;
int toDelete = -1;

for ( auto & proxyMolecule : p_scene->getProxiesMolecules() )
for ( auto & proxySystem : p_scene->getProxiesSystems() )
{
// Display transform.
if ( ImGui::TreeNode( fmt::format( "Molecule ({})", idMolecule ).c_str() ) )
if ( ImGui::TreeNode( fmt::format( "System ({})", idSystem ).c_str() ) )
{
// Display transform.
Mat4f transform = *proxyMolecule->transform;
Mat4f transform = *proxySystem->transform;
ImGui::Text( "Transform" );
ImGui::InputFloat4( "", &transform[ 0 ][ 0 ] );
ImGui::InputFloat4( "", &transform[ 1 ][ 0 ] );
Expand All @@ -429,43 +429,43 @@ namespace VTX::Bench

if ( ImGui::Button( "S" ) )
{
proxyMolecule->onSelect( true );
proxySystem->onSelect( true );
}
ImGui::SameLine();
if ( ImGui::Button( "US" ) )
{
proxyMolecule->onSelect( false );
proxySystem->onSelect( false );
}
ImGui::SameLine();
if ( ImGui::Button( "UV" ) )
{
proxyMolecule->onVisible( false );
proxySystem->onVisible( false );
}
ImGui::SameLine();
if ( ImGui::Button( "V" ) )
{
proxyMolecule->onVisible( true );
proxySystem->onVisible( true );
}
ImGui::SameLine();
if ( ImGui::Button( "Rep" ) )
{
proxyMolecule->onRepresentation( rand() % 3 );
proxySystem->onRepresentation( rand() % 3 );
}
ImGui::SameLine();
if ( ImGui::Button( "X" ) )
{
// Don't remove from proxy directly, remove from scene before (after loop).
toDelete = int( idMolecule );
toDelete = int( idSystem );
}

ImGui::TreePop();
}
idMolecule++;
idSystem++;
}

if ( toDelete != -1 )
{
p_scene->removeMolecule( toDelete );
p_scene->removeSystem( toDelete );
}
}
ImGui::End();
Expand Down
24 changes: 12 additions & 12 deletions app/bench/src/util.cpp
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
#include "util.hpp"
#include <io/reader/molecule.hpp>
#include <io/reader/system.hpp>
#include <util/network.hpp>

namespace VTX::Bench
{
Core::Struct::Molecule loadMolecule( const FilePath & p_filename )
Core::Struct::System loadSystem( const FilePath & p_filename )
{
IO::Reader::Molecule reader;
Core::Struct::Molecule molecule;
IO::Reader::System reader;
Core::Struct::System system;

reader.readFile( VTX::Util::Filesystem::getExecutableDir() / "data" / p_filename, molecule );
reader.readFile( VTX::Util::Filesystem::getExecutableDir() / "data" / p_filename, system );

return molecule;
return system;
}

Core::Struct::Molecule downloadMolecule( const std::string & p_pdb )
Core::Struct::System downloadSystem( const std::string & p_pdb )
{
IO::Reader::Molecule reader;
Core::Struct::Molecule molecule;
std::string data;
IO::Reader::System reader;
Core::Struct::System system;
std::string data;

VTX::Util::Network::httpRequestGet( "https://files.rcsb.org/download/" + p_pdb + ".pdb", &data );
reader.readBuffer( data, p_pdb + ".pdb", molecule );
reader.readBuffer( data, p_pdb + ".pdb", system );

return molecule;
return system;
}

} // namespace VTX::Bench
6 changes: 3 additions & 3 deletions app/bench/src/util.hpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#ifndef __VTX_BENCH_UTIL__
#define __VTX_BENCH_UTIL__

#include <core/struct/molecule.hpp>
#include <core/struct/system.hpp>
#include <util/types.hpp>

namespace VTX::Bench
{
Core::Struct::Molecule loadMolecule( const FilePath & p_filename );
Core::Struct::Molecule downloadMolecule( const std::string & p_pdb );
Core::Struct::System loadSystem( const FilePath & p_filename );
Core::Struct::System downloadSystem( const std::string & p_pdb );

// Skybox tests.
/*
Expand Down
3 changes: 3 additions & 0 deletions dev/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ find_package(Qt6 COMPONENTS OpenGLWidgets REQUIRED)
find_package(Eigen3 CONFIG REQUIRED)
find_package(fmt CONFIG REQUIRED)
find_package(re2 CONFIG REQUIRED)
find_package(Boost CONFIG REQUIRED) # Needed for multiprocessing on pdb database test
find_package(LibArchive REQUIRED)


# Util.
include("${DIR_LIBS}/util/cmake/library.cmake")
Expand Down
2 changes: 2 additions & 0 deletions dev/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ def requirements(self):
self.requires("gromacs/2024.0")
self.requires("fmt/10.2.1")
self.requires("re2/20231101")
self.requires("libarchive/3.7.6")
self.requires("boost/1.86.0")

def config_options(self):
# Package options.
Expand Down
Loading

0 comments on commit fa41d79

Please sign in to comment.