diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..4c6ecac --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +python/notebooks/* +**/build +**/data +**/node_modules diff --git a/.gitignore b/.gitignore index b4466bd..3a9f6fb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +bin/* +build*/* .ipynb_checkpoints/ *.py[cod] @@ -7,8 +9,8 @@ **/video.mp4 # notebooks -notebooks/HelloWorld.jpg -notebooks/data/bonsai/*.nhdr -notebooks/data/bonsai/*.raw -notebooks/data/pancreas/*.raw -notebooks/data/OpenSlide/*.tiff +python/notebooks/HelloWorld.jpg +python/notebooks/data/bonsai/*.nhdr +python/notebooks/data/bonsai/*.raw +python/notebooks/data/pancreas/*.raw +python/notebooks/data/OpenSlide/*.tiff diff --git a/3rdparty/LICENSE.ExposureRenderer b/3rdparty/LICENSE.ExposureRenderer new file mode 100644 index 0000000..8939c8a --- /dev/null +++ b/3rdparty/LICENSE.ExposureRenderer @@ -0,0 +1,20 @@ +Copyright (c) 2011, T. Kroes +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the +following conditions are met: + +- Redistributions of source code must retain the above copyright notice, this list of conditions and the following +disclaimer. +- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following +disclaimer in the documentation and/or other materials provided with the distribution. +- Neither the name of the TU Delft nor the names of its contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/3rdparty/LICENSE.OpenSSL b/3rdparty/LICENSE.OpenSSL new file mode 100644 index 0000000..b8cc044 --- /dev/null +++ b/3rdparty/LICENSE.OpenSSL @@ -0,0 +1,177 @@ + + Apache License + Version 2.0, January 2004 + https://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS \ No newline at end of file diff --git a/3rdparty/LICENSE.gRPC b/3rdparty/LICENSE.gRPC new file mode 100644 index 0000000..ec78c94 --- /dev/null +++ b/3rdparty/LICENSE.gRPC @@ -0,0 +1,610 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +----------------------------------------------------------- + +BSD 3-Clause License + +Copyright 2016, Google Inc. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, +this list of conditions and the following disclaimer in the documentation +and/or other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its +contributors may be used to endorse or promote products derived from this +software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF +THE POSSIBILITY OF SUCH DAMAGE. + +----------------------------------------------------------- + +Mozilla Public License Version 2.0 +================================== + +1. Definitions +-------------- + +1.1. "Contributor" + means each individual or legal entity that creates, contributes to + the creation of, or owns Covered Software. + +1.2. "Contributor Version" + means the combination of the Contributions of others (if any) used + by a Contributor and that particular Contributor's Contribution. + +1.3. "Contribution" + means Covered Software of a particular Contributor. + +1.4. "Covered Software" + means Source Code Form to which the initial Contributor has attached + the notice in Exhibit A, the Executable Form of such Source Code + Form, and Modifications of such Source Code Form, in each case + including portions thereof. + +1.5. "Incompatible With Secondary Licenses" + means + + (a) that the initial Contributor has attached the notice described + in Exhibit B to the Covered Software; or + + (b) that the Covered Software was made available under the terms of + version 1.1 or earlier of the License, but not also under the + terms of a Secondary License. + +1.6. "Executable Form" + means any form of the work other than Source Code Form. + +1.7. "Larger Work" + means a work that combines Covered Software with other material, in + a separate file or files, that is not Covered Software. + +1.8. "License" + means this document. + +1.9. "Licensable" + means having the right to grant, to the maximum extent possible, + whether at the time of the initial grant or subsequently, any and + all of the rights conveyed by this License. + +1.10. "Modifications" + means any of the following: + + (a) any file in Source Code Form that results from an addition to, + deletion from, or modification of the contents of Covered + Software; or + + (b) any new file in Source Code Form that contains any Covered + Software. + +1.11. "Patent Claims" of a Contributor + means any patent claim(s), including without limitation, method, + process, and apparatus claims, in any patent Licensable by such + Contributor that would be infringed, but for the grant of the + License, by the making, using, selling, offering for sale, having + made, import, or transfer of either its Contributions or its + Contributor Version. + +1.12. "Secondary License" + means either the GNU General Public License, Version 2.0, the GNU + Lesser General Public License, Version 2.1, the GNU Affero General + Public License, Version 3.0, or any later versions of those + licenses. + +1.13. "Source Code Form" + means the form of the work preferred for making modifications. + +1.14. "You" (or "Your") + means an individual or a legal entity exercising rights under this + License. For legal entities, "You" includes any entity that + controls, is controlled by, or is under common control with You. For + purposes of this definition, "control" means (a) the power, direct + or indirect, to cause the direction or management of such entity, + whether by contract or otherwise, or (b) ownership of more than + fifty percent (50%) of the outstanding shares or beneficial + ownership of such entity. + +2. License Grants and Conditions +-------------------------------- + +2.1. Grants + +Each Contributor hereby grants You a world-wide, royalty-free, +non-exclusive license: + +(a) under intellectual property rights (other than patent or trademark) + Licensable by such Contributor to use, reproduce, make available, + modify, display, perform, distribute, and otherwise exploit its + Contributions, either on an unmodified basis, with Modifications, or + as part of a Larger Work; and + +(b) under Patent Claims of such Contributor to make, use, sell, offer + for sale, have made, import, and otherwise transfer either its + Contributions or its Contributor Version. + +2.2. Effective Date + +The licenses granted in Section 2.1 with respect to any Contribution +become effective for each Contribution on the date the Contributor first +distributes such Contribution. + +2.3. Limitations on Grant Scope + +The licenses granted in this Section 2 are the only rights granted under +this License. No additional rights or licenses will be implied from the +distribution or licensing of Covered Software under this License. +Notwithstanding Section 2.1(b) above, no patent license is granted by a +Contributor: + +(a) for any code that a Contributor has removed from Covered Software; + or + +(b) for infringements caused by: (i) Your and any other third party's + modifications of Covered Software, or (ii) the combination of its + Contributions with other software (except as part of its Contributor + Version); or + +(c) under Patent Claims infringed by Covered Software in the absence of + its Contributions. + +This License does not grant any rights in the trademarks, service marks, +or logos of any Contributor (except as may be necessary to comply with +the notice requirements in Section 3.4). + +2.4. Subsequent Licenses + +No Contributor makes additional grants as a result of Your choice to +distribute the Covered Software under a subsequent version of this +License (see Section 10.2) or under the terms of a Secondary License (if +permitted under the terms of Section 3.3). + +2.5. Representation + +Each Contributor represents that the Contributor believes its +Contributions are its original creation(s) or it has sufficient rights +to grant the rights to its Contributions conveyed by this License. + +2.6. Fair Use + +This License is not intended to limit any rights You have under +applicable copyright doctrines of fair use, fair dealing, or other +equivalents. + +2.7. Conditions + +Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted +in Section 2.1. + +3. Responsibilities +------------------- + +3.1. Distribution of Source Form + +All distribution of Covered Software in Source Code Form, including any +Modifications that You create or to which You contribute, must be under +the terms of this License. You must inform recipients that the Source +Code Form of the Covered Software is governed by the terms of this +License, and how they can obtain a copy of this License. You may not +attempt to alter or restrict the recipients' rights in the Source Code +Form. + +3.2. Distribution of Executable Form + +If You distribute Covered Software in Executable Form then: + +(a) such Covered Software must also be made available in Source Code + Form, as described in Section 3.1, and You must inform recipients of + the Executable Form how they can obtain a copy of such Source Code + Form by reasonable means in a timely manner, at a charge no more + than the cost of distribution to the recipient; and + +(b) You may distribute such Executable Form under the terms of this + License, or sublicense it under different terms, provided that the + license for the Executable Form does not attempt to limit or alter + the recipients' rights in the Source Code Form under this License. + +3.3. Distribution of a Larger Work + +You may create and distribute a Larger Work under terms of Your choice, +provided that You also comply with the requirements of this License for +the Covered Software. If the Larger Work is a combination of Covered +Software with a work governed by one or more Secondary Licenses, and the +Covered Software is not Incompatible With Secondary Licenses, this +License permits You to additionally distribute such Covered Software +under the terms of such Secondary License(s), so that the recipient of +the Larger Work may, at their option, further distribute the Covered +Software under the terms of either this License or such Secondary +License(s). + +3.4. Notices + +You may not remove or alter the substance of any license notices +(including copyright notices, patent notices, disclaimers of warranty, +or limitations of liability) contained within the Source Code Form of +the Covered Software, except that You may alter any license notices to +the extent required to remedy known factual inaccuracies. + +3.5. Application of Additional Terms + +You may choose to offer, and to charge a fee for, warranty, support, +indemnity or liability obligations to one or more recipients of Covered +Software. However, You may do so only on Your own behalf, and not on +behalf of any Contributor. You must make it absolutely clear that any +such warranty, support, indemnity, or liability obligation is offered by +You alone, and You hereby agree to indemnify every Contributor for any +liability incurred by such Contributor as a result of warranty, support, +indemnity or liability terms You offer. You may include additional +disclaimers of warranty and limitations of liability specific to any +jurisdiction. + +4. Inability to Comply Due to Statute or Regulation +--------------------------------------------------- + +If it is impossible for You to comply with any of the terms of this +License with respect to some or all of the Covered Software due to +statute, judicial order, or regulation then You must: (a) comply with +the terms of this License to the maximum extent possible; and (b) +describe the limitations and the code they affect. Such description must +be placed in a text file included with all distributions of the Covered +Software under this License. Except to the extent prohibited by statute +or regulation, such description must be sufficiently detailed for a +recipient of ordinary skill to be able to understand it. + +5. Termination +-------------- + +5.1. The rights granted under this License will terminate automatically +if You fail to comply with any of its terms. However, if You become +compliant, then the rights granted under this License from a particular +Contributor are reinstated (a) provisionally, unless and until such +Contributor explicitly and finally terminates Your grants, and (b) on an +ongoing basis, if such Contributor fails to notify You of the +non-compliance by some reasonable means prior to 60 days after You have +come back into compliance. Moreover, Your grants from a particular +Contributor are reinstated on an ongoing basis if such Contributor +notifies You of the non-compliance by some reasonable means, this is the +first time You have received notice of non-compliance with this License +from such Contributor, and You become compliant prior to 30 days after +Your receipt of the notice. + +5.2. If You initiate litigation against any entity by asserting a patent +infringement claim (excluding declaratory judgment actions, +counter-claims, and cross-claims) alleging that a Contributor Version +directly or indirectly infringes any patent, then the rights granted to +You by any and all Contributors for the Covered Software under Section +2.1 of this License shall terminate. + +5.3. In the event of termination under Sections 5.1 or 5.2 above, all +end user license agreements (excluding distributors and resellers) which +have been validly granted by You or Your distributors under this License +prior to termination shall survive termination. + +************************************************************************ +* * +* 6. Disclaimer of Warranty * +* ------------------------- * +* * +* Covered Software is provided under this License on an "as is" * +* basis, without warranty of any kind, either expressed, implied, or * +* statutory, including, without limitation, warranties that the * +* Covered Software is free of defects, merchantable, fit for a * +* particular purpose or non-infringing. The entire risk as to the * +* quality and performance of the Covered Software is with You. * +* Should any Covered Software prove defective in any respect, You * +* (not any Contributor) assume the cost of any necessary servicing, * +* repair, or correction. This disclaimer of warranty constitutes an * +* essential part of this License. No use of any Covered Software is * +* authorized under this License except under this disclaimer. * +* * +************************************************************************ + +************************************************************************ +* * +* 7. Limitation of Liability * +* -------------------------- * +* * +* Under no circumstances and under no legal theory, whether tort * +* (including negligence), contract, or otherwise, shall any * +* Contributor, or anyone who distributes Covered Software as * +* permitted above, be liable to You for any direct, indirect, * +* special, incidental, or consequential damages of any character * +* including, without limitation, damages for lost profits, loss of * +* goodwill, work stoppage, computer failure or malfunction, or any * +* and all other commercial damages or losses, even if such party * +* shall have been informed of the possibility of such damages. This * +* limitation of liability shall not apply to liability for death or * +* personal injury resulting from such party's negligence to the * +* extent applicable law prohibits such limitation. Some * +* jurisdictions do not allow the exclusion or limitation of * +* incidental or consequential damages, so this exclusion and * +* limitation may not apply to You. * +* * +************************************************************************ + +8. Litigation +------------- + +Any litigation relating to this License may be brought only in the +courts of a jurisdiction where the defendant maintains its principal +place of business and such litigation shall be governed by laws of that +jurisdiction, without reference to its conflict-of-law provisions. +Nothing in this Section shall prevent a party's ability to bring +cross-claims or counter-claims. + +9. Miscellaneous +---------------- + +This License represents the complete agreement concerning the subject +matter hereof. If any provision of this License is held to be +unenforceable, such provision shall be reformed only to the extent +necessary to make it enforceable. Any law or regulation which provides +that the language of a contract shall be construed against the drafter +shall not be used to construe this License against a Contributor. + +10. Versions of the License +--------------------------- + +10.1. New Versions + +Mozilla Foundation is the license steward. Except as provided in Section +10.3, no one other than the license steward has the right to modify or +publish new versions of this License. Each version will be given a +distinguishing version number. + +10.2. Effect of New Versions + +You may distribute the Covered Software under the terms of the version +of the License under which You originally received the Covered Software, +or under the terms of any subsequent version published by the license +steward. + +10.3. Modified Versions + +If you create software not governed by this License, and you want to +create a new license for such software, you may create and use a +modified version of this License if you rename the license and remove +any references to the name of the license steward (except to note that +such modified license differs from this License). + +10.4. Distributing Source Code Form that is Incompatible With Secondary +Licenses + +If You choose to distribute Source Code Form that is Incompatible With +Secondary Licenses under the terms of this version of the License, the +notice described in Exhibit B of this License must be attached. + +Exhibit A - Source Code Form License Notice +------------------------------------------- + + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. + +If it is not possible or desirable to put the notice in a particular +file, then You may include the notice in a location (such as a LICENSE +file in a relevant directory) where a recipient would be likely to look +for such a notice. + +You may add additional accurate notices of copyright ownership. + +Exhibit B - "Incompatible With Secondary Licenses" Notice +--------------------------------------------------------- + + This Source Code Form is "Incompatible With Secondary Licenses", as + defined by the Mozilla Public License, v. 2.0. \ No newline at end of file diff --git a/3rdparty/LICENSE.gRPC-web b/3rdparty/LICENSE.gRPC-web new file mode 100644 index 0000000..f49a4e1 --- /dev/null +++ b/3rdparty/LICENSE.gRPC-web @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 6933eee..2f64408 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,27 @@ +# clara-viz 0.3.0 (June 22 2023) + +## Features + +* C++ interface is now public +* Add support for aarch64 (not for Python wheels) +* Add support for VR/AR rendering + + Camera has stereo mode and left end right eye poses, tangents and gaze directions + + Add warped and foveated rendering + + Add reprojection +* Add support for separate depth buffer +* Add support for alpha channel +* Add support for near and far depth plane +* Add support for transforming the volume using a matrix + +## Bug Fixes + +* Fix tonemap enable, had no effect before (always enabled). +* AttributeError: module 'itk' has no attribute 'itkSpatialOrientationPython' (https://github.com/NVIDIA/clara-viz/issues/26) + +## Security + +* Update Jupyter widget Java code packages to fix vulnerability CVE-2022-46175 + # clara-viz 0.2.2 (October 17 2022) ## Bug Fixes diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..ed87a25 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,82 @@ +# Copyright (c) 2020-2023, NVIDIA CORPORATION. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +cmake_minimum_required(VERSION 3.12) + +# Options +option(CLARA_VIZ_CUDA_PROFILING "Enable CUDA profiling" OFF) +option(CLARA_VIZ_CUDA_DEBUG "Enable CUDA debug" OFF) +option(CLARA_VIZ_WITH_GRPC "Build with gRPC frontend" ON) +option(CLARA_VIZ_WITH_OPENH264 "Build with OpenH264 support for encoding videos when no HW encoder is available" ON) +option(CLARA_VIZ_WITH_EXAMPLES "Build examples" ON) + +include(ExternalProject) + +project(ClaraViz + DESCRIPTION "ClaraViz" + VERSION 0.3.0 + LANGUAGES CXX +) + +set(CMAKE_INSTALL_PREFIX "${PROJECT_SOURCE_DIR}") +set(CLARA_VIZ_PUBLIC_CMAKE_TOOLS_DIR "${PROJECT_SOURCE_DIR}/cmake") + +include("${CLARA_VIZ_PUBLIC_CMAKE_TOOLS_DIR}/Project.cmake") +setup_project() + +# Build the thirdparty dependencies +add_subdirectory(thirdparty) + +set(_DEPENDENCIES CudaHelper) +if (CLARA_VIZ_WITH_OPENH264) + set(_DEPENDENCIES ${_DEPENDENCIES} OpenH264) +endif() +if (CLARA_VIZ_WITH_GRPC) + set(_DEPENDENCIES ${_DEPENDENCIES} gRPC grpc-web) +endif() + +# Build the ClaraViz project +# This is done with an external project. Thirdparty projects are also +# external projects and the only way to for CMake to correctly handle +# the dependencies is that our source is also build as an external +# project. +ExternalProject_Add(ClaraViz + PREFIX claraviz + DOWNLOAD_COMMAND "" + SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src" + INSTALL_DIR ${CMAKE_INSTALL_PREFIX} + BUILD_ALWAYS ON + CMAKE_ARGS + -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX} + -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} + CMAKE_CACHE_ARGS + -DgRPC_DIR:PATH=${gRPC_DIR} + -Dprotobuf-javascript_SOURCE_DIR:PATH=${protobuf-javascript_SOURCE_DIR} + -Dabsl_DIR:PATH=${absl_DIR} + -DZLIB_ROOT:PATH=${ZLIB_ROOT} + -DProtobuf_DIR:PATH=${Protobuf_DIR} + -DOPENSSL_ROOT_DIR:PATH=${OPENSSL_ROOT_DIR} + -Dgrpc-web_DIR:PATH=${grpc-web_DIR} + -DCudaHelper_DIR:PATH=${CudaHelper_DIR} + -DOpenH264_DIR:PATH=${OpenH264_DIR} + -Dnlohmann_json_SOURCE_DIR:PATH=${nlohmann_json_SOURCE_DIR} + -Dnlohmann_json_BINARY_DIR:PATH=${nlohmann_json_BINARY_DIR} + -DCLARA_VIZ_PUBLIC_CMAKE_TOOLS_DIR:PATH=${CLARA_VIZ_PUBLIC_CMAKE_TOOLS_DIR} + -DCLARA_VIZ_CUDA_PROFILING:BOOL=${CLARA_VIZ_CUDA_PROFILING} + -DCLARA_VIZ_CUDA_DEBUG:BOOL=${CLARA_VIZ_CUDA_DEBUG} + -DCLARA_VIZ_WITH_GRPC:BOOL=${CLARA_VIZ_WITH_GRPC} + -DCLARA_VIZ_WITH_OPENH264:BOOL=${CLARA_VIZ_WITH_OPENH264} + -DCLARA_VIZ_WITH_EXAMPLES:BOOL=${CLARA_VIZ_WITH_EXAMPLES} + DEPENDS ${_DEPENDENCIES} +) diff --git a/Dockerfile.claravizrenderserver b/Dockerfile.claravizrenderserver new file mode 100644 index 0000000..1d5e606 --- /dev/null +++ b/Dockerfile.claravizrenderserver @@ -0,0 +1,34 @@ +# Copyright (c) 2019-2023, NVIDIA CORPORATION. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +ARG DOCKER_HUB +FROM ${DOCKER_HUB}nvidia/cuda:11.2.0-base-ubuntu18.04 + +WORKDIR /app + +COPY ./bin/ ./bin/ +COPY ./lib/ ./lib/ + +EXPOSE 2050 + +RUN echo "#!/bin/bash \n/app/bin/$(uname -m)/ClaraVizRenderServer \"\$@\"" > ./entrypoint.sh && \ + chmod +x entrypoint.sh +ENTRYPOINT ["./entrypoint.sh"] + +# all devices should be visible +ENV NVIDIA_VISIBLE_DEVICES all +# set 'compute' driver cap to use Cuda +# set 'video' driver cap to use the video encoder +# set 'graphics' driver cap to use OpenGL/EGL +ENV NVIDIA_DRIVER_CAPABILITIES graphics,video,compute,utility diff --git a/Dockerfile_aarch64.build b/Dockerfile_aarch64.build new file mode 100644 index 0000000..09f816e --- /dev/null +++ b/Dockerfile_aarch64.build @@ -0,0 +1,65 @@ +# Copyright (c) 2019-2023, NVIDIA CORPORATION. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +ARG DOCKER_HUB +FROM ${DOCKER_HUB}nvidia/cuda:11.2.0-devel-ubuntu18.04 + +# install dependencies +# * wget, ca-certificates: to download packages +# * build-essential: for building code +# * git: used by cmake to clone git projects +# * nasm: used by openh264 +# * libx11-dev: used by 'claravizrenderer-ui' example +RUN apt-get update \ + && apt-get upgrade -y \ + && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ + wget ca-certificates build-essential git nasm libx11-dev \ + && rm -rf /var/lib/apt/lists/* + +# Install git-lfs to be used by cmake +# We need a system wide installation of git lfs. The install script installs for the current user only, therefore additionally +# install with '--system' +RUN mkdir /tmp/git-lfs \ + && cd /tmp/git-lfs \ + && ARCH=$(uname -m) \ + && if [ "${ARCH}" = "aarch64" ]; then GIT_LFS_ARCH="arm64"; else GIT_LFS_ARCH="amd64"; fi \ + && wget -nv https://github.com/git-lfs/git-lfs/releases/download/v2.6.0/git-lfs-linux-$GIT_LFS_ARCH-v2.6.0.tar.gz \ + && mkdir -p git-lfs-linux-$GIT_LFS_ARCH-v2.6.0 \ + && tar xf git-lfs-linux-$GIT_LFS_ARCH-v2.6.0.tar.gz -C git-lfs-linux-$GIT_LFS_ARCH-v2.6.0 \ + && cd git-lfs-linux-$GIT_LFS_ARCH-v2.6.0 \ + && ./install.sh \ + && git lfs install --system \ + && cd - \ + && rm -rf /tmp/git-lfs + +# Install cmake +ARG CMAKE_VERSION="3.21.0" +RUN mkdir /tmp/cmake \ + && cd /tmp/cmake \ + && ARCH=$(uname -m) \ + && wget -nv https://github.com/Kitware/CMake/releases/download/v$CMAKE_VERSION/cmake-$CMAKE_VERSION-linux-$ARCH.tar.gz \ + && tar xf cmake-$CMAKE_VERSION-linux-$ARCH.tar.gz \ + && cp -r cmake-$CMAKE_VERSION-linux-$ARCH/bin/* /usr/local/bin/ \ + && cp -r cmake-$CMAKE_VERSION-linux-$ARCH/share/* /usr/local/share/ \ + && cd - \ + && rm -rf /tmp/cmake + +# all devices should be visible +ENV NVIDIA_VISIBLE_DEVICES all +# set 'compute' driver cap to use Cuda +# set 'video' driver cap to use the video encoder +# set 'graphics' driver cap to use OpenGL/EGL +ENV NVIDIA_DRIVER_CAPABILITIES graphics,video,compute,utility + +USER root \ No newline at end of file diff --git a/Dockerfile_x86_64.build b/Dockerfile_x86_64.build new file mode 100644 index 0000000..88d2548 --- /dev/null +++ b/Dockerfile_x86_64.build @@ -0,0 +1,72 @@ +# Copyright (c) 2019-2023, NVIDIA CORPORATION. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +ARG DOCKER_HUB=quay.io/ +FROM ${DOCKER_HUB}pypa/manylinux_2_28_x86_64:2023-03-20-098e33d + +# Install the Cuda toolkit +# - use gcc-10 since gcc-12 is not supported by CUDA 11.4 +RUN dnf config-manager --add-repo https://developer.download.nvidia.com/compute/cuda/repos/rhel8/x86_64/cuda-rhel8.repo \ + && dnf install -y \ + cuda-minimal-build-11-4 \ + cuda-driver-devel-11-4 \ + libnvjpeg-devel-11-4 \ + && ln -s /usr/local/cuda-11.4 /usr/local/cuda \ + && dnf install -y gcc-toolset-10-gcc gcc-toolset-10-gcc-c++ \ + && echo -e "#!/bin/bash\nsource scl_source enable gcc-toolset-10" > /etc/profile.d/enablegcctoolset-10.sh \ + && dnf clean all \ + && rm -rf /var/cache/dnf + +ENV PATH=/usr/local/cuda/bin${PATH:+:${PATH}} +ENV LD_LIBRARY_PATH=/usr/local/cuda/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}} + +# Install dependencies +# * wget: to download packages +# * git: used by cmake to clone git projects +# * nasm: used by openh264 +# * libX11-devel: used by 'claravizrenderer-ui' example +RUN dnf install -y wget git nasm libX11-devel \ + && dnf clean all \ + && rm -rf /var/cache/dnf + +WORKDIR /tmp + +# Install git-lfs to be used by cmake +# We need a system wide installation of git lfs. The install script installs for the current user only, therefore additionally +# install with '--system' +RUN mkdir /tmp/git-lfs \ + && cd /tmp/git-lfs \ + && ARCH=$(uname -m) \ + && if [ "${ARCH}" = "aarch64" ]; then GIT_LFS_ARCH="arm64"; else GIT_LFS_ARCH="amd64"; fi \ + && wget -nv https://github.com/git-lfs/git-lfs/releases/download/v2.6.0/git-lfs-linux-$GIT_LFS_ARCH-v2.6.0.tar.gz \ + && mkdir -p git-lfs-linux-$GIT_LFS_ARCH-v2.6.0 \ + && tar xf git-lfs-linux-$GIT_LFS_ARCH-v2.6.0.tar.gz -C git-lfs-linux-$GIT_LFS_ARCH-v2.6.0 \ + && cd git-lfs-linux-$GIT_LFS_ARCH-v2.6.0 \ + && ./install.sh \ + && git lfs install --system \ + && cd - \ + && rm -rf /tmp/git-lfs + +# use the CUDA gcc-toolset for any command +ENTRYPOINT [ "scl", "enable", "gcc-toolset-10", "--", "manylinux-entrypoint" ] + +# all devices should be visible +ENV NVIDIA_VISIBLE_DEVICES all +# set 'compute' driver cap to use Cuda +# set 'video' driver cap to use the video encoder +# set 'graphics' driver cap to use OpenGL/EGL +ENV NVIDIA_DRIVER_CAPABILITIES graphics,video,compute,utility + +USER root + diff --git a/LICENSE-3rdparty.md b/LICENSE-3rdparty.md index 122e5d2..a623e8c 100644 --- a/LICENSE-3rdparty.md +++ b/LICENSE-3rdparty.md @@ -11,6 +11,41 @@ in the repository/distribution. --- +ExposureRenderer +- License: BSD-like License + - https://github.com/ThomasKroes/exposure-render/blob/f79ed1e608c8ece7f3558507306c1e5698c22fc6/Source/exposurerender.h +- Copyright: T. Kroes + +gRPC +- License: Apache 2.0 License + - https://github.com/grpc/grpc/blob/master/LICENSE +- Copyright: + +gRPC-web +- License: Apache 2.0 License + - https://github.com/grpc/grpc-web/blob/master/LICENSE +- Copyright: + +OpenSSL +- License: Apache 2.0 License + - https://github.com/openssl/openssl/blob/master/LICENSE.txt +- Copyright: + +ThreadPool +- License: zlib License + - https://github.com/progschj/ThreadPool/blob/master/COPYING +- Copyright: Jakob Progsch, Václav Zeman + +OpenH264 +- License: BSD-2-Clause License + - https://github.com/cisco/openh264/blob/master/LICENSE +- Copyright: Cisco Systems + +JSON for Modern C++ +- License: MIT License + - https://github.com/nlohmann/json/blob/develop/LICENSE.MIT +- Copyright: Niels Lohmann + ipywidgets - License: BSD-like License - https://github.com/jupyter-widgets/ipywidgets/blob/master/LICENSE diff --git a/README.md b/README.md index 4c4b19f..fd46479 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ On Windows, starting with Chrome version 91 (also with Microsoft Edge) the inter ## Requirements -* OS: Linux x86_64 +* OS: Linux x86_64 or aarch64 * NVIDIA GPU: Pascal or newer, including Pascal, Volta, Turing and Ampere families * NVIDIA driver: 450.36.06+ @@ -30,72 +30,41 @@ On Windows, starting with Chrome version 91 (also with Microsoft Edge) the inter https://docs.nvidia.com/clara-viz/index.html -## Quick Start +## Build -### Installation +### With docker file -This will install all Clara Viz packages use pip: +This is using a docker file to build the binaries. First build the docker file used to compile the code: ```bash -$ pip install clara-viz +docker build -t clara_viz_builder_$(uname -m) -f Dockerfile_$(uname -m).build . ``` -Clara Viz is using namespace packages. The main functionality is implemented in the 'clara-viz-core' package, -Jupyter Notebook widgets are found in the 'clara-viz-widgets' package. -So for example if you just need the renderer use +Then start the build process inside the build docker image. Build results are written to the 'build' directory. ```bash -$ pip install clara-viz-core +docker run --network host --rm -it -u $(id -u):$(id -g) -v $PWD:/ClaraViz \ + -w /ClaraViz clara_viz_builder_$(uname -m) ./build.sh -o build_$(uname -m) ``` -### Use interactive widget in Jupyter Notebook +### From command line -Install the Jupyter notebook widgets. +#### Dependencies -```bash -$ pip install clara-viz-widgets -``` - -Start Jupyter Lab, open the notebooks in the `notebooks` folder. Make sure Git LFS is installed when cloning the repo, else the data files are not downloaded correctly and you will see file open errors when using the example notebooks. - -```python -from clara.viz.widgets import Widget -from clara.viz.core import Renderer -import numpy as np - -# load a RAW CT data file (volume is 512x256x256 voxels) -input = np.fromfile("CT.raw", dtype=np.int16) -input = input.reshape((512, 256, 256)) - -display(Widget(Renderer(input))) -``` - -### Render CT data from Python - -```python -from PIL import Image -import clara.viz.core -import numpy as np +git +git-lfs +nasm +CMake 3.19.1 -# load a RAW CT data file (volume is 512x256x256 voxels) -input = np.fromfile("CT.raw", dtype=np.int16) -input = input.reshape((512, 256, 256)) +#### Build -# create the renderer -renderer = clara.viz.core.Renderer(input) - -# render to a raw numpy array -output = renderer.render_image(1024, 768, image_type=clara.viz.core.ImageType.RAW_RGB_U8_DEPTH_U8) -rgb_data = np.asarray(output)[:, :, :3] - -# show with PIL -image = Image.fromarray(rgb_data) -image.show() +```bash +./build.sh -o build_$(uname -m) ``` ## Use within a Docker container -Clara Viz requires CUDA, use a `base` container from `https://hub.docker.com/r/nvidia/cuda` for example `nvidia/cuda:11.4.2-base-ubuntu20.04`. By default the CUDA container exposes the `compute` and `utility` capabilities only. Clara Viz additionally needs the `graphics` and `video` capabilites. Therefore the docker container needs to be run with the `NVIDIA_DRIVER_CAPABILITIES` env variable set: +Clara Viz requires CUDA, use a `base` container from `https://hub.docker.com/r/nvidia/cuda` for example `nvidia/cuda:11.4.2-base-ubuntu20.04`. By default the CUDA container exposes the `compute` and `utility` capabilities only. Clara Viz additionally needs the `graphics` and `video` capabilities. Therefore the docker container needs to be run with the `NVIDIA_DRIVER_CAPABILITIES` env variable set: ```bash $ docker run -it --rm -e NVIDIA_DRIVER_CAPABILITIES=graphics,video,compute,utility nvidia/cuda:11.4.2-base-ubuntu20.04 ``` @@ -121,4 +90,4 @@ is used in this project. Apache-2.0 License (see `LICENSE` file). -Copyright (c) 2020-2021, NVIDIA CORPORATION. +Copyright (c) 2020-2023, NVIDIA CORPORATION. diff --git a/bin/aarch64/ClaraVizRenderServer b/bin/aarch64/ClaraVizRenderServer new file mode 100755 index 0000000..7fd5a9c Binary files /dev/null and b/bin/aarch64/ClaraVizRenderServer differ diff --git a/bin/x86_64/ClaraVizRenderServer b/bin/x86_64/ClaraVizRenderServer new file mode 100755 index 0000000..2d3f99c Binary files /dev/null and b/bin/x86_64/ClaraVizRenderServer differ diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..a0b05b9 --- /dev/null +++ b/build.sh @@ -0,0 +1,72 @@ +#!/bin/bash -e +# Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +SRC=$PWD +COVERAGE=0 +# by default output is the current directory +OUT=$(readlink -f $SRC) + +# colors +RED="\033[0;31m" +GREEN="\033[0;32m" +NC="\033[0m" # No Color + +# print a failure message +function failMsg +{ + echo -e "$RED$1$NC$2" +} + +while (($#)); do +case $1 in + -o|--output) + shift + if [ -z $1 ]; then + failMsg "Missing argument" + exit 1 + fi + OUT=$(readlink -f $1) + shift + ;; + + -h|--help) + echo "Usage: $0 [-o|--output]" + echo "" + echo " -o, --output" + echo " output directory, default is current directory" + echo " -h, --help" + echo " display this help message" + exit 1 + ;; + + *) + failMsg "Unknown option '"$1"'" + exit 1 + ;; +esac +done + +mkdir -p $OUT +cd $OUT + +# initial call to cmake to generate the build files +if [ ! -f CMakeCache.txt ]; then + cmake $SRC +fi + +# build +make -j$(nproc) +# install to package +cmake --install . diff --git a/cmake/Project.cmake b/cmake/Project.cmake new file mode 100644 index 0000000..9008824 --- /dev/null +++ b/cmake/Project.cmake @@ -0,0 +1,80 @@ +# Copyright (c) 2019-2023, NVIDIA CORPORATION. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +cmake_minimum_required(VERSION 3.12) + +macro(setup_project) + # avoid 'Up-to-date' install messages + set(CMAKE_INSTALL_MESSAGE LAZY) + + # Ensure user selected a build type + if (NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel." FORCE) + endif() + + # CUDA settings + + # use the stub libs instead of real binaries, with that building in docker without using the nvidia runtime works + set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} /usr/local/cuda/lib64/stubs) + + # Generate code for multiple architectures, if we don't do this the JIT compiler will compile SM specific + # code from the embedded PTX code. This will increase program startup times. + # Pascal (60, 61), Volta (70), Turing (75), Ampere (80) + set(CMAKE_CUDA_ARCHITECTURES 60-real 61-real 70-real 75-real 80) + + set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} --use_fast_math") + # allow calling constexpr host function from device code and vice versa, used to call std::numeric_limits functions from device + set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} --expt-relaxed-constexpr") + + + if (CLARA_VIZ_CUDA_DEBUG) + # enable for device debugging in debug mode + set(CMAKE_CUDA_FLAGS_DEBUG "${CMAKE_CUDA_FLAGS_DEBUG} --device-debug") + endif() + + if (CLARA_VIZ_CUDA_PROFILING) + # enable for profiling + set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} --generate-line-info") + endif() + + # statically link the runtime + set(CMAKE_CUDA_RUNTIME_LIBRARY "Static") + + # enable c++17 + set(CMAKE_CXX_STANDARD 17) + if(NOT DEFINED CMAKE_CUDA_STANDARD) + set(CMAKE_CUDA_STANDARD 17) + set(CMAKE_CUDA_STANDARD_REQUIRED ON) + endif() + + # set flags for coverage builds + set(CMAKE_CXX_FLAGS_COVERAGE + "-DNDEBUG" + CACHE STRING "Flags used by the C++ compiler during coverage builds." + FORCE) + set(CMAKE_C_FLAGS_COVERAGE + "-DNDEBUG" + CACHE STRING "Flags used by the C compiler during coverage builds." + FORCE) + MARK_AS_ADVANCED( + CMAKE_CXX_FLAGS_COVERAGE + CMAKE_C_FLAGS_COVERAGE) + + # setup nvsharedmemory + find_package(nvsharedmemory CONFIG) + if(nvsharedmemory_FOUND) + add_compile_definitions(CLARA_VIZ_USE_NVSHAREDMEMORY) + endif() + +endmacro() diff --git a/cmake/Tools.cmake b/cmake/Tools.cmake new file mode 100644 index 0000000..8155410 --- /dev/null +++ b/cmake/Tools.cmake @@ -0,0 +1,251 @@ +# Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +cmake_minimum_required(VERSION 3.12) + +include(CMakeParseArguments) + +# Add custom commands to process ``.proto`` files to C++:: +# +# protobuf_grpc_generate ([TARGET ] [APPEND_PATH] +# [LANGUAGE ] [OUT_VAR ] [EXPORT_MACRO ] +# [IMPORT_DIRS [dirs...]] [GENERATE_EXTENSIONS [exts...] +# [PROTOS [files...]]) +# +# ``TARGET`` +# if specified the generated source files are added to the target +# ``OUT_VAR`` +# if specified the generated source files are stored to a variable +# ``APPEND_PATH`` +# create an include path for each file specified +# ``LANGUAGE`` +# generated language, either 'python', 'grpc-web' or 'cpp', default 'cpp' +# ``EXPORT_MACRO`` +# is a macro which should expand to ``__declspec(dllexport)`` or +# ``__declspec(dllimport)`` depending on what is being compiled. +# ``IMPORT_DIRS`` +# import directories +# ``GENERATE_EXTENSIONS`` +# extensions of generated files, needed if an unrecognized language is specified +# ``PROTOC_ARGS`` +# protoc argument, needed if an unrecognized language is specified +# ``PROTOS`` +# ``.proto`` files +function(protobuf_grpc_generate) + set(_options APPEND_PATH) + set(_singleargs LANGUAGE OUT_VAR EXPORT_MACRO) + if(COMMAND target_sources) + list(APPEND _singleargs TARGET) + endif() + set(_multiargs PROTOS IMPORT_DIRS GENERATE_EXTENSIONS) + + cmake_parse_arguments(protobuf_generate "${_options}" "${_singleargs}" "${_multiargs}" "${ARGN}") + + if(NOT protobuf_generate_PROTOS AND NOT protobuf_generate_TARGET) + message(SEND_ERROR "Error: protobuf_generate called without any targets or source files") + return() + endif() + + if(NOT protobuf_generate_OUT_VAR AND NOT protobuf_generate_TARGET) + message(SEND_ERROR "Error: protobuf_generate called without a target or output variable") + return() + endif() + + if(NOT protobuf_generate_LANGUAGE) + set(protobuf_generate_LANGUAGE cpp) + endif() + string(TOLOWER ${protobuf_generate_LANGUAGE} protobuf_generate_LANGUAGE) + + if(protobuf_generate_EXPORT_MACRO AND protobuf_generate_LANGUAGE STREQUAL cpp) + set(_dll_export_decl "dllexport_decl=${protobuf_generate_EXPORT_MACRO}:") + endif() + + if(protobuf_generate_LANGUAGE STREQUAL cpp) + set(protobuf_PROTOC_ARGS --grpc_out ${_dll_export_decl}${CMAKE_CURRENT_BINARY_DIR} --cpp_out ${_dll_export_decl}${CMAKE_CURRENT_BINARY_DIR} --plugin=protoc-gen-grpc=$) + set(protobuf_GENERATE_EXTENSIONS .pb.h .pb.cc .grpc.pb.h .grpc.pb.cc) + elseif(protobuf_generate_LANGUAGE STREQUAL python) + set(protobuf_PROTOC_ARGS --grpc_out ${_dll_export_decl}${CMAKE_CURRENT_BINARY_DIR} --python_out ${_dll_export_decl}${CMAKE_CURRENT_BINARY_DIR} --plugin=protoc-gen-grpc=$) + set(protobuf_GENERATE_EXTENSIONS _pb2.py) + elseif(protobuf_generate_LANGUAGE STREQUAL grpc-web) + set(protobuf_PROTOC_ARGS --js_out=import_style=commonjs:${CMAKE_CURRENT_BINARY_DIR} --grpc-web_out=import_style=commonjs,mode=grpcwebtext:${CMAKE_CURRENT_BINARY_DIR} --plugin=protoc-gen-grpc-web=$) + # Workaround for https://github.com/protocolbuffers/protobuf-javascript/issues/127 + # set path to protoc-gen-js + set(protobuf_PROTOC_ARGS ${protobuf_PROTOC_ARGS} --plugin=protoc-gen-js=${protobuf-javascript_SOURCE_DIR}/bin/protoc-gen-js) + set(protobuf_GENERATE_EXTENSIONS .js) + else() + if(NOT protobuf_GENERATE_EXTENSIONS OR NOT protobuf_PROTOC_ARGS) + message(SEND_ERROR "Error: protobuf_generate given unknown Language ${LANGUAGE}, please provide a value for GENERATE_EXTENSIONS and PROTOC_ARGS") + return() + endif() + endif() + + if(protobuf_generate_TARGET) + get_target_property(_source_list ${protobuf_generate_TARGET} SOURCES) + foreach(_file ${_source_list}) + if(_file MATCHES "proto$") + list(APPEND protobuf_generate_PROTOS ${_file}) + endif() + endforeach() + endif() + + if(NOT protobuf_generate_PROTOS) + message(SEND_ERROR "Error: protobuf_generate could not find any .proto files") + return() + endif() + + if(protobuf_generate_APPEND_PATH) + # Create an include path for each file specified + foreach(_file ${protobuf_generate_PROTOS}) + get_filename_component(_abs_file ${_file} ABSOLUTE) + get_filename_component(_abs_path ${_abs_file} PATH) + list(FIND _protobuf_include_path ${_abs_path} _contains_already) + if(${_contains_already} EQUAL -1) + list(APPEND _protobuf_include_path -I ${_abs_path}) + endif() + endforeach() + else() + set(_protobuf_include_path -I ${CMAKE_CURRENT_SOURCE_DIR}) + endif() + + foreach(DIR IN LISTS protobuf_generate_IMPORT_DIRS) + get_filename_component(ABS_PATH ${DIR} ABSOLUTE) + list(FIND _protobuf_include_path ${ABS_PATH} _contains_already) + if(${_contains_already} EQUAL -1) + list(APPEND _protobuf_include_path -I ${ABS_PATH}) + endif() + endforeach() + + set(_generated_srcs_all) + foreach(_proto ${protobuf_generate_PROTOS}) + get_filename_component(_abs_file ${_proto} ABSOLUTE) + get_filename_component(_directory ${_proto} DIRECTORY) + get_filename_component(_basename ${_proto} NAME_WE) + + set(_generated_srcs) + foreach(_ext ${protobuf_GENERATE_EXTENSIONS}) + list(APPEND _generated_srcs "${CMAKE_CURRENT_BINARY_DIR}/${_directory}/${_basename}${_ext}") + endforeach() + list(APPEND _generated_srcs_all ${_generated_srcs}) + + add_custom_command( + OUTPUT ${_generated_srcs} + COMMAND protobuf::protoc + ARGS ${protobuf_PROTOC_ARGS} + ${_protobuf_include_path} + ${_abs_file} + DEPENDS ${_abs_file} protobuf::protoc + COMMENT "Running ${protobuf_generate_LANGUAGE} protocol buffer compiler on ${_proto}" + VERBATIM ) + endforeach() + + set_source_files_properties(${_generated_srcs_all} PROPERTIES GENERATED TRUE) + if(protobuf_generate_OUT_VAR) + set(${protobuf_generate_OUT_VAR} ${_generated_srcs_all} PARENT_SCOPE) + endif() + if(protobuf_generate_TARGET) + target_sources(${protobuf_generate_TARGET} PRIVATE ${_generated_srcs_all}) + endif() + +endfunction() + +# Add gRPC protobuf files. Generate sources and add dependencies +function(grpc_generate PROJECT_NAME) + # protobuf sources are generate in the current binary directory, add + # that directory to the include directories so we can include header + # files + set(CMAKE_INCLUDE_CURRENT_DIR TRUE PARENT_SCOPE) + + target_link_libraries(${PROJECT_NAME} + PUBLIC + gRPC::grpc++ + ) + + target_include_directories(${PROJECT_NAME} + PUBLIC + $ + ) + + # include the path to the proto files + get_target_property(_include_paths ${PROJECT_NAME} INTERFACE_INCLUDE_DIRECTORIES) + protobuf_grpc_generate(TARGET ${PROJECT_NAME} IMPORT_DIRS ${_include_paths}) +endfunction() + +# Prebuild setup - get the desired version +function(prebuild_setup) + set(_options ) + set(_singleargs VERSION_VAR) + set(_multiargs ) + + cmake_parse_arguments(prebuild_setup "${_options}" "${_singleargs}" "${_multiargs}" "${ARGN}") + + if (NOT prebuild_setup_VERSION_VAR) + message(SEND_ERROR "Version variable not specified") + return() + endif() + + # read the version + file(READ ${CMAKE_CURRENT_SOURCE_DIR}/version.txt _version) + set_directory_properties(PROPERTIES CMAKE_CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/version.txt) + set(${prebuild_setup_VERSION_VAR} ${_version} PARENT_SCOPE) +endfunction() + +# Builds the package name +function(prebuild_package_name) + set(_options ) + set(_singleargs PREFIX VERSION VAR) + set(_multiargs ) + + cmake_parse_arguments(prebuild_package_name "${_options}" "${_singleargs}" "${_multiargs}" "${ARGN}") + + if (NOT prebuild_package_name_PREFIX) + message(SEND_ERROR "Prefix not specified") + return() + endif() + if (NOT prebuild_package_name_VERSION) + message(SEND_ERROR "Version not specified") + return() + endif() + if (NOT prebuild_package_name_VAR) + message(SEND_ERROR "Result variable not specified") + return() + endif() + if (DEFINED ENV{AUDITWHEEL_POLICY}) + set(_auditwheel_policy "-$ENV{AUDITWHEEL_POLICY}") + else() + set(_auditwheel_policy "") + endif() + + # name of the package + set(_package_name ${prebuild_package_name_PREFIX}-${prebuild_package_name_VERSION}-${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}${_auditwheel_policy}) + set(${prebuild_package_name_VAR} ${_package_name} PARENT_SCOPE) +endfunction() + +# Enable code coverage for the given project when the build target is 'Coverage' +function(target_code_coverage PROJECT_NAME) + if (CMAKE_BUILD_TYPE STREQUAL "Coverage") + target_compile_options(${PROJECT_NAME} + PRIVATE + # disable optimizations + -O0 + # when compiling for Cuda keep the temporary files and pass the coverage option to gcc + $<$:--keep --keep-dir ${CMAKE_CURRENT_BINARY_DIR} -Xcompiler> + # compile and link code instrumented for coverage analysis + --coverage + ) + target_link_libraries(${PROJECT_NAME} + PUBLIC + gcov + ) + endif() +endfunction() diff --git a/cmake/clara_viz_rendererConfig.cmake b/cmake/clara_viz_rendererConfig.cmake new file mode 100644 index 0000000..49b5c27 --- /dev/null +++ b/cmake/clara_viz_rendererConfig.cmake @@ -0,0 +1,147 @@ +# Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" LESS 2.8) + message(FATAL_ERROR "CMake >= 2.8.0 required") +endif() +if(CMAKE_VERSION VERSION_LESS "2.8.3") + message(FATAL_ERROR "CMake >= 2.8.3 required") +endif() +cmake_policy(PUSH) +cmake_policy(VERSION 2.8.3...3.24) + + +####### Expanded from @PACKAGE_INIT@ by configure_package_config_file() ####### +####### Any changes to this file will be overwritten by the next CMake run #### +####### The input file was ClaraVizRendererConfig.cmake.in ######## + +get_filename_component(PACKAGE_PREFIX_DIR "${CMAKE_CURRENT_LIST_DIR}/../" ABSOLUTE) + +macro(set_and_check _var _file) + set(${_var} "${_file}") + if(NOT EXISTS "${_file}") + message(FATAL_ERROR "File or directory ${_file} referenced by variable ${_var} does not exist !") + endif() +endmacro() + +macro(check_required_components _NAME) + foreach(comp ${${_NAME}_FIND_COMPONENTS}) + if(NOT ${_NAME}_${comp}_FOUND) + if(${_NAME}_FIND_REQUIRED_${comp}) + set(${_NAME}_FOUND FALSE) + endif() + endif() + endforeach() +endmacro() + +#################################################################################### + +#---------------------------------------------------------------- +# Generated CMake target import file. +#---------------------------------------------------------------- + +# Commands may need to know the format version. +set(CMAKE_IMPORT_FILE_VERSION 1) + +# Protect against multiple inclusion, which would fail when already imported targets are added once more. +set(_cmake_targets_defined "") +set(_cmake_targets_not_defined "") +set(_cmake_expected_targets "") +foreach(_cmake_expected_target IN ITEMS clara::viz::renderer) + list(APPEND _cmake_expected_targets "${_cmake_expected_target}") + if(TARGET "${_cmake_expected_target}") + list(APPEND _cmake_targets_defined "${_cmake_expected_target}") + else() + list(APPEND _cmake_targets_not_defined "${_cmake_expected_target}") + endif() +endforeach() +unset(_cmake_expected_target) +if(_cmake_targets_defined STREQUAL _cmake_expected_targets) + unset(_cmake_targets_defined) + unset(_cmake_targets_not_defined) + unset(_cmake_expected_targets) + unset(CMAKE_IMPORT_FILE_VERSION) + cmake_policy(POP) + return() +endif() +if(NOT _cmake_targets_defined STREQUAL "") + string(REPLACE ";" ", " _cmake_targets_defined_text "${_cmake_targets_defined}") + string(REPLACE ";" ", " _cmake_targets_not_defined_text "${_cmake_targets_not_defined}") + message(FATAL_ERROR "Some (but not all) targets in this export set were already defined.\nTargets Defined: ${_cmake_targets_defined_text}\nTargets not yet defined: ${_cmake_targets_not_defined_text}\n") +endif() +unset(_cmake_targets_defined) +unset(_cmake_targets_not_defined) +unset(_cmake_expected_targets) + + +# Compute the installation prefix relative to this file. +get_filename_component(_IMPORT_PREFIX "${CMAKE_CURRENT_LIST_FILE}" PATH) +get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH) +if(_IMPORT_PREFIX STREQUAL "/") + set(_IMPORT_PREFIX "") +endif() + +# Create imported target clara::viz::renderer +add_library(clara::viz::renderer SHARED IMPORTED) + +set_target_properties(clara::viz::renderer PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${_IMPORT_PREFIX}/include;${_IMPORT_PREFIX}/src" + INTERFACE_LINK_LIBRARIES "/usr/local/cuda/lib64/stubs/libcuda.so" +) + +if(CMAKE_VERSION VERSION_LESS 2.8.12) + message(FATAL_ERROR "This file relies on consumers using CMake 2.8.12 or greater.") +endif() + +# Import target "clara::viz::renderer" for configuration "Release" +set_property(TARGET clara::viz::renderer APPEND PROPERTY IMPORTED_CONFIGURATIONS RELEASE) +set_target_properties(clara::viz::renderer PROPERTIES + IMPORTED_LOCATION_RELEASE "${_IMPORT_PREFIX}/lib/${CMAKE_SYSTEM_PROCESSOR}/libclara_viz_renderer.so.0.3.0" + IMPORTED_SONAME_RELEASE "libclara_viz_renderer.so.0" + ) + +list(APPEND _cmake_import_check_targets clara::viz::renderer ) +list(APPEND _cmake_import_check_files_for_clara::viz::renderer "${_IMPORT_PREFIX}/lib/${CMAKE_SYSTEM_PROCESSOR}/libclara_viz_renderer.so.0.3.0" ) + +# Cleanup temporary variables. +set(_IMPORT_PREFIX) + +# Loop over all imported files and verify that they actually exist +foreach(_cmake_target IN LISTS _cmake_import_check_targets) + foreach(_cmake_file IN LISTS "_cmake_import_check_files_for_${_cmake_target}") + if(NOT EXISTS "${_cmake_file}") + message(FATAL_ERROR "The imported target \"${_cmake_target}\" references the file + \"${_cmake_file}\" +but this file does not exist. Possible reasons include: +* The file was deleted, renamed, or moved to another location. +* An install or uninstall procedure did not complete successfully. +* The installation package was faulty and contained + \"${CMAKE_CURRENT_LIST_FILE}\" +but not all the files it references. +") + endif() + endforeach() + unset(_cmake_file) + unset("_cmake_import_check_files_for_${_cmake_target}") +endforeach() +unset(_cmake_target) +unset(_cmake_import_check_targets) + +# This file does not depend on other imported targets which have +# been exported from the same project but in a separate export set. + +# Commands beyond this point should not need to know the version. +set(CMAKE_IMPORT_FILE_VERSION) +cmake_policy(POP) + diff --git a/cmake/clara_viz_rendererConfigVersion.cmake b/cmake/clara_viz_rendererConfigVersion.cmake new file mode 100644 index 0000000..33e59b4 --- /dev/null +++ b/cmake/clara_viz_rendererConfigVersion.cmake @@ -0,0 +1,65 @@ +# This is a basic version file for the Config-mode of find_package(). +# It is used by write_basic_package_version_file() as input file for configure_file() +# to create a version-file which can be installed along a config.cmake file. +# +# The created file sets PACKAGE_VERSION_EXACT if the current version string and +# the requested version string are exactly the same and it sets +# PACKAGE_VERSION_COMPATIBLE if the current version is >= requested version, +# but only if the requested major version is the same as the current one. +# The variable CVF_VERSION must be set before calling configure_file(). + + +set(PACKAGE_VERSION "0.3.0") + +if(PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION) + set(PACKAGE_VERSION_COMPATIBLE FALSE) +else() + + if("0.3.0" MATCHES "^([0-9]+)\\.") + set(CVF_VERSION_MAJOR "${CMAKE_MATCH_1}") + if(NOT CVF_VERSION_MAJOR VERSION_EQUAL 0) + string(REGEX REPLACE "^0+" "" CVF_VERSION_MAJOR "${CVF_VERSION_MAJOR}") + endif() + else() + set(CVF_VERSION_MAJOR "0.3.0") + endif() + + if(PACKAGE_FIND_VERSION_RANGE) + # both endpoints of the range must have the expected major version + math (EXPR CVF_VERSION_MAJOR_NEXT "${CVF_VERSION_MAJOR} + 1") + if (NOT PACKAGE_FIND_VERSION_MIN_MAJOR STREQUAL CVF_VERSION_MAJOR + OR ((PACKAGE_FIND_VERSION_RANGE_MAX STREQUAL "INCLUDE" AND NOT PACKAGE_FIND_VERSION_MAX_MAJOR STREQUAL CVF_VERSION_MAJOR) + OR (PACKAGE_FIND_VERSION_RANGE_MAX STREQUAL "EXCLUDE" AND NOT PACKAGE_FIND_VERSION_MAX VERSION_LESS_EQUAL CVF_VERSION_MAJOR_NEXT))) + set(PACKAGE_VERSION_COMPATIBLE FALSE) + elseif(PACKAGE_FIND_VERSION_MIN_MAJOR STREQUAL CVF_VERSION_MAJOR + AND ((PACKAGE_FIND_VERSION_RANGE_MAX STREQUAL "INCLUDE" AND PACKAGE_VERSION VERSION_LESS_EQUAL PACKAGE_FIND_VERSION_MAX) + OR (PACKAGE_FIND_VERSION_RANGE_MAX STREQUAL "EXCLUDE" AND PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION_MAX))) + set(PACKAGE_VERSION_COMPATIBLE TRUE) + else() + set(PACKAGE_VERSION_COMPATIBLE FALSE) + endif() + else() + if(PACKAGE_FIND_VERSION_MAJOR STREQUAL CVF_VERSION_MAJOR) + set(PACKAGE_VERSION_COMPATIBLE TRUE) + else() + set(PACKAGE_VERSION_COMPATIBLE FALSE) + endif() + + if(PACKAGE_FIND_VERSION STREQUAL PACKAGE_VERSION) + set(PACKAGE_VERSION_EXACT TRUE) + endif() + endif() +endif() + + +# if the installed or the using project don't have CMAKE_SIZEOF_VOID_P set, ignore it: +if(CMAKE_SIZEOF_VOID_P STREQUAL "" OR "8" STREQUAL "") + return() +endif() + +# check that the installed version has the same 32/64bit-ness as the one which is currently searching: +if(NOT CMAKE_SIZEOF_VOID_P STREQUAL "8") + math(EXPR installedBits "8 * 8") + set(PACKAGE_VERSION "${PACKAGE_VERSION} (${installedBits}bit)") + set(PACKAGE_VERSION_UNSUITABLE TRUE) +endif() diff --git a/include/ClaraVizRenderer.h b/include/ClaraVizRenderer.h new file mode 100644 index 0000000..982c6da --- /dev/null +++ b/include/ClaraVizRenderer.h @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2019-2022, NVIDIA CORPORATION. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include +#include + +#include + +namespace clara::viz +{ + +class MessageReceiver; + +/// Render backend for volumes +enum VolumeRenderBackend +{ + NvRTVol, ///< NvRTVol renderer +#ifdef CLARA_VIZ_WITH_OMNIVERSE + Omniverse, ///< Omniverse RTX renderer +#endif // CLARA_VIZ_WITH_OMNIVERSE + Default = NvRTVol +}; + +/** + * Renderer. + * Receives messages from the interfaces, renders images and pass them to the video message + * receiver. + */ +class Renderer +{ +public: + /** + * Construct + * + * @param video_msg_receiver [in] video message receiver + * @param image_msg_receiver [in] image message receiver + * @param cuda_device_ordinals [in] Cuda devices to render on + * @param volume_render_backend [in] render backend for volumes + * @param log_level [in] log level + * @param log_stream [in] log stream + */ + explicit Renderer(const std::shared_ptr &video_msg_receiver, + const std::shared_ptr &image_msg_receiver, + const std::vector &cuda_device_ordinals, + VolumeRenderBackend volume_render_backend = VolumeRenderBackend::Default, + LogLevel log_level = LogLevel::Info, + std::ostream *log_stream = &std::cout); + Renderer() = delete; + + /** + * Destruct. + */ + ~Renderer(); + + /** + * Run the renderer. + */ + void Run(); + + /** + * Shutdown the renderer, wait for all running tasks to finish. + */ + void Shutdown(); + + /** + * @returns the message receiver of the renderer + */ + std::shared_ptr GetReceiver() const; + +private: + struct Impl; + std::shared_ptr impl_; +}; + +} // namespace clara::viz diff --git a/lib/aarch64/libclara_viz_renderer.so b/lib/aarch64/libclara_viz_renderer.so new file mode 120000 index 0000000..1515e2e --- /dev/null +++ b/lib/aarch64/libclara_viz_renderer.so @@ -0,0 +1 @@ +libclara_viz_renderer.so.0 \ No newline at end of file diff --git a/lib/aarch64/libclara_viz_renderer.so.0 b/lib/aarch64/libclara_viz_renderer.so.0 new file mode 120000 index 0000000..0498d31 --- /dev/null +++ b/lib/aarch64/libclara_viz_renderer.so.0 @@ -0,0 +1 @@ +libclara_viz_renderer.so.0.3.0 \ No newline at end of file diff --git a/lib/aarch64/libclara_viz_renderer.so.0.3.0 b/lib/aarch64/libclara_viz_renderer.so.0.3.0 new file mode 100644 index 0000000..cab0d28 Binary files /dev/null and b/lib/aarch64/libclara_viz_renderer.so.0.3.0 differ diff --git a/lib/x86_64/libclara_viz_renderer.so b/lib/x86_64/libclara_viz_renderer.so new file mode 120000 index 0000000..1515e2e --- /dev/null +++ b/lib/x86_64/libclara_viz_renderer.so @@ -0,0 +1 @@ +libclara_viz_renderer.so.0 \ No newline at end of file diff --git a/lib/x86_64/libclara_viz_renderer.so.0 b/lib/x86_64/libclara_viz_renderer.so.0 new file mode 120000 index 0000000..0498d31 --- /dev/null +++ b/lib/x86_64/libclara_viz_renderer.so.0 @@ -0,0 +1 @@ +libclara_viz_renderer.so.0.3.0 \ No newline at end of file diff --git a/lib/x86_64/libclara_viz_renderer.so.0.3.0 b/lib/x86_64/libclara_viz_renderer.so.0.3.0 new file mode 100755 index 0000000..e05f9e5 Binary files /dev/null and b/lib/x86_64/libclara_viz_renderer.so.0.3.0 differ diff --git a/python/README.md b/python/README.md new file mode 100644 index 0000000..2f3bd52 --- /dev/null +++ b/python/README.md @@ -0,0 +1,62 @@ +# Quick Start + +## Installation + +This will install all Clara Viz packages use pip: + +```bash +$ pip install clara-viz +``` + +Clara Viz is using namespace packages. The main functionality is implemented in the 'clara-viz-core' package, +Jupyter Notebook widgets are found in the 'clara-viz-widgets' package. +So for example if you just need the renderer use + +```bash +$ pip install clara-viz-core +``` + +## Use interactive widget in Jupyter Notebook + +Install the Jupyter notebook widgets. + +```bash +$ pip install clara-viz-widgets +``` + +Start Jupyter Lab, open the notebooks in the `notebooks` folder. Make sure Git LFS is installed when cloning the repo, else the data files are not downloaded correctly and you will see file open errors when using the example notebooks. + +```python +from clara.viz.widgets import Widget +from clara.viz.core import Renderer +import numpy as np + +# load a RAW CT data file (volume is 512x256x256 voxels) +input = np.fromfile("CT.raw", dtype=np.int16) +input = input.reshape((512, 256, 256)) + +display(Widget(Renderer(input))) +``` + +## Render CT data from Python + +```python +from PIL import Image +import clara.viz.core +import numpy as np + +# load a RAW CT data file (volume is 512x256x256 voxels) +input = np.fromfile("CT.raw", dtype=np.int16) +input = input.reshape((512, 256, 256)) + +# create the renderer +renderer = clara.viz.core.Renderer(input) + +# render to a raw numpy array +output = renderer.render_image(1024, 768, image_type=clara.viz.core.ColorImageType.RAW_RGBA_U8) +rgb_data = np.asarray(output)[:, :, :3] + +# show with PIL +image = Image.fromarray(rgb_data) +image.show() +``` diff --git a/notebooks/Cinematic_rendering.ipynb b/python/notebooks/Cinematic_rendering.ipynb similarity index 100% rename from notebooks/Cinematic_rendering.ipynb rename to python/notebooks/Cinematic_rendering.ipynb diff --git a/notebooks/Interactive_widget.ipynb b/python/notebooks/Interactive_widget.ipynb similarity index 98% rename from notebooks/Interactive_widget.ipynb rename to python/notebooks/Interactive_widget.ipynb index 6077c02..1c6d1f5 100644 --- a/notebooks/Interactive_widget.ipynb +++ b/python/notebooks/Interactive_widget.ipynb @@ -34,7 +34,7 @@ "header_filename = 'bonsai.nhdr'\n", "if not os.path.exists('data/bonsai/' + header_filename):\n", " print('Downloading {}'.format(header_filename))\n", - " urlretrieve('https://klacansky.com/open-scivis-datasets/metadata/' + header_filename, 'data/bonsai/' + header_filename)\n", + " urlretrieve('https://klacansky.com/open-scivis-datasets/bonsai/' + header_filename, 'data/bonsai/' + header_filename)\n", "\n", "# define the render settings\n", "with open('data/bonsai/settings.json') as f:\n", diff --git a/notebooks/Multi_resolution_image.ipynb b/python/notebooks/Multi_resolution_image.ipynb similarity index 100% rename from notebooks/Multi_resolution_image.ipynb rename to python/notebooks/Multi_resolution_image.ipynb diff --git a/notebooks/Render_image.ipynb b/python/notebooks/Render_image.ipynb similarity index 99% rename from notebooks/Render_image.ipynb rename to python/notebooks/Render_image.ipynb index d58caae..574f17a 100644 --- a/notebooks/Render_image.ipynb +++ b/python/notebooks/Render_image.ipynb @@ -75,7 +75,7 @@ "renderer.set_settings(settings)\n", "\n", "# now render\n", - "jpeg_data = renderer.render_image(1024, 768, image_type=clara.viz.core.ImageType.JPEG)" + "jpeg_data = renderer.render_image(1024, 768, image_type=clara.viz.core.ColorImageType.JPEG)" ] }, { @@ -132,7 +132,7 @@ "source": [ "settings['Views'][0]['cameraName'] = 'Front'\n", "renderer.set_settings(settings)\n", - "display(IPython.display.Image(renderer.render_image(1024, 768, image_type=clara.viz.core.ImageType.JPEG)))" + "display(IPython.display.Image(renderer.render_image(1024, 768, image_type=clara.viz.core.ColorImageType.JPEG)))" ] } ], diff --git a/notebooks/Slice_rendering.ipynb b/python/notebooks/Slice_rendering.ipynb similarity index 100% rename from notebooks/Slice_rendering.ipynb rename to python/notebooks/Slice_rendering.ipynb diff --git a/notebooks/Video_recording.ipynb b/python/notebooks/Video_recording.ipynb similarity index 100% rename from notebooks/Video_recording.ipynb rename to python/notebooks/Video_recording.ipynb diff --git a/notebooks/data/OpenSlide/README.md b/python/notebooks/data/OpenSlide/README.md similarity index 100% rename from notebooks/data/OpenSlide/README.md rename to python/notebooks/data/OpenSlide/README.md diff --git a/notebooks/data/bonsai/README.md b/python/notebooks/data/bonsai/README.md similarity index 100% rename from notebooks/data/bonsai/README.md rename to python/notebooks/data/bonsai/README.md diff --git a/notebooks/data/bonsai/settings.json b/python/notebooks/data/bonsai/settings.json similarity index 100% rename from notebooks/data/bonsai/settings.json rename to python/notebooks/data/bonsai/settings.json diff --git a/notebooks/data/pancreas/README.md b/python/notebooks/data/pancreas/README.md similarity index 100% rename from notebooks/data/pancreas/README.md rename to python/notebooks/data/pancreas/README.md diff --git a/notebooks/data/syn3193805/README.md b/python/notebooks/data/syn3193805/README.md similarity index 100% rename from notebooks/data/syn3193805/README.md rename to python/notebooks/data/syn3193805/README.md diff --git a/notebooks/data/syn3193805/img0066.nii.gz b/python/notebooks/data/syn3193805/img0066.nii.gz similarity index 100% rename from notebooks/data/syn3193805/img0066.nii.gz rename to python/notebooks/data/syn3193805/img0066.nii.gz diff --git a/notebooks/data/syn3193805/label0066.nii.gz b/python/notebooks/data/syn3193805/label0066.nii.gz similarity index 100% rename from notebooks/data/syn3193805/label0066.nii.gz rename to python/notebooks/data/syn3193805/label0066.nii.gz diff --git a/notebooks/data/syn3193805/settings.json b/python/notebooks/data/syn3193805/settings.json similarity index 100% rename from notebooks/data/syn3193805/settings.json rename to python/notebooks/data/syn3193805/settings.json diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..727b151 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,38 @@ +# Copyright (c) 2020-2023, NVIDIA CORPORATION. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +cmake_minimum_required(VERSION 3.12) + +project(ClaraVizServer + DESCRIPTION "ClaraVizServer" + VERSION 0.3.0 + LANGUAGES CXX +) + +include("${CLARA_VIZ_PUBLIC_CMAKE_TOOLS_DIR}/Project.cmake") +setup_project() + +# add the tools +include("${CLARA_VIZ_PUBLIC_CMAKE_TOOLS_DIR}/Tools.cmake") + +if (CLARA_VIZ_WITH_EXAMPLES) + add_subdirectory(examples) +endif() + +if (CLARA_VIZ_WITH_GRPC) + add_subdirectory(nvrpc) + add_subdirectory(protos) +endif() + +add_subdirectory(claraviz) diff --git a/src/claraviz/CMakeLists.txt b/src/claraviz/CMakeLists.txt new file mode 100644 index 0000000..50fcd63 --- /dev/null +++ b/src/claraviz/CMakeLists.txt @@ -0,0 +1,254 @@ +# Copyright (c) 2018-2023, NVIDIA CORPORATION. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, s3oftware +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +cmake_minimum_required(VERSION 3.12) + +###################### +# core +###################### +set(PROJECT_NAME clara_viz_core) + +add_library(${PROJECT_NAME} STATIC) +add_library(clara::viz::core ALIAS ${PROJECT_NAME}) + +find_package(CUDAToolkit REQUIRED) +find_package(OpenH264 CONFIG) + +if (NOT TARGET nlohmann_json) + add_subdirectory(${nlohmann_json_SOURCE_DIR} ${nlohmann_json_BINARY_DIR} EXCLUDE_FROM_ALL) +endif() + +target_code_coverage(${PROJECT_NAME}) + +set_target_properties(${PROJECT_NAME} + PROPERTIES POSITION_INDEPENDENT_CODE True + EXPORT_NAME clara::viz::core + ) + +target_sources(${PROJECT_NAME} + PRIVATE + core/Video.cpp + + hardware/nvenc/NvEncService.cpp + + interface/CameraApertureInterface.cpp + interface/CameraInterface.cpp + interface/DataViewInterface.cpp + interface/LightInterface.cpp + interface/PostProcessDenoiseInterface.cpp + interface/PostProcessTonemapInterface.cpp + interface/RenderSettingsInterface.cpp + interface/TransferFunctionInterface.cpp + interface/VideoInterface.cpp + interface/ViewInterface.cpp + + util/Log.cpp + util/Message.cpp + util/Observed.cpp + util/Thread.cpp + + video/Mp4Wrapper.cpp + video/NvEncVideoEncoder.cpp + video/VideoEncoder.cpp + ) + +target_include_directories(${PROJECT_NAME} + PUBLIC + $ + $ + ${CUDAToolkit_INCLUDE_DIRS} + ) + +target_link_libraries(${PROJECT_NAME} + PUBLIC + nlohmann_json::nlohmann_json + ) + +if(OpenH264_FOUND) + target_compile_definitions(${PROJECT_NAME} + PRIVATE + CLARA_VIZ_WITH_OPENH264 + ) + target_sources(${PROJECT_NAME} + PRIVATE + video/OpenH264VideoEncoder.cpp + ) + target_link_libraries(${PROJECT_NAME} + PUBLIC + OpenH264::openh264 + ) +endif() + +###################### +# core hw +###################### +set(PROJECT_NAME clara_viz_core_hw) + +add_library(${PROJECT_NAME} STATIC) +add_library(clara::viz::core::hw ALIAS ${PROJECT_NAME}) + +find_package(CUDA REQUIRED) # for find_cuda_helper_libs +find_package(CUDAToolkit REQUIRED) +find_package(nvsharedmemory CONFIG) +find_package(ZLIB) + +enable_language(CUDA) + +target_code_coverage(${PROJECT_NAME}) + +set_target_properties(${PROJECT_NAME} + PROPERTIES POSITION_INDEPENDENT_CODE True + EXPORT_NAME clara::viz::core::hw + ) + +target_sources(${PROJECT_NAME} + PRIVATE + core/Image.cpp + + interface/ImageInterface.cpp + + hardware/cuda/Convert.cu + + hardware/nvjpeg/NvJpegService.cpp + + image/JpegEncoder.cpp + + interface/DataInterface.cpp + interface/JsonInterface.cpp + + util/Blob.cpp + ) + +if(nvsharedmemory_FOUND) + target_sources(${PROJECT_NAME} + PRIVATE + util/SharedMemoryBlob.cpp + ) + target_link_libraries(${PROJECT_NAME} + PUBLIC + nvsharedmemory + ) +endif() + +if(ZLIB_FOUND) + target_sources(${PROJECT_NAME} + PRIVATE + util/MHDLoader.cpp + ) + target_link_libraries(${PROJECT_NAME} + PUBLIC + ZLIB::ZLIB + ) +endif() + +target_link_libraries(${PROJECT_NAME} + PUBLIC + clara::viz::core + CUDA::cuda_driver + CUDA::cudart_static + ) + +# nvidia-docker is not mapping nvjpeg into the image, prefer to link statically +find_cuda_helper_libs(nvjpeg_static) +if(NOT CUDA_nvjpeg_static_LIBRARY) + find_cuda_helper_libs(nvjpeg) + if(NOT CUDA_nvjpeg_LIBRARY) + message(FATAL_ERROR "Could not find nvjpeg lib (neither shared nor static)") + endif() + target_link_libraries(${PROJECT_NAME} + PUBLIC + CUDA::nvjpeg + ) +else() + target_link_libraries(${PROJECT_NAME} + PUBLIC + CUDA::nvjpeg_static + ) +endif() + +if (CLARA_VIZ_WITH_GRPC) + ###################### + # core grpc + ###################### + set(PROJECT_NAME clara_viz_core_grpc) + + add_library(${PROJECT_NAME} STATIC) + add_library(clara::viz::core::grpc ALIAS ${PROJECT_NAME}) + + find_package(gRPC REQUIRED CONFIG) + + target_code_coverage(${PROJECT_NAME}) + + set_target_properties(${PROJECT_NAME} + PROPERTIES POSITION_INDEPENDENT_CODE True + ) + + target_sources(${PROJECT_NAME} + PRIVATE + core/RenderServerBase.cpp + + rpc/BackgroundLightRPC.cpp + rpc/CameraApertureRPC.cpp + rpc/CameraRPC.cpp + rpc/DataCropRPC.cpp + rpc/DataTransformRPC.cpp + rpc/DataViewRPC.cpp + rpc/LightRPC.cpp + rpc/PostProcessTonemapRPC.cpp + rpc/PostProcessDenoiseRPC.cpp + rpc/RenderSettingsRPC.cpp + rpc/ResetRPC.cpp + rpc/ServerRPC.cpp + rpc/TransferFunctionRPC.cpp + rpc/VideoRPC.cpp + rpc/ViewRPC.cpp + ) + + target_link_libraries(${PROJECT_NAME} + PUBLIC + gRPC::grpc++ + nv::rpc + clara::viz::core + clara::viz::proto + ) + + ###################### + # core grpc hw + ###################### + set(PROJECT_NAME clara_viz_core_grpc_hw) + + add_library(${PROJECT_NAME} STATIC) + add_library(clara::viz::core::grpc::hw ALIAS ${PROJECT_NAME}) + + find_package(gRPC REQUIRED CONFIG) + + target_code_coverage(${PROJECT_NAME}) + + set_target_properties(${PROJECT_NAME} + PROPERTIES POSITION_INDEPENDENT_CODE True + ) + + target_sources(${PROJECT_NAME} + PRIVATE + rpc/DataRPC.cpp + rpc/ImageRPC.cpp + rpc/QueryLimitsRPC.cpp + ) + + target_link_libraries(${PROJECT_NAME} + PUBLIC + gRPC::grpc++ + clara::viz::proto + clara::viz::core::hw + ) +endif() \ No newline at end of file diff --git a/src/claraviz/core/Image.cpp b/src/claraviz/core/Image.cpp new file mode 100644 index 0000000..099a675 --- /dev/null +++ b/src/claraviz/core/Image.cpp @@ -0,0 +1,293 @@ +/* + * Copyright (c) 2020-2023, NVIDIA CORPORATION. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "claraviz/core/Image.h" + +#include + +#include "claraviz/hardware/cuda/CudaService.h" +#include "claraviz/interface/ImageInterface.h" +#include "claraviz/image/JpegEncoder.h" +#include "claraviz/util/Thread.h" +#include "claraviz/util/StdContainerBlob.h" + +namespace clara::viz +{ + +DEFINE_CLASS_MESSAGEID(ImageMessage); +DEFINE_CLASS_MESSAGEID(ImageEncodeMessage); +DEFINE_CLASS_MESSAGEID(ImageRenderFailedMessage); +DEFINE_CLASS_MESSAGEID(ImageEncodedDataMessage); + +namespace +{ + +/** + * Shutdown message ID + */ +DEFINE_MESSAGEID(IDMESSAGE_SHUTDOWN); + +} // anonymous namespace + +/** + * Server implementation data + */ +class Image::Impl +{ +public: + explicit Impl(const std::shared_ptr &base, const std::shared_ptr &image_interface_output, + uint32_t cuda_device_ordinal); + Impl() = delete; + + void Run(); + void Shutdown(); + +private: + /** + * Interface thread function. + */ + void ThreadFunction(std::function ready); + + /** + * Send to encoder. + * + * @param message [in] + */ + void Encode(std::shared_ptr message); + + /// base class (needs to be a weak_ptr to break circular dependency) + const std::weak_ptr base_; + + /// message receiver for the encoded data + std::shared_ptr image_interface_output_; + + /** + * Cuda context. + * Note that the context has to be the first member interacting with Cuda. + * The context will be destroyed last and all other Cuda objects should be already + * be destroyed at this point. + */ + std::unique_ptr cuda_context_; + + /// The cuda device to render on + const uint32_t cuda_device_ordinal_; + + /// interface thread + std::unique_ptr thread_; + + /// JPEG encoder + std::unique_ptr encoder_; +}; + +std::shared_ptr Image::Create(const std::shared_ptr &image_interface_output, + uint32_t cuda_device_ordinal) +{ + auto image = std::make_shared(); + + image->impl_.reset(new Image::Impl(image, image_interface_output, cuda_device_ordinal)); + + return image; +} + +Image::~Image() +{ + Shutdown(); +} + +void Image::Run() +{ + impl_->Run(); +} + +void Image::Shutdown() +{ + if (impl_) + { + impl_->Shutdown(); + } +} + +Image::Impl::Impl(const std::shared_ptr &base, const std::shared_ptr &image_interface_output, + uint32_t cuda_device_ordinal) + : base_(base) + , image_interface_output_(image_interface_output) + , cuda_device_ordinal_(cuda_device_ordinal) +{ + if (!base) + { + throw InvalidArgument("base") << "is nullptr"; + } +} + +void Image::Impl::Run() +{ + // run the render thread + thread_.reset(new Thread("Encoder thread", [this](std::function ready) { ThreadFunction(ready); })); +} + +void Image::Impl::Shutdown() +{ + if (thread_) + { + // might be called when the base class is already destroyed + const std::shared_ptr base = base_.lock(); + if (base) + { + base->EnqueueMessage(std::make_shared(IDMESSAGE_SHUTDOWN)); + } + + // destroy the thread + thread_.reset(); + } +} + +void Image::Impl::ThreadFunction(std::function ready) +{ + // initialize Cuda + CudaCheck(cuInit(0)); + cuda_context_.reset(new CudaPrimaryContext(cuda_device_ordinal_)); + + // create the encoder + encoder_.reset(new JpegEncoder()); + + // thread is ready now + ready(); + + while (true) + { + try + { + auto base = base_.lock(); + + base->Wait(); + + bool shutdown = false; + std::shared_ptr message; + while ((message = base->DequeueMessage())) + { + Log(LogLevel::Debug) << "Image received " << message->GetID().GetName(); + + if (message->GetID() == ImageInterface::Message::id_) + { + // interface message + const ImageInterface::DataOut &image_data_ = + std::static_pointer_cast(message)->data_out_; + + // ignore initial state message + if (image_data_.color_type == ColorImageType::UNKNOWN) + { + break; + } + + // forward the data to the client + auto image_message = std::make_shared(); + + image_message->view_name_ = image_data_.view_name; + image_message->width_ = image_data_.width; + image_message->height_ = image_data_.height; + image_message->color_type_ = image_data_.color_type; + if (image_data_.color_type == ColorImageType::JPEG) + { + image_message->parameters_.jpeg_.quality_ = image_data_.jpeg_quality; + } + image_message->color_memory_ = image_data_.color_memory; + image_message->depth_type_ = image_data_.depth_type; + image_message->depth_memory_ = image_data_.depth_memory; + + base->SendMessage(image_message); + } + else if (message->GetID() == ImageEncodeMessage::id_) + { + // client message (from renderer), encode a frame + Encode(std::static_pointer_cast(message)); + } + else if (message->GetID() == ImageRenderFailedMessage::id_) + { + // send a empty data message to the client + auto encoded_data_message = std::make_shared(); + encoded_data_message->color_type_ = ColorImageType::UNKNOWN; + encoded_data_message->depth_type_ = DepthImageType::UNKNOWN; + image_interface_output_->EnqueueMessage(encoded_data_message); + } + else if (message->GetID() == IDMESSAGE_SHUTDOWN) + { + shutdown = true; + } + else + { + throw InvalidState() << "Unhandled message Id " << message->GetID().GetName(); + } + } + + if (shutdown) + { + break; + } + } + catch (const std::exception &e) + { + Log(LogLevel::Error) << "Image thread threw exception " << e.what(); + } + catch (...) + { + Log(LogLevel::Error) << "Image thread threw unknown exception"; + } + } +} + +void Image::Impl::Encode(std::shared_ptr message) +{ + auto encoded_data_message = std::make_shared(); + + auto base = base_.lock(); + + // check if there is color data and we should encode to JPEG, do it + if (message->color_memory_) + { + if (message->color_type_ == ColorImageType::JPEG) + { + // encode the image + JpegEncoder::Format encoder_format; + switch (message->color_format_) + { + case ImageEncodeMessage::ColorFormat::ABGR_U8: + encoder_format = JpegEncoder::Format::ABGR; + break; + default: + throw InvalidState() << "Unhandled image format " << static_cast(message->color_format_); + } + + encoder_->SetQuality(message->parameters_.jpeg_.quality_); + std::unique_ptr> data(new std::vector()); + encoder_->Encode(message->width_, message->height_, encoder_format, message->color_memory_, *data.get()); + encoded_data_message->color_memory_.reset(new StdContainerBlob>(std::move(data))); + } + else + { + // else just pass it along + encoded_data_message->color_memory_ = message->color_memory_; + } + } + encoded_data_message->color_type_ = message->color_type_; + + encoded_data_message->depth_memory_ = message->depth_memory_; + encoded_data_message->depth_type_ = message->depth_type_; + + // send the data to the image data receiver + image_interface_output_->EnqueueMessage(encoded_data_message); +} + +} // namespace clara::viz diff --git a/src/claraviz/core/Image.h b/src/claraviz/core/Image.h new file mode 100644 index 0000000..c0e8496 --- /dev/null +++ b/src/claraviz/core/Image.h @@ -0,0 +1,255 @@ +/* + * Copyright (c) 2020-2023, NVIDIA CORPORATION. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include + +#include "claraviz/util/Message.h" + +namespace clara::viz +{ + +class IBlob; + +/// color image type enum +enum class ColorImageType +{ + /** + * unknown (invalid) + */ + UNKNOWN, + /** + * RAW uncompressed RGB unsigned int 8-bit with unused unsigned int 8-bit + * This is a word-ordered format where a pixel is represented by a 32-bit word with R + * in the lowest 8 bits, G in the next 8 bits, B in the + * 8 bits after that and A in the highest 8 bits. + */ + RAW_RGBA_U8, + /** + * JPEG + */ + JPEG, +}; + +/// depth image type enum +enum class DepthImageType +{ + /** + * unknown (invalid) + */ + UNKNOWN, + /** + * RAW uncompressed depth 32-bit float. + */ + RAW_DEPTH_F32, +}; + +/** + * Image output server. + * Communicates to the server through messages, once an image is requested + * a `ImageRequestMessage` is emitted. To deliver an image enqueue a `ImageEncodeMessage`. + */ +class Image + : public std::enable_shared_from_this + , public MessageProvider + , public MessageReceiver +{ +public: + /** + * Create + * + * @param image_interface_output [in] The message receiver for the encoded data + * @param cuda_device_ordinal [in] Cuda device to use for encoding + * + * @returns created instance + */ + static std::shared_ptr Create(const std::shared_ptr &image_interface_output, + uint32_t cuda_device_ordinal); + virtual ~Image(); + + /** + * Start the server + */ + void Run(); + + /** + * Shutdown + */ + void Shutdown(); + +private: + struct Impl; + std::unique_ptr impl_; +}; + +/// parameters (depends on type) +union EncodeParameters +{ + /// Jpeg parameters + struct + { + // quality + uint32_t quality_; + } jpeg_; +}; + +/** + * Emitted by the Image class indicating that a new image is requested to be delivered. + */ +class ImageMessage : public Message +{ +public: + ImageMessage() + : Message(id_) + { + } + + /// name of the view to render + std::string view_name_; + /// width of the image + uint32_t width_; + /// height of the image + uint32_t height_; + + /// type of the color image + ColorImageType color_type_; + /// Pre-allocated CUDA memory blob to write color data into. The allocated memory must be able to store width by + /// height elements of type 'color_type_'. If this member is empty, memory will be allocated by the renderer. + std::shared_ptr color_memory_; + + /// type of the color image + DepthImageType depth_type_; + /// Pre-allocated CUDA memory blob to write depth data into. The allocated memory must be able to store width by + /// height elements of type 'depth_type_'. If this member is empty, memory will be allocated by the renderer. + std::shared_ptr depth_memory_; + + /// parameters (depends on type) + EncodeParameters parameters_; + + /// message id + static const MessageID id_; +}; + +/** + * Encode a resource. + * Send by the client to the Image service. + */ +class ImageEncodeMessage : public Message +{ +public: + ImageEncodeMessage() + : Message(id_) + { + } + + /// width in pixels of the resources + uint32_t width_; + /// height in pixels of the resources + uint32_t height_; + + /** + * Supported color pixel formats + */ + enum class ColorFormat + { + /** + * 8 bit Packed A8B8G8R8. This is a word-ordered format + * where a pixel is represented by a 32-bit word with R + * in the lowest 8 bits, G in the next 8 bits, B in the + * 8 bits after that and A in the highest 8 bits. */ + ABGR_U8 + }; + + /// the color resource to encode + std::shared_ptr color_memory_; + /// pixel format of the color resource + ColorFormat color_format_; + /// type of the encoded color image + ColorImageType color_type_; + + /** + * Supported depth pixel formats + */ + enum class DepthFormat + { + /** + * 32-bit float depth. + */ + D_F32, + }; + + /// the depth resource to encode + std::shared_ptr depth_memory_; + /// pixel format of the depth resource + DepthFormat depth_format_; + /// type of the encoded depth image + DepthImageType depth_type_; + + /// parameters (depends on type) + EncodeParameters parameters_; + + /// message id + static const MessageID id_; +}; + +/** + * Image rendering failed message. + * Send by the client to the Image service. + */ +class ImageRenderFailedMessage : public Message +{ +public: + ImageRenderFailedMessage() + : Message(id_) + { + } + + /// The reason why the rendering failed + std::string reason_; + + /// message id + static const MessageID id_; +}; + +/** + * Message containing the image data + * Emitted by the Image service. + */ +class ImageEncodedDataMessage : public Message +{ +public: + ImageEncodedDataMessage() + : Message(id_) + { + } + + /// type of the color data + ColorImageType color_type_; + /// the color memory + std::shared_ptr color_memory_; + + /// type of the depth data + DepthImageType depth_type_; + /// the depth memory + std::shared_ptr depth_memory_; + + /// message id + static const MessageID id_; +}; + +} // namespace clara::viz diff --git a/src/claraviz/core/RenderServerBase.cpp b/src/claraviz/core/RenderServerBase.cpp new file mode 100644 index 0000000..176ff70 --- /dev/null +++ b/src/claraviz/core/RenderServerBase.cpp @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2018-2022, NVIDIA CORPORATION. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "claraviz/core/RenderServerBase.h" + +#include + +#include + +#include "claraviz/util/Log.h" + +namespace clara::viz +{ + +namespace +{ + +/** + * Called by the signal handler to shutdown the server + */ +std::function shutdown_server; + +void SignalHandler(int signum) +{ + // Don't need a mutex here since signals should be disabled while in + // the handler. + Log(LogLevel::Info) << "Interrupt signal (" << signum << ") received."; + + static std::once_flag flag; + std::call_once(flag, [] { + std::unique_ptr thread; + + thread.reset(new std::thread([] { shutdown_server(); })); + + thread->detach(); + }); +} + +} // anonymous namespace + +RenderServerBase::RenderServerBase(const std::string &address) + : server_rpc_(new ServerRPC(address)) +{ + // setup the global shutdown function used by the signal handler to + // shutdown the server + shutdown_server = [this] { + if (!Shutdown()) + { + Log(LogLevel::Warning) << "Failed to shutdown render server"; + } + }; + + // Trap SIGINT and SIGTERM to allow server to exit gracefully + signal(SIGINT, SignalHandler); + signal(SIGTERM, SignalHandler); +} + +const std::shared_ptr &RenderServerBase::GetServerRPC() +{ + return server_rpc_; +} + +void RenderServerBase::Run() +{ + // run the RPC server + server_rpc_->Run(); +} + +void RenderServerBase::Wait() +{ + // wait for the RPC server + server_rpc_->Wait(); +} + +bool RenderServerBase::Shutdown() +{ + // shutdown the RPC server + return server_rpc_->Shutdown(); +} + +} // namespace clara::viz diff --git a/src/claraviz/core/RenderServerBase.h b/src/claraviz/core/RenderServerBase.h new file mode 100644 index 0000000..5735828 --- /dev/null +++ b/src/claraviz/core/RenderServerBase.h @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2018-2022, NVIDIA CORPORATION. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include + +#include +#include + +namespace clara::viz +{ + +/** + * Base class for all RenderServer's. + * Contains a gRPC server and a signal handler to shutdown on Ctrl-C. + */ +class RenderServerBase : public NonCopyable +{ +public: + /** + * Construct + * + * @param address [in] address to start the gRPC service on + */ + RenderServerBase(const std::string &address); + virtual ~RenderServerBase() = default; + + /** + * @returns the RPC server + */ + const std::shared_ptr &GetServerRPC(); + + /** + * Run the server. + */ + virtual void Run(); + + /** + * Shutdown the server, wait for all running tasks to finish. + * + * @returns false if a timeout occurred, else true + */ + virtual bool Shutdown(); + + /** + * Wait for the server, does not return until the server is shutdown. + */ + virtual void Wait(); + +private: + std::shared_ptr server_rpc_; +}; + +} // namespace clara::viz diff --git a/src/claraviz/core/Video.cpp b/src/claraviz/core/Video.cpp new file mode 100644 index 0000000..e7bc897 --- /dev/null +++ b/src/claraviz/core/Video.cpp @@ -0,0 +1,511 @@ +/* + * Copyright (c) 2019-2023, NVIDIA CORPORATION. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "claraviz/core/Video.h" + +#include "claraviz/interface/VideoInterface.h" +#include "claraviz/hardware/cuda/CudaService.h" +#include "claraviz/util/Thread.h" +#include "claraviz/util/Blob.h" +#include "claraviz/video/NvEncVideoEncoder.h" +#ifdef CLARA_VIZ_WITH_OPENH264 +#include "claraviz/video/OpenH264VideoEncoder.h" +#endif + +namespace clara::viz +{ + +DEFINE_CLASS_MESSAGEID(VideoMessage); +DEFINE_CLASS_MESSAGEID(VideoEncodeMessage); + +namespace +{ + +/** + * Shutdown message ID + */ +DEFINE_MESSAGEID(IDMESSAGE_SHUTDOWN); + +} // anonymous namespace + +/** + * Server implementation data + */ +class Video::Impl +{ +public: + explicit Impl(const std::shared_ptr